github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/bloom/xxhash/xxhash.go (about)

     1  // Package xxhash is an extension of github.com/cespare/xxhash which adds
     2  // routines optimized to hash arrays of fixed size elements.
     3  package xxhash
     4  
     5  import (
     6  	"encoding/binary"
     7  	"math/bits"
     8  )
     9  
    10  const (
    11  	prime1 uint64 = 0x9E3779B185EBCA87
    12  	prime2 uint64 = 0xC2B2AE3D27D4EB4F
    13  	prime3 uint64 = 0x165667B19E3779F9
    14  	prime4 uint64 = 0x85EBCA77C2B2AE63
    15  	prime5 uint64 = 0x27D4EB2F165667C5
    16  	// Pre-computed operations because the compiler otherwise complains that the
    17  	// results overflow 64 bit integers.
    18  	prime1plus2 uint64 = 0x60EA27EEADC0B5D6 // prime1 + prime2
    19  	negprime1   uint64 = 0x61C8864E7A143579 // -prime1
    20  )
    21  
    22  func avalanche(h uint64) uint64 {
    23  	h ^= h >> 33
    24  	h *= prime2
    25  	h ^= h >> 29
    26  	h *= prime3
    27  	h ^= h >> 32
    28  	return h
    29  }
    30  
    31  func round(acc, input uint64) uint64 {
    32  	acc += input * prime2
    33  	acc = rol31(acc)
    34  	acc *= prime1
    35  	return acc
    36  }
    37  
    38  func mergeRound(acc, val uint64) uint64 {
    39  	val = round(0, val)
    40  	acc ^= val
    41  	acc = acc*prime1 + prime4
    42  	return acc
    43  }
    44  
    45  func u64(b []byte) uint64 { return binary.LittleEndian.Uint64(b) }
    46  func u32(b []byte) uint32 { return binary.LittleEndian.Uint32(b) }
    47  
    48  func rol1(x uint64) uint64  { return bits.RotateLeft64(x, 1) }
    49  func rol7(x uint64) uint64  { return bits.RotateLeft64(x, 7) }
    50  func rol11(x uint64) uint64 { return bits.RotateLeft64(x, 11) }
    51  func rol12(x uint64) uint64 { return bits.RotateLeft64(x, 12) }
    52  func rol18(x uint64) uint64 { return bits.RotateLeft64(x, 18) }
    53  func rol23(x uint64) uint64 { return bits.RotateLeft64(x, 23) }
    54  func rol27(x uint64) uint64 { return bits.RotateLeft64(x, 27) }
    55  func rol31(x uint64) uint64 { return bits.RotateLeft64(x, 31) }