github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/bloom/hash.go (about) 1 package bloom 2 3 import "github.com/vc42/parquet-go/bloom/xxhash" 4 5 // Hash is an interface abstracting the hashing algorithm used in bloom filters. 6 // 7 // Hash instances must be safe to use concurrently from multiple goroutines. 8 type Hash interface { 9 // Returns the 64 bit hash of the value passed as argument. 10 Sum64(value []byte) uint64 11 12 // Compute hashes of individual values of primitive types. 13 Sum64Uint8(value uint8) uint64 14 Sum64Uint16(value uint16) uint64 15 Sum64Uint32(value uint32) uint64 16 Sum64Uint64(value uint64) uint64 17 Sum64Uint128(value [16]byte) uint64 18 19 // Compute hashes of the array of fixed size values passed as arguments, 20 // returning the number of hashes written to the destination buffer. 21 MultiSum64Uint8(dst []uint64, src []uint8) int 22 MultiSum64Uint16(dst []uint64, src []uint16) int 23 MultiSum64Uint32(dst []uint64, src []uint32) int 24 MultiSum64Uint64(dst []uint64, src []uint64) int 25 MultiSum64Uint128(dst []uint64, src [][16]byte) int 26 } 27 28 // XXH64 is an implementation of the Hash interface using the XXH64 algorithm. 29 type XXH64 struct{} 30 31 func (XXH64) Sum64(b []byte) uint64 { 32 return xxhash.Sum64(b) 33 } 34 35 func (XXH64) Sum64Uint8(v uint8) uint64 { 36 return xxhash.Sum64Uint8(v) 37 } 38 39 func (XXH64) Sum64Uint16(v uint16) uint64 { 40 return xxhash.Sum64Uint16(v) 41 } 42 43 func (XXH64) Sum64Uint32(v uint32) uint64 { 44 return xxhash.Sum64Uint32(v) 45 } 46 47 func (XXH64) Sum64Uint64(v uint64) uint64 { 48 return xxhash.Sum64Uint64(v) 49 } 50 51 func (XXH64) Sum64Uint128(v [16]byte) uint64 { 52 return xxhash.Sum64Uint128(v) 53 } 54 55 func (XXH64) MultiSum64Uint8(h []uint64, v []uint8) int { 56 return xxhash.MultiSum64Uint8(h, v) 57 } 58 59 func (XXH64) MultiSum64Uint16(h []uint64, v []uint16) int { 60 return xxhash.MultiSum64Uint16(h, v) 61 } 62 63 func (XXH64) MultiSum64Uint32(h []uint64, v []uint32) int { 64 return xxhash.MultiSum64Uint32(h, v) 65 } 66 67 func (XXH64) MultiSum64Uint64(h []uint64, v []uint64) int { 68 return xxhash.MultiSum64Uint64(h, v) 69 } 70 71 func (XXH64) MultiSum64Uint128(h []uint64, v [][16]byte) int { 72 return xxhash.MultiSum64Uint128(h, v) 73 } 74 75 var ( 76 _ Hash = XXH64{} 77 )