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 // float load_factor() const
     17 
     18 #include <unordered_map>
     19 #include <string>
     20 #include <cassert>
     21 #include <cfloat>
     22 
     23 #include "min_allocator.h"
     24 
     25 int main()
     26 {
     27     {
     28         typedef std::unordered_map<int, std::string> C;
     29         typedef std::pair<int, std::string> P;
     30         P a[] =
     31         {
     32             P(10, "ten"),
     33             P(20, "twenty"),
     34             P(30, "thirty"),
     35             P(40, "fourty"),
     36             P(50, "fifty"),
     37             P(60, "sixty"),
     38             P(70, "seventy"),
     39             P(80, "eighty"),
     40         };
     41         const C c(std::begin(a), std::end(a));
     42         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
     43     }
     44     {
     45         typedef std::unordered_map<int, std::string> C;
     46         typedef std::pair<int, std::string> P;
     47         const C c;
     48         assert(c.load_factor() == 0);
     49     }
     50 #if __cplusplus >= 201103L
     51     {
     52         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
     53                             min_allocator<std::pair<const int, std::string>>> C;
     54         typedef std::pair<int, std::string> P;
     55         P a[] =
     56         {
     57             P(10, "ten"),
     58             P(20, "twenty"),
     59             P(30, "thirty"),
     60             P(40, "fourty"),
     61             P(50, "fifty"),
     62             P(60, "sixty"),
     63             P(70, "seventy"),
     64             P(80, "eighty"),
     65         };
     66         const C c(std::begin(a), std::end(a));
     67         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
     68     }
     69     {
     70         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
     71                             min_allocator<std::pair<const int, std::string>>> C;
     72         typedef std::pair<int, std::string> P;
     73         const C c;
     74         assert(c.load_factor() == 0);
     75     }
     76 #endif
     77 }
     78