Skip to content

Commit d95d3bb

Browse files
Use ceiling instead of rounding when calculating number of buckets (#3687)
1 parent d3a7da7 commit d95d3bb

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

stl/inc/xhash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ public:
926926
}
927927

928928
void reserve(size_type _Maxcount) { // rebuild table with room for _Maxcount elements
929-
rehash(static_cast<size_type>(static_cast<float>(_Maxcount) / max_load_factor() + 0.5F));
929+
rehash(_Min_load_factor_buckets(_Maxcount));
930930
}
931931

932932
conditional_t<_Multi, iterator, pair<iterator, bool>> insert(const value_type& _Val) {

tests/std/test.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ tests\GH_000545_include_compare
171171
tests\GH_000625_vector_bool_optimization
172172
tests\GH_000685_condition_variable_any
173173
tests\GH_000690_overaligned_function
174+
tests\GH_000732_hash_reserve
174175
tests\GH_000890_pow_template
175176
tests\GH_000935_complex_numerical_accuracy
176177
tests\GH_000940_missing_valarray_copy
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
RUNALL_INCLUDE ..\usual_matrix.lst
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <cassert>
5+
#include <unordered_set>
6+
7+
using namespace std;
8+
9+
int main() {
10+
unordered_set<int> a;
11+
a.max_load_factor(24.0f / 64.25f);
12+
a.reserve(24);
13+
assert(a.bucket_count() > 64);
14+
return 0;
15+
}

0 commit comments

Comments
 (0)