function hashCode(s){ if(!s.split) { s = s.toString(); } return murmurHash3.x86.hash32(s); // return s.split("").reduce(function(a,b){ // a=((a<<5)-a)+b.charCodeAt(0); // return a&a // },0); }
export function getShardNum(shardTotal, suiteName) { const hashIntsPerShard = MAX_HASH / shardTotal; const hashInt = murmurHash3.x86.hash32(suiteName); // murmur3 produces 32bit integers, so we devide it by the number of chunks // to determine which chunk the suite should fall in. +1 because the current // chunk is 1-based const shardNum = Math.floor(hashInt / hashIntsPerShard) + 1; // It's not clear if hash32 can produce the MAX_HASH or not, // but this just ensures that shard numbers don't go out of bounds // and cause tests to be ignored unnecessarily return Math.max(1, Math.min(shardNum, shardTotal)); }
/** * Calculates, stores, and returns the index for a supplied word. * * @param {string} word * @returns {integer} word index */ addWord( word ) { const hash = murmurhash3js.x86.hash32( word ); const remainder = hash % this.dim; this.hashTable.set( word, remainder ); return remainder; }