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


Golang fnv.New32函数代码示例

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


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

示例1: ModHash

func (g *FieldGrouping) ModHash(tuple Values) uint32 {
	h := fnv.New32()
	values := g.SourceFields.Select(g.Selector, tuple)
	for _, value := range values {
		h.Write(value.Encode())
	}
	h = fnv.New32()
	return h.Sum32() % uint32(len(g.Dests))
}
开发者ID:pfeairheller,项目名称:sif,代码行数:9,代码来源:field_grouping.go

示例2: getBucketWithBuiltInHasher

// Get bucket (or sharded map) by key in 1 cache instance with built in hash function of Golang
func (cache *Cache) getBucketWithBuiltInHasher(key string) (*ConcurrentMap, uint) {
	hasher := fnv.New32()
	hasher.Write([]byte(key))
	bucketsCount := len(cache.buckets)
	bucketIndex := uint(hasher.Sum32()) % uint(bucketsCount)
	return cache.buckets[bucketIndex], bucketIndex
}
开发者ID:minhduccm,项目名称:goconcache,代码行数:8,代码来源:concache.go

示例3: BenchmarkFnv32

func BenchmarkFnv32(b *testing.B) {
	h := fnv.New32()
	for i := 0; i < b.N; i++ {
		h.Write(in)
		h.Sum(nil)
	}
}
开发者ID:panamafrancis,项目名称:xxhash,代码行数:7,代码来源:xxhash_test.go

示例4: Key

func (self matchHash) Key(target matchHash) uint32 {
	hasher := fnv.New32()
	for k, s := range self {
		var value, mask []byte
		if bKey, ok := k.(OxmKeyBasic); !ok || oxm.Header(bKey).Class() != ofp4.OFPXMC_OPENFLOW_BASIC {
			continue
		} else {
			length, _ := ofp4.OxmOfDefs(uint32(bKey))
			value = make([]byte, length)
			mask = make([]byte, length)
		}
		if t, ok := target[k]; ok {
			a := s.(OxmValueMask)
			b := t.(OxmValueMask)
			for i, _ := range mask {
				mask[i] = 0xFF
			}
			if a.Mask != nil {
				for i, _ := range mask {
					mask[i] &= a.Mask[i]
				}
			}
			if b.Mask != nil {
				for i, _ := range mask {
					mask[i] &= b.Mask[i]
				}
			}
			for i, _ := range value {
				value[i] = b.Value[i] & mask[i]
			}
		}
		hasher.Write(value)
	}
	return hasher.Sum32()
}
开发者ID:hkwi,项目名称:gopenflow,代码行数:35,代码来源:match.go

示例5: computeHash

// Computes the hash of the cursor by computing the hash of every enpdoint supplied
func computeHash(endpoints []loadbalance.Endpoint) uint32 {
	h := fnv.New32()
	for _, endpoint := range endpoints {
		h.Write([]byte(endpoint.Id()))
	}
	return h.Sum32()
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:8,代码来源:cursor.go

示例6: hashKey

// hashKey hashes a key into a uint32
func hashKey(key []byte) uint32 {

	// need to convert to a []byte
	h := fnv.New32()
	h.Write(key)
	return h.Sum32()
}
开发者ID:eliothedeman,项目名称:immut,代码行数:8,代码来源:trie.go

示例7: init

// init initializes the matcher.
func (m *matcher) init(prog *syntax.Prog, n int) error {
	m.prog = prog
	m.dstate = make(map[uint32]*dstate)
	m.numMatch = n
	m.maxState = 10
	m.allTail = &m.all
	m.numByte = 256
	for i := range m.undo {
		m.undo[i] = byte(i)
	}
	m.h = fnv.New32()

	m.z1.q.Init(uint32(len(prog.Inst)))
	m.z2.q.Init(uint32(len(prog.Inst)))
	m.z3.q.Init(uint32(len(prog.Inst)))
	m.ids = make([]int, 0, len(prog.Inst))

	m.addq(&m.z1.q, uint32(prog.Start), syntax.EmptyBeginLine|syntax.EmptyBeginText)
	m.z1.flag = flagBOL | flagBOT
	m.start = m.cache(&m.z1, nil, 0)

	m.z1.q.Reset()
	m.addq(&m.z1.q, uint32(prog.Start), syntax.EmptyBeginLine)
	m.z1.flag = flagBOL
	m.startLine = m.cache(&m.z1, nil, 0)

	m.crunchProg()

	return nil
}
开发者ID:0x7cc,项目名称:rsc,代码行数:31,代码来源:match.go

示例8: NewInverseBloomFilter

// NewInverseBloomFilter creates and returns a new InverseBloomFilter with the
// specified capacity.
func NewInverseBloomFilter(capacity uint) *InverseBloomFilter {
	return &InverseBloomFilter{
		array:    make([]*[]byte, capacity),
		hash:     fnv.New32(),
		capacity: capacity,
	}
}
开发者ID:robmurtha,项目名称:BoomFilters,代码行数:9,代码来源:inverse.go

示例9: fnv32

func (e *Engine) fnv32() error {
	data, err := computeHash(fnv.New32(), e.stack.Pop())
	if err == nil {
		e.stack.Push(data)
	}
	return err
}
开发者ID:ancientlore,项目名称:hashsrv,代码行数:7,代码来源:hash.go

示例10: TestHyperLogLogIntersectLarge

func TestHyperLogLogIntersectLarge(t *testing.T) {
	rand.Seed(time.Now().UnixNano())

	runs := uint64(10000000)
	registerSize := uint(2048)

	a, _ := New(registerSize)
	b, _ := New(registerSize)
	hash := fnv.New32()

	for i := uint64(0); i < runs; i++ {
		hash.Write([]byte(randStringBytesMaskImprSrc(10)))
		s := hash.Sum32()
		a.Add(s)
		if i%2 == 0 {
			b.Add(s)
		}
		hash.Reset()
	}

	intersected, _ := a.Intersect(b)
	maxIntersect := (float64(runs) / 2) * 1.022
	minIntersect := (float64(runs) / 2) * 0.988

	if float64(intersected) > maxIntersect || float64(intersected) < minIntersect {
		log.Printf("Intersect exceeded deviation bounderies (min: %f max: %f result: %d)", minIntersect, maxIntersect, intersected)
		t.Fail()
	}
}
开发者ID:flxReinoud,项目名称:hyperloglog,代码行数:29,代码来源:hyperloglog_test.go

示例11: TestHyperLogLogIntersectNone

func TestHyperLogLogIntersectNone(t *testing.T) {
	a, _ := New(2048)
	b, _ := New(2048)

	hash := fnv.New32()

	// Apple in both
	hash.Write([]byte("apple"))
	s := hash.Sum32()
	a.Add(s)
	hash.Reset()

	// Beer in both
	hash.Write([]byte("beer"))
	s = hash.Sum32()
	a.Add(s)
	hash.Reset()

	// Banana in a
	hash.Write([]byte("banana"))
	s = hash.Sum32()
	a.Add(s)
	hash.Reset()

	intersected, _ := a.Intersect(b)
	log.Printf("none %d", intersected)
}
开发者ID:flxReinoud,项目名称:hyperloglog,代码行数:27,代码来源:hyperloglog_test.go

示例12: computeOffsets

func computeOffsets(index *nodeIndex, n *trieNode) int64 {
	if n.leaf {
		return n.value
	}
	hasher := fnv.New32()
	// We only index continuation bytes.
	for i := 0; i < blockSize; i++ {
		v := int64(0)
		if nn := n.table[0x80+i]; nn != nil {
			v = computeOffsets(index, nn)
		}
		hasher.Write([]byte{byte(v >> 24), byte(v >> 16), byte(v >> 8), byte(v)})
	}
	h := hasher.Sum32()
	if n.isInternal() {
		v, ok := index.lookupBlockIdx[h]
		if !ok {
			v = int64(len(index.lookupBlocks))
			index.lookupBlocks = append(index.lookupBlocks, n)
			index.lookupBlockIdx[h] = v
		}
		n.value = v
	} else {
		v, ok := index.valueBlockIdx[h]
		if !ok {
			v = int64(len(index.valueBlocks))
			index.valueBlocks = append(index.valueBlocks, n)
			index.valueBlockIdx[h] = v
		}
		n.value = v
	}
	return n.value
}
开发者ID:scottfranklin,项目名称:golang_exp,代码行数:33,代码来源:trie.go

示例13: NewInverseBloomFilter

// NewInverseBloomFilter creates and returns a new InverseBloomFilter with the
// specified capacity.
func NewInverseBloomFilter(capacity uint) *InverseBloomFilter {
	return &InverseBloomFilter{
		array:    make([]*[]byte, capacity),
		hashPool: &sync.Pool{New: func() interface{} { return fnv.New32() }},
		capacity: capacity,
	}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:9,代码来源:inverse.go

示例14: getShard

// getShard gets the shard responsible for the given key
func (pm *ParMap) getShard(key string) *shard {
	hasher := fnv.New32()
	hasher.Write([]byte(key))
	shard := pm.shards[hasher.Sum32()%pm.count]

	return shard
}
开发者ID:pombredanne,项目名称:pbtc,代码行数:8,代码来源:parmap.go

示例15: testHyperLogLog

func testHyperLogLog(t *testing.T, n, low_b, high_b int) {
	words := dictionary(n)
	bad := 0
	n_words := uint64(len(words))
	for i := low_b; i < high_b; i++ {
		m := uint(math.Pow(2, float64(i)))

		h, err := New(m)
		if err != nil {
			t.Fatalf("can't make New(%d): %v", m, err)
		}

		hash := fnv.New32()
		for _, word := range words {
			hash.Write([]byte(word))
			h.Add(hash.Sum32())
			hash.Reset()
		}

		expected_error := 1.04 / math.Sqrt(float64(m))
		actual_error := math.Abs(geterror(n_words, h.Count()))

		if actual_error > expected_error {
			bad++
			t.Logf("m=%d: error=%.5f, expected <%.5f; actual=%d, estimated=%d\n",
				m, actual_error, expected_error, n_words, h.Count())
		}

	}
	t.Logf("%d of %d tests exceeded estimated error", bad, high_b-low_b)
}
开发者ID:eclesh,项目名称:hyperloglog,代码行数:31,代码来源:hyperloglog_test.go


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