func benchmarkHash(b *testing.B, h hash.Hash64) { uids := getUids(b.N) var s uint64 b.ResetTimer() for i := 0; i < b.N; i++ { h.Reset() io.WriteString(h, uids[i]) s = h.Sum64() } result = s }
func hashUpdateOrdered(h hash.Hash64, a, b uint64) uint64 { // For ordered updates, use a real hash function h.Reset() // We just panic if the binary writes fail because we are writing // an int64 which should never be fail-able. e1 := binary.Write(h, binary.LittleEndian, a) e2 := binary.Write(h, binary.LittleEndian, b) if e1 != nil { panic(e1) } if e2 != nil { panic(e2) } return h.Sum64() }
func testCollissions(t *testing.T, h hash.Hash64) { uids := getUids(uidSize) results := make(map[uint64]bool) cols := 0 for i := 0; i < uidSize; i++ { h.Reset() io.WriteString(h, uids[i]) s := h.Sum64() if _, col := results[s]; col { cols += 1 } else { results[s] = true } } if cols > 0 { t.Errorf("Found %v collissions for uidSize %v\n", cols, uidSize) } }
// Hash64 is a convenience method for hashing a string against a hash.Hash64 func Hash64(s string, h hash.Hash64) uint64 { h.Reset() h.Write([]byte(s)) return h.Sum64() }
// hashKernel returns the upper and lower base hash values from which the k // hashes are derived. func hashKernel(data []byte, hash hash.Hash64) (uint32, uint32) { hash.Write(data) sum := hash.Sum(nil) hash.Reset() return binary.BigEndian.Uint32(sum[4:8]), binary.BigEndian.Uint32(sum[0:4]) }