immutablejs源码中这个计算数字哈希的函数的怎么理解?
function hashNum(o) {
var type = typeof o;
if (type === 'number') {
if (o !== o || o === Infinity) {
return 0;
}
var h = o | 0;
if (h !== o) {
h ^= o * 0xFFFFFFFF;
}
while (o > 0xFFFFFFFF) {
o /= 0xFFFFFFFF;
h ^= o;
}
return smi(h);
}
}
// v8 has an optimization(优化组合) for storing 31-bit signed numbers(有正负符号数).
// Values which have either 00 or 11 as the high order bits(高字节位) qualify(限定).
// This function drops the highest order bit in a signed number(有正负符号数), maintaining(坚持,保卫)
// the sign bit(符号位).
function smi(i32) {
return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
}
慕姐8265434
相关分类