aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/libstdc++-v3/testsuite/20_util/hash
diff options
context:
space:
mode:
authorBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
committerBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
commit1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch)
treec607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/libstdc++-v3/testsuite/20_util/hash
parent283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff)
downloadtoolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/libstdc++-v3/testsuite/20_util/hash')
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/52931.cc32
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_bit_flip_set.cc61
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_bit_string_set.cc55
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc52
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_numeric_pattern_set.cc52
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_uniform_random.cc53
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_quality.h74
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc54
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/quality.cc172
-rw-r--r--gcc-4.9/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc49
10 files changed, 654 insertions, 0 deletions
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/52931.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/52931.cc
new file mode 100644
index 000000000..e1357a6c7
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/52931.cc
@@ -0,0 +1,32 @@
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+// Copyright (C) 2012-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <type_traits>
+#include <functional>
+
+class S{}; // No hash specialization
+
+template<class T>
+auto f(int) -> decltype(std::hash<T>(), std::true_type());
+
+template<class T>
+auto f(...) -> decltype(std::false_type());
+
+static_assert(!decltype(f<S>(0))::value, "");
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_bit_flip_set.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_bit_flip_set.cc
new file mode 100644
index 000000000..600dd730d
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_bit_flip_set.cc
@@ -0,0 +1,61 @@
+// { dg-options "-std=gnu++0x" }
+// Use smaller statistics when running on simulators, so it takes less time.
+// { dg-options "-std=gnu++0x -DSAMPLES=30000" { target simulator } }
+
+// Copyright (C) 2010-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "chi2_quality.h"
+
+// Tests chi^2 for a distribution of strings that differ from each
+// other by only a few bits. We start with an arbitrary base string, and
+// flip three random bits for each member of the set.
+void
+test_bit_flip_set()
+{
+ bool test __attribute__((unused)) = true;
+ const unsigned long N = SAMPLES;
+ const unsigned long k = N/100;
+ const unsigned int len = 67;
+ const unsigned int bitlen = len * 8;
+ const unsigned int bits_to_flip = 3;
+ const char base[len+1] = "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789!@#$%";
+
+ std::unordered_set<std::string> set;
+ while (set.size() < N)
+ {
+ std::string s(base, base+len);
+ for (unsigned int i = 0; i < bits_to_flip; ++i)
+ {
+ int bit = rand() % bitlen;
+ s[bit/8] ^= (1 << (bit%8));
+ }
+ set.insert(s);
+ }
+
+ double chi2 = chi2_hash(set, k);
+ VERIFY( chi2 < k*1.1 );
+}
+
+int
+main()
+{
+ test_bit_flip_set();
+ return 0;
+}
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_bit_string_set.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_bit_string_set.cc
new file mode 100644
index 000000000..eb9237f1f
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_bit_string_set.cc
@@ -0,0 +1,55 @@
+// { dg-options "-std=gnu++0x" }
+// Use smaller statistics when running on simulators, so it takes less time.
+// For e.g. cris-elf, mipsisa32r2el-elf, powerpc-eabi and i386-linux-gnu,
+// this test fails for SAMPLES=30000.
+// { dg-options "-std=gnu++0x -DSAMPLES=35000" { target simulator } }
+
+// Copyright (C) 2010-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "chi2_quality.h"
+
+// Tests chi^2 for a set of strings that all consist of '1' and '0'.
+void
+test_bit_string_set()
+{
+ bool test __attribute__((unused)) = true;
+ const unsigned long N = SAMPLES;
+ const unsigned long k = N/100;
+ std::vector<std::string> set;
+ std::string s;
+ for (unsigned long i = 0; i < N; ++i)
+ {
+ s.clear();
+ for (unsigned int j = 0; j < sizeof(unsigned long) * 8; ++j)
+ {
+ const bool bit = (1UL << j) & i;
+ s.push_back(bit ? '1' : '0');
+ }
+ set.push_back(s);
+ }
+
+ double chi2 = chi2_hash(set, k);
+ VERIFY( chi2 < k*1.1 );
+}
+
+int
+main()
+{
+ test_bit_string_set();
+ return 0;
+}
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
new file mode 100644
index 000000000..384c724d0
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
@@ -0,0 +1,52 @@
+// On some simulators, the workload is simply too large with values big
+// enough for the test to pass the quality test, so just skip it altogether.
+// { dg-do run { target { ! simulator } } }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "chi2_quality.h"
+
+// Tests chi^2 for a set of words taken from a document written in English.
+void
+test_document_words()
+{
+ bool test __attribute__((unused)) = true;
+ const std::string f_name = "thirty_years_among_the_dead_preproc.txt";
+ std::ifstream in(f_name);
+ VERIFY( in.is_open() );
+ std::vector<std::string> words;
+ words.assign(std::istream_iterator<std::string>(in),
+ std::istream_iterator<std::string>());
+ VERIFY( words.size() > 100000 );
+ std::sort(words.begin(), words.end());
+ auto it = std::unique(words.begin(), words.end());
+ words.erase(it, words.end());
+ VERIFY( words.size() > 5000 );
+
+ const unsigned long k = words.size() / 20;
+ double chi2 = chi2_hash(words, k);
+ VERIFY( chi2 < k*1.1 );
+}
+
+int
+main()
+{
+ test_document_words();
+ return 0;
+}
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_numeric_pattern_set.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_numeric_pattern_set.cc
new file mode 100644
index 000000000..1840641d0
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_numeric_pattern_set.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=gnu++0x" }
+// Use smaller statistics when running on simulators, so it takes less time.
+// For x86_64-linux-gnu SAMPLES=30000 fails, so increase slightly.
+// { dg-options "-std=gnu++0x -DSAMPLES=35000" { target simulator } }
+
+// Copyright (C) 2010-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "chi2_quality.h"
+
+// Tests chi^2 of a set of strings that all have a similar pattern,
+// intended to mimic some sort of ID string.
+void
+test_numeric_pattern_set()
+{
+ bool test __attribute__((unused)) = true;
+ const unsigned long N = SAMPLES;
+ const unsigned long k = N/100;
+ std::vector<std::string> set;
+ for (unsigned long i = 0; i < N; ++i)
+ {
+ long i1 = i % 100000;
+ long i2 = i / 100000;
+ char buf[16];
+ std::sprintf(buf, "XX-%05lu-%05lu", i1, i2);
+ set.push_back(buf);
+ }
+
+ double chi2 = chi2_hash(set, k);
+ VERIFY( chi2 < k*1.1 );
+}
+
+int
+main()
+{
+ test_numeric_pattern_set();
+ return 0;
+}
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_uniform_random.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_uniform_random.cc
new file mode 100644
index 000000000..5006afa6e
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_q_uniform_random.cc
@@ -0,0 +1,53 @@
+// { dg-options "-std=gnu++0x" }
+// Use smaller statistics when running on simulators, so it takes less time.
+// For powerpc-eabi, SAMPLES=30000 fails.
+// { dg-options "-std=gnu++0x -DSAMPLES=35000" { target simulator } }
+
+// Copyright (C) 2010-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "chi2_quality.h"
+
+// Tests chi^2 for a distribution of uniformly generated random strings.
+void
+test_uniform_random()
+{
+ bool test __attribute__((unused)) = true;
+ std::srand(137);
+ std::unordered_set<std::string> set;
+ std::string s;
+ const unsigned long N = SAMPLES;
+ const unsigned long k = N/100;
+ const unsigned int len = 25;
+ while (set.size() < N)
+ {
+ s.clear();
+ for (unsigned int i = 0; i < len; ++i)
+ s.push_back(rand() % 128);
+ set.insert(s);
+ }
+
+ double chi2 = chi2_hash(set, k);
+ VERIFY( chi2 < k*1.1 );
+}
+
+int
+main()
+{
+ test_uniform_random();
+ return 0;
+}
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_quality.h b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_quality.h
new file mode 100644
index 000000000..58bd23b0d
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/chi2_quality.h
@@ -0,0 +1,74 @@
+// Copyright (C) 2010-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// This file uses the chi^2 test to measure the quality of a hash
+// function, by computing the uniformity with which it distributes a set
+// of N strings into k buckets (where k is significantly greater than N).
+//
+// Each bucket has B[i] strings in it. The expected value of each bucket
+// for a uniform distribution is z = N/k, so
+// chi^2 = Sum_i (B[i] - z)^2 / z.
+//
+// We check whether chi^2 is small enough to be consistent with the
+// hypothesis of a uniform distribution. If F(chi^2, k-1) is close to
+// 0 (where F is the cumulative probability distribution), we can
+// reject that hypothesis. So we don't want F to be too small, which
+// for large k, means we want chi^2 to be not too much larger than k.
+//
+// We use the chi^2 test for several sets of strings. Any non-horrible
+// hash function should do well with purely random strings. A really
+// good hash function will also do well with more structured sets,
+// including ones where the strings differ by only a few bits.
+
+#include <algorithm>
+#include <cstdlib>
+#include <cstdio>
+#include <fstream>
+#include <functional>
+#include <iostream>
+#include <iterator>
+#include <string>
+#include <unordered_set>
+#include <vector>
+#include <testsuite_hooks.h>
+
+#ifndef SAMPLES
+#define SAMPLES 300000
+#endif
+
+template <typename Container>
+ double
+ chi2_hash(const Container& c, long buckets)
+ {
+ std::vector<int> counts(buckets);
+ std::hash<std::string> hasher;
+ double elements = 0;
+ for (auto i = c.begin(); i != c.end(); ++i)
+ {
+ ++counts[hasher(*i) % buckets];
+ ++elements;
+ }
+
+ const double z = elements / buckets;
+ double sum = 0;
+ for (long i = 0; i < buckets; ++i)
+ {
+ double delta = counts[i] - z;
+ sum += delta*delta;
+ }
+ return sum/z;
+ }
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc
new file mode 100644
index 000000000..5033514d5
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc
@@ -0,0 +1,54 @@
+// { dg-options "-std=gnu++0x" }
+// 2007-08-20 <benjamin@redhat.com>
+//
+// Copyright (C) 2007-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <functional>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+template<typename T>
+ void
+ do_test()
+ {
+ bool test __attribute__((unused)) = true;
+
+ typedef T value_type;
+ typedef std::hash<value_type> hash_type;
+ using std::size_t;
+
+ value_type v; // default initialized is fine, same value all that matters.
+ hash_type h1;
+ size_t r1 = size_t(h1(v));
+
+ hash_type h2;
+ size_t r2 = size_t(h2(v));
+
+ VERIFY( r1 == r2 );
+ }
+
+void test01()
+{
+ do_test<std::error_code>();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/quality.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/quality.cc
new file mode 100644
index 000000000..a3c064ba8
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/quality.cc
@@ -0,0 +1,172 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-options "-DNTESTS=1 -DNSTRINGS=100 -DSTRSIZE=21 -std=gnu++0x" { target simulator } }
+
+// Copyright (C) 2010-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <cstdlib>
+#include <unordered_set>
+#include <string>
+#include <functional>
+#include <vector>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+#ifndef NTESTS
+#define NTESTS 5
+#endif
+#ifndef NSTRINGS
+#define NSTRINGS 200
+#endif
+#ifndef STRSIZE
+#define STRSIZE 42
+#endif
+
+const unsigned int num_quality_tests = NTESTS;
+const unsigned int num_strings_for_quality_tests = NSTRINGS;
+const unsigned int string_size = STRSIZE;
+
+vector<string>
+random_strings(unsigned int n, unsigned int len)
+{
+ string s(len, '\0');
+ unordered_set<string> result_set;
+ while (result_set.size() < n)
+ {
+ result_set.insert(s);
+ unsigned int tmp = rand();
+ tmp %= len * 256;
+ s[tmp / 256] = tmp % 256;
+ }
+ return vector<string>(result_set.begin(), result_set.end());
+}
+
+double
+score_from_varying_position(string s, unsigned int index)
+{
+ bool test __attribute__((unused)) = true;
+ unsigned int bits_in_hash_code = sizeof(size_t) * 8;
+
+ // We'll iterate through all 256 vals for s[index], leaving the rest
+ // of s fixed. Then, for example, out of the 128 times that
+ // s[index] has its 3rd bit equal to 0 we would like roughly half 1s
+ // and half 0s in bit 9 of the hash codes.
+ //
+ // Bookkeeping: Conceptually we want a 3D array of ints. We want to
+ // count the number of times each output position (of which there are
+ // bits_in_hash_code) is 1 for each bit position within s[index] (of
+ // which there are 8) and value of that bit (of which there are 2).
+ const unsigned int jj = 2;
+ const unsigned int kk = jj * bits_in_hash_code;
+ const unsigned int array_size = 8 * kk;
+ vector<int> ones(array_size, 0);
+
+ for (int i = 0; i < 256; i++)
+ {
+ s[index] = i;
+ size_t h = hash<string>()(s);
+ for (int j = 0; h != 0; j++, h >>= 1)
+ {
+ if (h & 1)
+ {
+ for (int k = 0; k < 8; k++)
+ ++ones[k * kk + j * jj + ((i >> k) & 1)];
+ }
+ }
+ }
+
+ // At most, the innermost statement in the above loop nest can
+ // execute 256 * bits_in_hash_code * 8 times. If the hash is good,
+ // it'll execute about half that many times, with a pretty even
+ // spread across the elements of ones[].
+ VERIFY( 256 * bits_in_hash_code * 8 / array_size == 128 );
+ int max_ones_possible = 128;
+ int good = 0, bad = 0;
+ for (int bit = 0; bit <= 1; bit++)
+ {
+ for (unsigned int j = 0; j < bits_in_hash_code; j++)
+ {
+ for (int bitpos = 0; bitpos < 8; bitpos++)
+ {
+ int z = ones[bitpos * kk + j * jj + bit];
+ if (z <= max_ones_possible / 6
+ || z >= max_ones_possible * 5 / 6)
+ {
+ // The hash function screwed up, or was just unlucky,
+ // as 128 flips of a perfect coin occasionally yield
+ // far from 64 heads.
+ bad++;
+ }
+ else
+ good++;
+ }
+ }
+ }
+ return good / (double)(good + bad);
+}
+
+double
+score_from_varying_position(const vector<string>& v, unsigned int index)
+{
+ double score = 0;
+ for (unsigned int i = 0; i < v.size(); i++)
+ score += score_from_varying_position(v[i], index);
+ return score / v.size();
+}
+
+double
+quality_test(unsigned int num_strings, unsigned int string_size)
+{
+ // Construct random strings.
+ vector<string> v = random_strings(num_strings, string_size);
+ double sum_of_scores = 0;
+ for (unsigned int i = 0; i < string_size; i++)
+ sum_of_scores += score_from_varying_position(v, i);
+
+ // A good hash function should have a score very close to 1, and a bad
+ // hash function will have a score close to 0.
+ return sum_of_scores / string_size;
+}
+
+void
+quality_test()
+{
+ bool test __attribute__((unused)) = true;
+ srand(137);
+ double sum_of_scores = 0;
+ for (unsigned int i = 0; i < num_quality_tests; i++)
+ {
+ double score = quality_test(num_strings_for_quality_tests,
+ string_size);
+ sum_of_scores += score;
+ VERIFY( score > 0.99 );
+ }
+
+ if (num_quality_tests > 1)
+ {
+ double mean_quality = sum_of_scores / num_quality_tests;
+ VERIFY( mean_quality > 0.9999 );
+ }
+}
+
+int
+main()
+{
+ quality_test();
+ return 0;
+}
diff --git a/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc
new file mode 100644
index 000000000..3026fc312
--- /dev/null
+++ b/gcc-4.9/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc
@@ -0,0 +1,49 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2007-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <functional>
+#include <string>
+#include <system_error>
+
+// Verify that we can instantiate hash for every required type.
+template class std::hash<bool>;
+template class std::hash<char>;
+template class std::hash<signed char>;
+template class std::hash<unsigned char>;
+template class std::hash<char16_t>;
+template class std::hash<char32_t>;
+template class std::hash<short>;
+template class std::hash<int>;
+template class std::hash<long>;
+template class std::hash<unsigned short>;
+template class std::hash<unsigned int>;
+template class std::hash<unsigned long>;
+template class std::hash<float>;
+template class std::hash<double>;
+template class std::hash<long double>;
+template class std::hash<void*>;
+template class std::hash<std::string>;
+template class std::hash<std::error_code>;
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+template class std::hash<wchar_t>;
+template class std::hash<std::wstring>;
+#endif
+