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_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> |
Howard Hinnant | f836d53 | 2011-12-02 21:23:14 +0000 | [diff] [blame] | 21 | #include <cfloat> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | |
Eric Fiselier | fd9bbf5 | 2015-07-19 03:16:47 +0000 | [diff] [blame] | 23 | #include "test_macros.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 24 | #include "min_allocator.h" |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 25 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | int main() |
| 27 | { |
| 28 | { |
| 29 | typedef std::unordered_map<int, std::string> C; |
| 30 | typedef std::pair<int, std::string> P; |
| 31 | P a[] = |
| 32 | { |
| 33 | P(10, "ten"), |
| 34 | P(20, "twenty"), |
| 35 | P(30, "thirty"), |
Alp Toker | 08f8ac6 | 2014-05-15 11:33:29 +0000 | [diff] [blame] | 36 | P(40, "forty"), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | P(50, "fifty"), |
| 38 | P(60, "sixty"), |
| 39 | P(70, "seventy"), |
| 40 | P(80, "eighty"), |
| 41 | }; |
| 42 | const C c(std::begin(a), std::end(a)); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 43 | assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 44 | } |
| 45 | { |
| 46 | typedef std::unordered_map<int, std::string> C; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | const C c; |
| 48 | assert(c.load_factor() == 0); |
| 49 | } |
Eric Fiselier | fd9bbf5 | 2015-07-19 03:16:47 +0000 | [diff] [blame] | 50 | #if TEST_STD_VER >= 11 |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 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"), |
Alp Toker | 08f8ac6 | 2014-05-15 11:33:29 +0000 | [diff] [blame] | 60 | P(40, "forty"), |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 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)); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 67 | assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 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; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 72 | const C c; |
| 73 | assert(c.load_factor() == 0); |
| 74 | } |
| 75 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 76 | } |