本文整理汇总了Golang中hash.Hash64.Reset方法的典型用法代码示例。如果您正苦于以下问题:Golang Hash64.Reset方法的具体用法?Golang Hash64.Reset怎么用?Golang Hash64.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hash.Hash64
的用法示例。
在下文中一共展示了Hash64.Reset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: benchmarkHash
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
}
示例2: hashUpdateOrdered
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()
}
示例3: testCollissions
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)
}
}
示例4: Hash64
// 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()
}
示例5: hashKernel
// 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])
}