Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('xxhashjs, xxhash, twice, expect 2847076442', function() {
let js1 = XXH.h32("abcd", 0x01020304).toNumber()
let js2 = XXH.h32("abcd", js1).toNumber()
let buf = new Buffer("abcd")
let ntv1 = xxhash.hash(buf, 0x01020304)
let ntv2 = xxhash.hash(buf, ntv1)
let enc = new Buffer(4)
let enc2 = new Buffer(4)
xxhash.hash(buf, 0x01020304, enc)
expect(enc.equals(new Buffer('b5bfecd1', 'hex'))).to.be.true
xxhash.hash(buf, enc.readUInt32LE(), enc)
expect(enc.readUInt32LE()).to.equal(2847076642)
})
})
it('xxhashjs, xxhash, twice, expect 2847076442', function() {
let js1 = XXH.h32("abcd", 0x01020304).toNumber()
let js2 = XXH.h32("abcd", js1).toNumber()
let buf = new Buffer("abcd")
let ntv1 = xxhash.hash(buf, 0x01020304)
let ntv2 = xxhash.hash(buf, ntv1)
let enc = new Buffer(4)
let enc2 = new Buffer(4)
xxhash.hash(buf, 0x01020304, enc)
expect(enc.equals(new Buffer('b5bfecd1', 'hex'))).to.be.true
xxhash.hash(buf, enc.readUInt32LE(), enc)
expect(enc.readUInt32LE()).to.equal(2847076642)
})
})
remove(item){
if(!Buffer.isBuffer(item)) item = Buffer.from(item);
for(let i = 0; i < this.seeds.length; ++i){
let hash = xxhash(item, this.seeds[i]).toString();
let bit = hash % this.bits;
this._unSetBit(bit);
}
}
}
export const getHashFunction = (): HashFunction => {
const hasher = h32();
hasher.init(123);
return contents =>
hasher
.update(contents)
.digest()
.toString(16);
};
export function hashString(s: string): string {
return xxhash.h32(s, 0xdeadbeef).toString(16)
}
exports.descriptorChecksum = function (d) {
return (XXH(d, CHECKSUM_SEED).toNumber() >> 8) & 0xFF
}
const getHash = contents =>
xxh.h32(0).update(String(contents)).digest().toString(16).substr(0, 8)
function hashAsInt (elem, seed = getDefaultSeed(), length = 64) {
switch (length) {
case 32:
return XXH.h32(elem, seed).toNumber()
case 64:
return XXH.h64(elem, seed).toNumber()
default:
return XXH.h64(elem, seed).toNumber()
}
}
exports.streamChecksum = function (d, c) {
if (d === null)
return c.digest().toNumber()
if (c === null)
c = XXH(CHECKSUM_SEED)
return c.update(d)
}
function hashAsString (elem, seed = getDefaultSeed(), base = 16, length = 64) {
let hash
switch (length) {
case 32:
hash = XXH.h32(elem, seed)
break
case 64:
hash = XXH.h64(elem, seed)
break
default:
hash = XXH.h64(elem, seed)
break
}
let string
if (base === 16) {
string = hash.toString(base)
if (string.length < (length / 4)) {
string = '0'.repeat((length / 4) - string.length) + string
}
} else if (base === 2) {
string = hex2bin(hash.toString(16))