本文整理汇总了Golang中hash/fnv.New64a函数的典型用法代码示例。如果您正苦于以下问题:Golang New64a函数的具体用法?Golang New64a怎么用?Golang New64a使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New64a函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: hash
func hash(v interface{}) int {
switch v := v.(type) {
case []interface{}:
var h int
for _, e := range v {
h += hash(e)
}
return h
case map[string]interface{}:
var h int
for k, v := range v {
h += hash(k) + hash(v)
}
return h
case string:
h := fnv.New64a()
h.Write([]byte(v))
return int(h.Sum64())
case bool:
if v {
return 1
}
return 0
case nil:
return 0
case json.Number:
h := fnv.New64a()
h.Write([]byte(v))
return int(h.Sum64())
}
panic(fmt.Sprintf("illegal argument: %v (%T)", v, v))
}
开发者ID:tsandall,项目名称:opa,代码行数:32,代码来源:index.go
示例2: putGetParallel
func putGetParallel(power int, factor float64) {
var h Hashmap
h = NewChainedHash(power, fnv.New64a())
n := uint64(math.Pow(2, float64(power)))
var wg sync.WaitGroup
wg.Add(2)
go func() {
for i := uint64(0); i < uint64((float64(n) * factor)); i++ {
h.Put(strconv.FormatUint(i, 10), strconv.FormatUint(i, 10))
}
wg.Done()
}()
go func() {
for cycle := 0; cycle < 5; cycle++ {
for i := uint64(0); i < n; i++ {
h.Get(strconv.FormatUint(i, 10))
}
}
wg.Done()
}()
wg.Wait()
}
开发者ID:nmjmdr,项目名称:chainedconcurrenthash,代码行数:29,代码来源:Benchmark_test.go
示例3: hashKey
func (c *myCipher) hashKey(key string) {
k := []byte(key)
hash := fnv.New64a()
hash.Write(k)
rand.Seed(int64(hash.Sum64()))
c.cipherTextIdx = rand.Perm(c.d.col)
}
开发者ID:damagination,项目名称:crypto_and_auth,代码行数:7,代码来源:column_based_transposition_cipher.go
示例4: getKey
func (n *node) getKey() string {
t := []byte(strconv.FormatInt(time.Now().UnixNano(), 10))
h := fnv.New64a()
h.Write(t)
s := strconv.FormatUint(h.Sum64(), 10)
return s
}
开发者ID:codemodus,项目名称:formlark,代码行数:7,代码来源:node.go
示例5: Lookup
func (tab *Table) Lookup(proto protocols.Protocol, hostID string, port uint16) (Rule, bool) {
var sum = fnv.New64a()
var buf [2]byte
sum.Reset()
buf[0] = byte(proto)
sum.Write(buf[:1])
io.WriteString(sum, hostID)
binary.BigEndian.PutUint16(buf[:], port)
sum.Write(buf[:])
id := sum.Sum64()
nEntries := len(tab.entries)
idx := sort.Search(nEntries, func(idx int) bool {
return tab.entries[idx].id >= id
})
for _, entry := range tab.entries[idx:] {
if entry.id != id {
break
}
if entry.Protocol == proto && entry.SrcHostID == hostID && entry.SrcPort == port {
return entry.Rule, true
}
}
return Rule{}, false
}
开发者ID:fd,项目名称:switchboard,代码行数:29,代码来源:table.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng