Skip to content

Commit

Permalink
Adjust threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichon-msft committed Feb 1, 2024
1 parent a5f96ee commit cd6d64e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/util/numberHash.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit cd6d64e

Please sign in to comment.