1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 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 // size_type bucket(const key_type& __k) const; 17 18 #ifdef _LIBCPP_DEBUG 19 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) 20 #endif 21 22 #include <unordered_set> 23 #include <cassert> 24 25 #include "min_allocator.h" 26 27 int main() 28 { 29 { 30 typedef std::unordered_set<int> C; 31 typedef int P; 32 P a[] = 33 { 34 P(1), 35 P(2), 36 P(3), 37 P(4), 38 P(1), 39 P(2) 40 }; 41 const C c(std::begin(a), std::end(a)); 42 size_t bc = c.bucket_count(); 43 assert(bc >= 5); 44 for (size_t i = 0; i < 13; ++i) 45 assert(c.bucket(i) == i % bc); 46 } 47 #if __cplusplus >= 201103L 48 { 49 typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; 50 typedef int P; 51 P a[] = 52 { 53 P(1), 54 P(2), 55 P(3), 56 P(4), 57 P(1), 58 P(2) 59 }; 60 const C c(std::begin(a), std::end(a)); 61 size_t bc = c.bucket_count(); 62 assert(bc >= 5); 63 for (size_t i = 0; i < 13; ++i) 64 assert(c.bucket(i) == i % bc); 65 } 66 #endif 67 #if _LIBCPP_DEBUG_LEVEL >= 1 68 { 69 typedef std::unordered_set<int> C; 70 C c; 71 C::size_type i = c.bucket(3); 72 assert(false); 73 } 74 #endif 75 } 76