Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <unordered_set> |
| 11 | |
| 12 | // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
| 13 | // class Alloc = allocator<Value>> |
| 14 | // class unordered_set |
| 15 | |
| 16 | // void rehash(size_type n); |
| 17 | |
| 18 | #include <unordered_set> |
| 19 | #include <cassert> |
| 20 | |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 21 | #include "min_allocator.h" |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 22 | |
| 23 | template <class C> |
| 24 | void test(const C& c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | { |
| 26 | assert(c.size() == 4); |
| 27 | assert(c.count(1) == 1); |
| 28 | assert(c.count(2) == 1); |
| 29 | assert(c.count(3) == 1); |
| 30 | assert(c.count(4) == 1); |
| 31 | } |
| 32 | |
| 33 | int main() |
| 34 | { |
| 35 | { |
| 36 | typedef std::unordered_set<int> C; |
| 37 | typedef int P; |
| 38 | P a[] = |
| 39 | { |
| 40 | P(1), |
| 41 | P(2), |
| 42 | P(3), |
| 43 | P(4), |
| 44 | P(1), |
| 45 | P(2) |
| 46 | }; |
| 47 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 48 | test(c); |
| 49 | assert(c.bucket_count() >= 5); |
| 50 | c.rehash(3); |
| 51 | assert(c.bucket_count() == 5); |
| 52 | test(c); |
| 53 | c.max_load_factor(2); |
| 54 | c.rehash(3); |
| 55 | assert(c.bucket_count() == 3); |
| 56 | test(c); |
| 57 | c.rehash(31); |
| 58 | assert(c.bucket_count() == 31); |
| 59 | test(c); |
| 60 | } |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 61 | #if __cplusplus >= 201103L |
| 62 | { |
| 63 | typedef std::unordered_set<int, std::hash<int>, |
| 64 | std::equal_to<int>, min_allocator<int>> C; |
| 65 | typedef int P; |
| 66 | P a[] = |
| 67 | { |
| 68 | P(1), |
| 69 | P(2), |
| 70 | P(3), |
| 71 | P(4), |
| 72 | P(1), |
| 73 | P(2) |
| 74 | }; |
| 75 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 76 | test(c); |
| 77 | assert(c.bucket_count() >= 5); |
| 78 | c.rehash(3); |
| 79 | assert(c.bucket_count() == 5); |
| 80 | test(c); |
| 81 | c.max_load_factor(2); |
| 82 | c.rehash(3); |
| 83 | assert(c.bucket_count() == 3); |
| 84 | test(c); |
| 85 | c.rehash(31); |
| 86 | assert(c.bucket_count() == 31); |
| 87 | test(c); |
| 88 | } |
| 89 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | } |