Home | History | Annotate | Download | only in unord.map
      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_map>
     11 
     12 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
     13 //           class Alloc = allocator<pair<const Key, T>>>
     14 // class unordered_map
     15 
     16 // void rehash(size_type n);
     17 
     18 #include <unordered_map>
     19 #include <string>
     20 #include <cassert>
     21 
     22 void test(const std::unordered_map<int, std::string>& c)
     23 {
     24     assert(c.size() == 4);
     25     assert(c.at(1) == "one");
     26     assert(c.at(2) == "two");
     27     assert(c.at(3) == "three");
     28     assert(c.at(4) == "four");
     29 }
     30 
     31 int main()
     32 {
     33     {
     34         typedef std::unordered_map<int, std::string> C;
     35         typedef std::pair<int, std::string> P;
     36         P a[] =
     37         {
     38             P(1, "one"),
     39             P(2, "two"),
     40             P(3, "three"),
     41             P(4, "four"),
     42             P(1, "four"),
     43             P(2, "four"),
     44         };
     45         C c(a, a + sizeof(a)/sizeof(a[0]));
     46         test(c);
     47         assert(c.bucket_count() >= 5);
     48         c.rehash(3);
     49         assert(c.bucket_count() == 5);
     50         test(c);
     51         c.max_load_factor(2);
     52         c.rehash(3);
     53         assert(c.bucket_count() == 3);
     54         test(c);
     55         c.rehash(31);
     56         assert(c.bucket_count() == 31);
     57         test(c);
     58     }
     59 }
     60