Skip to content

Commit 6cff861

Browse files
committed
Set the default load factor
1 parent cc8bdee commit 6cff861

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/hash.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct hash_tab {
1616
//
1717
static const double hash_multiplier1 = 0.618033988749895;
1818
static const double hash_multiplier2 = 0.316227766016838;
19+
static const double default_load_factor = .5;
1920

2021
static R_INLINE size_t get_full_size(size_t n_elements, double load_factor) {
2122
if (load_factor <= 0 || load_factor >= 1)
@@ -61,7 +62,7 @@ static hashtab * hash_create_(size_t n, double load_factor) {
6162
return ret;
6263
}
6364

64-
hashtab * hash_create(size_t n) { return hash_create_(n, .5); }
65+
hashtab * hash_create(size_t n) { return hash_create_(n, default_load_factor); }
6566

6667
// double hashing
6768
static R_INLINE size_t hash_index1(SEXP key, uintptr_t multiplier) {
@@ -82,7 +83,7 @@ static R_INLINE size_t hash_index2(SEXP key, uintptr_t multiplier) {
8283

8384
void hash_rehash(hashtab *h) {
8485
size_t new_size = h->size * 2;
85-
hashtab *new_h = hash_create_(new_size, 0.5);
86+
hashtab *new_h = hash_create_(new_size, default_load_factor);
8687

8788
for (size_t i = 0; i < h->size; ++i) {
8889
if (h->table[i].key) hash_set(new_h, h->table[i].key, h->table[i].value);

0 commit comments

Comments
 (0)