| ... | @@ -139,9 +139,9 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 | ... | @@ -139,9 +139,9 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 |
| 139 | // ensure that the hash map will be at most 60% full if | 139 | // ensure that the hash map will be at most 60% full if |
| 140 | // expected_count items are put into it | 140 | // expected_count items are put into it |
| 141 | var optimized_capacity = expected_count * 5 / 3; | 141 | var optimized_capacity = expected_count * 5 / 3; |
| 142 | // round capacity to the next power of two | 142 | // an overflow here would mean the amount of memory required would not |
| 143 | const pow = math.log2_int_ceil(usize, optimized_capacity); | 143 | // be representable in the address space |
| 144 | return math.pow(usize, 2, pow); | 144 | return math.ceilPowerOfTwo(usize, optimized_capacity) catch unreachable; |
| 145 | } | 145 | } |
| 146 | | 146 | |
| 147 | /// Increases capacity so that the hash map will be at most | 147 | /// Increases capacity so that the hash map will be at most |