///|
let prime1 : UInt64 = 0x9e3779b185ebca87UL
///|
let prime2 : UInt64 = 0xc2b2ae3d27d4eb4fUL
///|
let prime3 : UInt64 = 0x165667b19e3779f9UL
///|
let prime4 : UInt64 = 0x85ebca77c2b2ae63UL
///|
let prime5 : UInt64 = 0x27d4eb2f165667c5UL
///|
fn rotate_left(value : UInt64, bits : Int32) -> UInt64 {
(value << bits) | (value >> (64 - bits))
}
///|
fn load64(bytes : BytesView, pos : Int32) -> UInt64 {
load32(bytes, pos).to_uint64() | (load32(bytes, pos + 4).to_uint64() << 32)
}
///|
fn xx_round(acc : UInt64, lane : UInt64) -> UInt64 {
rotate_left(acc + lane * prime2, 31) * prime1
}
///|
fn xx_merge(acc : UInt64, lane : UInt64) -> UInt64 {
(acc ^ xx_round(0UL, lane)) * prime1 + prime4
}
///|
/// Lower 32 bits of the seed-zero XXH64 digest used in the seek table.
fn checksum32(bytes : BytesView) -> UInt32 {
let size = bytes.length()
let mut pos = 0
let mut hash = prime5
if size >= 32 {
let mut a = prime1 + prime2
let mut b = prime2
let mut c = 0UL
let mut d = 0UL - prime1
while pos <= size - 32 {
a = xx_round(a, load64(bytes, pos))
b = xx_round(b, load64(bytes, pos + 8))
c = xx_round(c, load64(bytes, pos + 16))
d = xx_round(d, load64(bytes, pos + 24))
pos += 32
}
hash = rotate_left(a, 1) +
rotate_left(b, 7) +
rotate_left(c, 12) +
rotate_left(d, 18)
hash = xx_merge(xx_merge(xx_merge(xx_merge(hash, a), b), c), d)
}
hash += size.to_uint64()
while pos <= size - 8 {
hash = rotate_left(hash ^ xx_round(0UL, load64(bytes, pos)), 27) * prime1 +
prime4
pos += 8
}
if pos <= size - 4 {
hash = rotate_left(hash ^ (load32(bytes, pos).to_uint64() * prime1), 23) *
prime2 +
prime3
pos += 4
}
while pos < size {
hash = rotate_left(hash ^ (bytes[pos].to_uint64() * prime5), 11) * prime1
pos += 1
}
hash = (hash ^ (hash >> 33)) * prime2
hash = (hash ^ (hash >> 29)) * prime3
(hash ^ (hash >> 32)).to_uint()
}