Beispiel #1
0
func TestHulkSmash(t *testing.T) {
	const C = 10000
	rnd, typ := rand.New(rand.NewSource(time.Now().UnixNano())), reflect.TypeOf([]byte(nil))
	for i := 0; i < C; i++ {
		v, ok := quick.Value(typ, rnd)
		if !ok {
			t.Fatal("!ok")
		}
		vb := v.Bytes()
		seed := uint64(rnd.Int63())
		x64 := N.NewS64(seed)
		x64.Write(vb)
		if s1, s2 := x64.Sum64(), N.Checksum64S(vb, seed); s1 != s2 {
			t.Fatalf("len(v) = %d: %d != %d, should be %d", len(vb), s1, s2, cxx.Checksum64S(vb, seed))
		}
		x32 := N.NewS32(uint32(seed))
		x32.Write(vb)
		if s1, s2 := x32.Sum32(), N.Checksum32S(vb, uint32(seed)); s1 != s2 {
			t.Fatalf("len(v) = %d: %d != %d, should be %d", len(vb), s1, s2, cxx.Checksum32S(vb, uint32(seed)))
		}
	}
}
Beispiel #2
0
func fast_hash(salt, val uint64) uint64 {
	return xxhash.Checksum64S(to_byte_array(val), salt)
}
// Checksum64 returns the checksum of the input data with the seed set to 0
func Checksum64(in []byte) uint64 { return N.Checksum64S(in, 0x0) }
// Checksum64S returns the checksum of the input data with the specific seed.
func Checksum64S(in []byte, seed uint64) uint64 { return N.Checksum64S(in, seed) }