当前位置: 首页>>代码示例>>Golang>>正文


Golang Hash32.Reset方法代码示例

本文整理汇总了Golang中hash.Hash32.Reset方法的典型用法代码示例。如果您正苦于以下问题:Golang Hash32.Reset方法的具体用法?Golang Hash32.Reset怎么用?Golang Hash32.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hash.Hash32的用法示例。


在下文中一共展示了Hash32.Reset方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: testIncremental

func testIncremental(t *testing.T, h hash.Hash32, result uint32, which string) {

	h.Reset()

	h.Write([]byte("hello"))
	h.Write([]byte("h"))
	h.Write([]byte("e"))
	h.Write([]byte("l"))
	h.Write([]byte("l"))
	h.Write([]byte("o"))
	h.Write([]byte("hellohello"))

	h32 := h.Sum32()

	if h32 != result {
		t.Errorf("%s: incremental failed: got %08x", which, h32)
	}

	h.Reset()
	h.Write([]byte("hellohellohellohello"))

	h32 = h.Sum32()

	if h32 != result {
		t.Errorf("%s: failed: got %08x", which, h32)
	}
}
开发者ID:rakitzis,项目名称:dgohash,代码行数:27,代码来源:hashes_test.go

示例2: testIncremental

func testIncremental(t *testing.T, h hash.Hash32, result uint32, which string) {

	h.Reset()

	var parts = []string{
		"h",
		"ell",
		"o",
		"he",
		"llo",
		"hellohello",
	}

	for _, p := range parts {
		l, _ := h.Write([]byte(p))
		if l != len(p) {
			t.Errorf("Write(%d bytes) = %d, want %d\n", len(p), l, len(p))
		}
	}

	h32 := h.Sum32()

	if h32 != result {
		t.Errorf("%s: incremental failed: got %08x", which, h32)
	}

	h.Reset()
	h.Write([]byte("hellohellohellohello"))

	h32 = h.Sum32()

	if h32 != result {
		t.Errorf("%s: failed: got %08x", which, h32)
	}
}
开发者ID:dgryski,项目名称:dgohash,代码行数:35,代码来源:hashes_test.go

示例3: commonBench

func commonBench(b *testing.B, h hash.Hash32, golden []_Golden) {
	for i := 0; i < b.N; i++ {
		for _, g := range golden {
			h.Reset()
			h.Write([]byte(g.in))
			h.Sum32()
		}
	}
}
开发者ID:rakitzis,项目名称:dgohash,代码行数:9,代码来源:hashes_test.go

示例4: imageHash

func imageHash(h hash.Hash32, dir *Directory, img *Image) int {
	h.Reset()
	h.Write([]byte(dir.RelPat()))
	h.Write([]byte(img.Name()))
	bytes, err := img.FileTime().MarshalBinary()
	if err == nil {
		h.Write(bytes)
	}
	return int(h.Sum32())
}
开发者ID:toutizes,项目名称:go-photos,代码行数:10,代码来源:indexer.go

示例5: FilesPathToPartition

// FilesPathToPartition hashes a file path to a partition.
func FilesPathToPartition(h hash.Hash32,
	partitions []string, path string) string {
	if len(partitions) <= 0 {
		return ""
	}

	h.Reset()
	io.WriteString(h, path)
	i := h.Sum32() % uint32(len(partitions))
	return partitions[i]
}
开发者ID:couchbase,项目名称:cbgt,代码行数:12,代码来源:feed_files.go

示例6: GetShard

// Returns shard under given key
func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared {
	hasherAsInterface := hashPool.Get()
	var hasher hash.Hash32
	if hasherAsInterface == nil {
		hasher = fnv.New32()
	} else {
		hasher = hasherAsInterface.(hash.Hash32)
		hasher.Reset()
	}
	hasher.Write([]byte(key))
	sum := hasher.Sum32()
	hashPool.Put(hasher)
	return m[uint(sum)%uint(SHARD_COUNT)]
}
开发者ID:jojimt,项目名称:netplugin,代码行数:15,代码来源:concurrent_map.go

示例7: becnchmark

func becnchmark(b *testing.B, h hash.Hash32, n int64) {
	b.SetBytes(n)
	data := make([]byte, n)
	for i := range data {
		data[i] = byte(i)
	}
	in := make([]byte, 0, h.Size())
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		h.Reset()
		h.Write(data)
		h.Sum(in)
	}
}
开发者ID:wangtuanjie,项目名称:crc32,代码行数:15,代码来源:crc32_test.go

示例8: benchmark

func benchmark(b *testing.B, h hash.Hash32, n, alignment int64) {
	b.SetBytes(n)
	data := make([]byte, n+alignment)
	data = data[alignment:]
	for i := range data {
		data[i] = byte(i)
	}
	in := make([]byte, 0, h.Size())

	// Warm up
	h.Reset()
	h.Write(data)
	h.Sum(in)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		h.Reset()
		h.Write(data)
		h.Sum(in)
	}
}
开发者ID:achanda,项目名称:go,代码行数:21,代码来源:crc32_test.go

示例9: testGolden

func testGolden(t *testing.T, h hash.Hash32, golden []_Golden, which string) {

	for _, g := range golden {
		h.Reset()
		h.Write([]byte(g.in))

		sum := h.Sum32()

		if sum != g.out {
			t.Errorf("%s(%s) = 0x%x want 0x%x", which, g.in, sum, g.out)
		}

		bsum := h.Sum(nil)

		if len(bsum) != 4 {
			t.Errorf("%s Sum(nil) returned %d bytes, wanted 4: %s\n", which, len(bsum), bsum)
		}

		s := binary.BigEndian.Uint32(bsum)

		if s != sum {
			t.Errorf("%s(%s).Sum(nil) = 0x%x want 0x%x", which, g.in, sum, g.out)
		}

		bsum = h.Sum([]byte{0x01, 0x02, 0x03, 0x04})

		if len(bsum) != 8 {
			t.Errorf("%s Sum(bsum) returned %d bytes, wanted 8: %x\n", which, len(bsum), bsum)
		}

		s = binary.BigEndian.Uint32(bsum[0:])
		s2 := binary.BigEndian.Uint32(bsum[4:])

		if s != 0x01020304 || s2 != sum {
			t.Errorf("%s(%s).Sum(bsum) = %x (expected 0x01020304 %x )", which, g.in, bsum, sum)
		}

	}
}
开发者ID:rakitzis,项目名称:dgohash,代码行数:39,代码来源:hashes_test.go

示例10: SeriesHash

// SeriesHash returns a hash of the metric, tags pair. The hash falls in uint16
// range.
func (c cmd) SeriesHash(hash hash.Hash32) int {
	hash.Reset()
	buf := c.Point()
	// include Metric
	i := bytes.IndexByte(buf, ' ')
	hash.Write(buf[:i])
	buf = buf[i+1:]
	// exclude Time
	i = bytes.IndexByte(buf, ' ')
	buf = buf[i+1:]
	// exclude Value
	i = bytes.IndexByte(buf, ' ')
	// include Tags
	hash.Write(buf[i:])
	// Sum
	sum := hash.Sum32()
	return int(uint16(sum))
}
开发者ID:The-Cloud-Source,项目名称:opentsp,代码行数:20,代码来源:client.go

示例11: Put

func (p *xxhPool) Put(h hash.Hash32) {
	h.Reset()
	p.Pool.Put(h)
}
开发者ID:curiositycasualty,项目名称:packer,代码行数:4,代码来源:lz4.go

示例12: ReleaseCRC32Checksum

// ReleaseCRC32Checksum releases a CRC32 back to the allocation pool.
func ReleaseCRC32Checksum(crc hash.Hash32) {
	crc.Reset()
	crc32Pool.Put(crc)
}
开发者ID:husttom,项目名称:cockroach,代码行数:5,代码来源:encoding.go

示例13: Hash32

// Hash32 is a convenience method for hashing a string against a hash.Hash32
func Hash32(s string, h hash.Hash32) uint32 {
	h.Reset()
	h.Write([]byte(s))
	return h.Sum32()
}
开发者ID:iNamik,项目名称:go_pkg,代码行数:6,代码来源:hasher32.go

示例14:

		})

		It("has no error", func() {
			_, err := jhash.Write(key)
			Expect(err).To(BeNil())
		})

	})

	Describe("Reset", func() {

		It("sets back to 0", func() {
			Expect(jhash.Sum32()).To(Equal(uint32(0)))
			jhash.Write(key)
			Expect(jhash.Sum32()).NotTo(Equal(uint32(0)))
			jhash.Reset()
			Expect(jhash.Sum32()).To(Equal(uint32(0)))
		})

	})

	Describe("Size", func() {

		It("is 4", func() {
			Expect(jhash.Size()).To(Equal(4))
		})

	})

	Describe("BlockSize", func() {
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:30,代码来源:jenkins_test.go


注:本文中的hash.Hash32.Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。