Adjust threshold

This commit is contained in:
David Michon 2024-01-31 16:20:27 -08:00
parent a5f96ee77c
commit cd6d64e511
1 changed files with 3 additions and 3 deletions

View File

@ -6,10 +6,10 @@
"use strict";
/**
* The maximum safe integer value for 32-bit signed integers.
* Threshold for switching from 32-bit to 64-bit hashing. This is selected to ensure that the bias towards lower modulo results when using 32-bit hashing is <0.5%.
* @type {number}
*/
const SAFE_LIMIT = 0x80000000;
const FNV_64_THRESHOLD = 1 << 24;
/**
* The FNV-1a offset basis for 32-bit hash values.
@ -103,7 +103,7 @@ function fnv1a64(str) {
*
*/
module.exports = (str, range) => {
if (range < SAFE_LIMIT) {
if (range < FNV_64_THRESHOLD) {
return fnv1a32(str) % range;
} else {
return Number(fnv1a64(str) % BigInt(range));