Skip to content

Commit 5a474e0

Browse files
committed
change multipliers
1 parent b017013 commit 5a474e0

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/hash.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@ struct hash_tab {
1212
struct hash_pair *tb1, *tb2;
1313
};
1414

15-
// Fast integer hash multipliers based on golden ratio and other constants
16-
// 0x9e3779b9 is 2^32 * phi (golden ratio) for 32-bit mixing
17-
#if SIZE_MAX == UINT64_MAX
18-
static const uintptr_t hash_multiplier1 = 0x9e3779b97f4a7c15ULL;
19-
static const uintptr_t hash_multiplier2 = 0x85ebca77c2b2ae35ULL;
20-
#else
21-
static const uintptr_t hash_multiplier1 = 0x9e3779b9U;
22-
static const uintptr_t hash_multiplier2 = 0x85ebca77U;
23-
#endif
15+
// TAOCP vol. 3, section 6.4: for multiplication hashing, use A ~ 1/phi, the golden ratio.
16+
//
17+
static const double hash_multiplier1 = 0.618033988749895;
18+
static const double hash_multiplier2 = 0.316227766016838;
2419

2520
static R_INLINE size_t get_full_size(size_t n_elements, double load_factor) {
2621
if (load_factor <= 0 || load_factor >= 1)

0 commit comments

Comments
 (0)