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


Golang murmur.HashString函数代码示例

本文整理汇总了Golang中github.com/zond/god/murmur.HashString函数的典型用法代码示例。如果您正苦于以下问题:Golang HashString函数的具体用法?Golang HashString怎么用?Golang HashString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: benchTreeSync

func benchTreeSync(b *testing.B, size, delta int) {
	b.StopTimer()
	tree1 := NewTree()
	tree2 := NewTree()
	var k []byte
	var v []byte
	for i := 0; i < size; i++ {
		k = murmur.HashString(fmt.Sprint(i))
		v = []byte(fmt.Sprint(i))
		tree1.Put(k, v, 1)
		tree2.Put(k, v, 1)
	}
	var s *Sync
	for i := 0; i < b.N/delta; i++ {
		for j := 0; j < delta; j++ {
			tree2.Del(murmur.HashString(fmt.Sprint(j)))
		}
		b.StartTimer()
		s = NewSync(tree1, tree2)
		s.Run()
		b.StopTimer()
		if bytes.Compare(tree1.Hash(), tree2.Hash()) != 0 {
			b.Fatalf("%v != %v", tree1.Hash(), tree2.Hash())
		}
	}
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:26,代码来源:radix_test.go

示例2: TestSyncSubTreeVersions

func TestSyncSubTreeVersions(t *testing.T) {
	tree1 := NewTree()
	tree3 := NewTree()
	n := 10
	var k, sk []byte
	var v []byte
	for i := 0; i < n; i++ {
		k = []byte(murmur.HashString(fmt.Sprint(i)))
		v = []byte(fmt.Sprint(i))
		if i%2 == 0 {
			tree3.Put(k, v, 1)
			tree1.Put(k, v, 1)
		} else {
			for j := 0; j < 10; j++ {
				sk = []byte(fmt.Sprint(j))
				tree1.SubPut(k, sk, v, 1)
				if i == 1 && j == 3 {
					tree3.SubPut(k, sk, []byte("another value"), 2)
				} else {
					tree3.SubPut(k, sk, v, 1)
				}
			}
		}
	}
	tree2 := NewTree()
	tree2.SubPut([]byte(murmur.HashString(fmt.Sprint(1))), []byte(fmt.Sprint(3)), []byte("another value"), 2)
	s := NewSync(tree1, tree2)
	s.Run()
	if bytes.Compare(tree1.Hash(), tree2.Hash()) == 0 {
		t.Errorf("should not be equal")
	}
	if tree1.deepEqual(tree2) {
		t.Errorf("should not be equal")
	}
	if bytes.Compare(tree3.Hash(), tree2.Hash()) != 0 {
		t.Errorf("%v and %v have hashes\n%v\n%v\nand they should be equal!", tree3.Describe(), tree2.Describe(), tree3.Hash(), tree2.Hash())
	}
	if !tree3.deepEqual(tree2) {
		t.Errorf("\n%v and \n%v are unequal", tree3.Describe(), tree2.Describe())
	}
	tree1.SubPut([]byte(murmur.HashString(fmt.Sprint(1))), []byte(fmt.Sprint(3)), []byte("another value again"), 3)
	s.Run()
	if bytes.Compare(tree3.Hash(), tree2.Hash()) == 0 {
		t.Errorf("should not be equal")
	}
	if tree3.deepEqual(tree2) {
		t.Errorf("should not be equal")
	}
	if bytes.Compare(tree1.Hash(), tree2.Hash()) != 0 {
		t.Errorf("%v and %v have hashes\n%v\n%v\nand they should be equal!", tree1.Describe(), tree2.Describe(), tree1.Hash(), tree2.Hash())
	}
	if !tree1.deepEqual(tree2) {
		t.Errorf("\n%v and \n%v are unequal", tree1.Describe(), tree2.Describe())
	}
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:55,代码来源:radix_test.go

示例3: main

func main() {
	f, err := os.Create("cpuprofile")
	if err != nil {
		panic(err.Error())
	}
	f2, err := os.Create("memprofile")
	if err != nil {
		panic(err.Error())
	}

	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()
	defer pprof.WriteHeapProfile(f2)

	benchNode := NewNodeDir("127.0.0.1:1231", "127.0.0.1:1231", "")
	benchNode.MustStart()
	var k []byte
	for i := 0; i < 100000; i++ {
		k = murmur.HashString(fmt.Sprint(i))
		benchNode.Put(common.Item{
			Key:   k,
			Value: k,
		})
	}
}
开发者ID:shawnpan,项目名称:god,代码行数:25,代码来源:profile.go

示例4: TestSyncDestructiveMatching

func TestSyncDestructiveMatching(t *testing.T) {
	tree1 := NewTree()
	tree2 := NewTree()
	tree3 := NewTree()
	n := 1000
	var k []byte
	var v []byte
	for i := 0; i < n; i++ {
		k = murmur.HashString(fmt.Sprint(i))
		v = []byte(fmt.Sprint(i))
		tree1.Put(k, v, 1)
		tree2.Put(k, v, 1)
		tree3.Put(k, v, 1)
	}
	NewSync(tree1, tree2).Destroy().Run()
	if !tree2.deepEqual(tree3) {
		t.Errorf("should be equal")
	}
	if tree1.Size() != 0 {
		t.Errorf("should be empty!")
	}
	tree4 := NewTree()
	if !tree1.deepEqual(tree4) {
		t.Errorf("should be equal!")
	}
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:26,代码来源:radix_test.go

示例5: TestSyncSubTree

func TestSyncSubTree(t *testing.T) {
	tree1 := NewTree()
	n := 10
	var k, sk []byte
	var v []byte
	for i := 0; i < n; i++ {
		k = []byte(murmur.HashString(fmt.Sprint(i)))
		v = []byte(fmt.Sprint(i))
		if i%2 == 0 {
			tree1.Put(k, v, 1)
		} else {
			for j := 0; j < 10; j++ {
				sk = []byte(fmt.Sprint(j))
				tree1.SubPut(k, sk, v, 1)
			}
		}
	}
	tree2 := NewTree()
	s := NewSync(tree1, tree2)
	s.Run()
	if bytes.Compare(tree1.Hash(), tree2.Hash()) != 0 {
		t.Errorf("%v and %v have hashes\n%v\n%v\nand they should be equal!", tree1.Describe(), tree2.Describe(), tree1.Hash(), tree2.Hash())
	}
	if !tree1.deepEqual(tree2) {
		t.Errorf("\n%v and \n%v are unequal", tree1.Describe(), tree2.Describe())
	}
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:27,代码来源:radix_test.go

示例6: benchTree

func benchTree(b *testing.B, n int, put, get bool) {
	fillBenchTree(b, n)
	b.StopTimer()
	oldprocs := runtime.GOMAXPROCS(runtime.NumCPU())
	defer runtime.GOMAXPROCS(oldprocs)
	var keys [][]byte
	var vals [][]byte
	for i := 0; i < b.N; i++ {
		keys = append(keys, murmur.HashString(fmt.Sprint(rand.Int63())))
		vals = append(vals, []byte(fmt.Sprint(rand.Int63())))
	}
	var k []byte
	var v []byte
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		k = benchmarkTestKeys[i%len(benchmarkTestKeys)]
		v = benchmarkTestValues[i%len(benchmarkTestValues)]
		if put {
			benchmarkTestTree.Put(k, v, 1)
		}
		if get {
			j, _, existed := benchmarkTestTree.Get(k)
			if bytes.Compare(j, v) != 0 {
				b.Fatalf("%v should contain %v, but got %v, %v", benchmarkTestTree.Describe(), v, j, existed)
			}
		}
	}
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:28,代码来源:radix_test.go

示例7: main

func main() {
	f, err := os.Create("cpuprofile")
	if err != nil {
		panic(err.Error())
	}
	f2, err := os.Create("memprofile")
	if err != nil {
		panic(err.Error())
	}

	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()
	defer pprof.WriteHeapProfile(f2)

	m := radix.NewTree()
	var k []byte
	for i := 0; i < 100000; i++ {
		k = murmur.HashString(fmt.Sprint(i))
		m.Put(k, k, 1)
		x, _, _ := m.Get(k)
		if bytes.Compare(x, k) != 0 {
			panic("humbug")
		}
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:25,代码来源:profile.go

示例8: testSubClear

func testSubClear(t *testing.T, c testClient) {
	var key []byte
	var value []byte
	subTree := []byte("apa")
	for i := 0; i < 10; i++ {
		key = murmur.HashString(fmt.Sprint(i))
		value = murmur.HashString(fmt.Sprint(i))
		c.SSubPut(subTree, key, value)
	}
	if c.SubSize(subTree) != 10 {
		t.Errorf("wrong size")
	}
	c.SSubClear(subTree)
	if c.SubSize(subTree) != 0 {
		t.Errorf("wrong size")
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:17,代码来源:client_test.go

示例9: main

func main() {
	a := (s(3, 30, 50, 20, 27))
	fmt.Println(a)
	fmt.Println(a)
	conn := client.MustConn("localhost:9191")
	bytes := common.MustJSONEncode(a)
	conn.Put(murmur.HashString("hi"), bytes)
}
开发者ID:Smedira,项目名称:GO-Amusement,代码行数:8,代码来源:sim.go

示例10: testGetPutDel

func testGetPutDel(t *testing.T, c testClient) {
	var key []byte
	var value []byte
	for i := 0; i < 1000; i++ {
		key = murmur.HashString(fmt.Sprint(i))
		value = murmur.HashString(fmt.Sprint(i))
		if v, e := c.Get(key); v != nil || e {
			t.Errorf("shouldn't exist")
		}
		c.SPut(key, value)
		if v, e := c.Get(key); bytes.Compare(value, v) != 0 || !e {
			t.Fatalf("should exist, but got %v => %v, %v", key, v, e)
		}
		c.SDel(key)
		if v, e := c.Get(key); v != nil || e {
			t.Errorf("shouldn't exist, but got %v => %v, %v", key, v, e)
		}
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:19,代码来源:client_test.go

示例11: fillBenchTree

func fillBenchTree(b *testing.B, n int) {
	b.StopTimer()
	for len(benchmarkTestKeys) < n {
		benchmarkTestKeys = append(benchmarkTestKeys, murmur.HashString(fmt.Sprint(len(benchmarkTestKeys))))
		benchmarkTestValues = append(benchmarkTestValues, []byte(fmt.Sprint(len(benchmarkTestValues))))
	}
	for benchmarkTestTree.Size() < n {
		benchmarkTestTree.Put(benchmarkTestKeys[benchmarkTestTree.Size()], benchmarkTestValues[benchmarkTestTree.Size()], 1)
	}
	b.StartTimer()
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:11,代码来源:radix_test.go

示例12: main

func main() {
	// connect to the default local server
	conn := client.MustConn("localhost:9191")
	// create a user

	// try to fetch the user again
	data, _ := conn.Get(murmur.HashString("hi"))
	var found []int
	// to unserialize it
	common.MustJSONDecode(data, &found)
	fmt.Printf("stored and found ", found)
}
开发者ID:Smedira,项目名称:GO-Amusement,代码行数:12,代码来源:test.go

示例13: TestSyncRandomLimits

func TestSyncRandomLimits(t *testing.T) {
	tree1 := NewTree()
	n := 10
	var k []byte
	var v []byte
	for i := 0; i < n; i++ {
		k = murmur.HashString(fmt.Sprint(i))
		v = []byte(fmt.Sprint(i))
		tree1.Put(k, v, 1)
	}
	var keys [][]byte
	tree1.Each(func(key []byte, byteValue []byte, timestamp int64) bool {
		keys = append(keys, key)
		return true
	})
	var fromKey []byte
	var toKey []byte
	var tree2 *Tree
	var tree3 *Tree
	var s *Sync
	for fromIndex, _ := range keys {
		for toIndex, _ := range keys {
			if fromIndex != toIndex {
				fromKey = keys[fromIndex]
				toKey = keys[toIndex]
				if bytes.Compare(fromKey, toKey) < 0 {
					tree2 = NewTree()
					tree1.Each(func(key []byte, byteValue []byte, timestamp int64) bool {
						if common.BetweenIE(key, fromKey, toKey) {
							tree2.Put(key, byteValue, 1)
						}
						return true
					})
					tree3 = NewTree()
					s = NewSync(tree1, tree3).From(fromKey).To(toKey)
					s.Run()
					if !tree3.deepEqual(tree2) {
						t.Errorf("when syncing from %v to %v, %v and %v have hashes\n%v\n%v\nand they should be equal!", common.HexEncode(fromKey), common.HexEncode(toKey), tree3.Describe(), tree2.Describe(), tree3.Hash(), tree2.Hash())
					}
				}
			}
		}
	}
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:44,代码来源:radix_test.go

示例14: BenchmarkClientAndServer

func BenchmarkClientAndServer(b *testing.B) {
	oldprocs := runtime.GOMAXPROCS(runtime.NumCPU())
	defer runtime.GOMAXPROCS(oldprocs)
	b.StopTimer()
	if benchNode == nil {
		benchNode = NewNode("127.0.0.1:1231", "127.0.0.1:1231")
		benchNode.MustStart()
	}
	c := client.MustConn("127.0.0.1:1231")
	c.Clear()
	var bs [][]byte
	for i := 0; i < b.N; i++ {
		bs = append(bs, murmur.HashString(fmt.Sprint(i)))
	}
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		c.Put(bs[i], bs[i])
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:19,代码来源:client_test.go

示例15: BenchmarkServer

func BenchmarkServer(b *testing.B) {
	oldprocs := runtime.GOMAXPROCS(runtime.NumCPU())
	defer runtime.GOMAXPROCS(oldprocs)
	b.StopTimer()
	if benchNode == nil {
		benchNode = NewNode("127.0.0.1:1231", "127.0.0.1:1231")
		benchNode.MustStart()
	}
	benchNode.Clear()
	var bs [][]byte
	for i := 0; i < b.N; i++ {
		bs = append(bs, murmur.HashString(fmt.Sprint(i)))
	}
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		benchNode.Put(common.Item{
			Key:   bs[i],
			Value: bs[i],
		})
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:21,代码来源:client_test.go


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