本文整理汇总了Golang中hash/crc32.MakeTable函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeTable函数的具体用法?Golang MakeTable怎么用?Golang MakeTable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakeTable函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetHash
func GetHash(a string) (hash.Hash, error) {
var h hash.Hash
switch a {
case "adler32":
h = adler32.New()
case "crc32", "crc32ieee":
h = crc32.New(crc32.MakeTable(crc32.IEEE))
case "crc32castagnoli":
h = crc32.New(crc32.MakeTable(crc32.Castagnoli))
case "crc32koopman":
h = crc32.New(crc32.MakeTable(crc32.Koopman))
case "crc64", "crc64iso":
h = crc64.New(crc64.MakeTable(crc64.ISO))
case "crc64ecma":
h = crc64.New(crc64.MakeTable(crc64.ECMA))
case "fnv", "fnv32":
h = fnv.New32()
case "fnv32a":
h = fnv.New32a()
case "fnv64":
h = fnv.New64()
case "fnv64a":
h = fnv.New64a()
case "hmac", "hmacsha256":
h = hmac.New(sha256.New, []byte(key))
case "hmacmd5":
h = hmac.New(md5.New, []byte(key))
case "hmacsha1":
h = hmac.New(sha1.New, []byte(key))
case "hmacsha512":
h = hmac.New(sha512.New, []byte(key))
case "md4":
h = md4.New()
case "md5":
h = md5.New()
case "ripemd160":
h = ripemd160.New()
case "sha1":
h = sha1.New()
case "sha224":
h = sha256.New224()
case "sha256":
h = sha256.New()
case "sha384":
h = sha512.New384()
case "sha512":
h = sha512.New()
default:
return nil, errors.New("Invalid algorithm")
}
return h, nil
}
开发者ID:patrickmn,项目名称:picugen,代码行数:52,代码来源:picugen.go
示例2: LockPartition
func LockPartition(pg *sql.DB, ns string, max uint64) (uint64, error) {
tab := crc32.MakeTable(crc32.IEEE)
for {
var p uint64
for p = 0; p < max; p++ {
pId := fmt.Sprintf("%s.%d", ns, p)
check := crc32.Checksum([]byte(pId), tab)
rows, err := pg.Query("select pg_try_advisory_lock($1)", check)
if err != nil {
continue
}
for rows.Next() {
var result sql.NullBool
rows.Scan(&result)
if result.Valid && result.Bool {
fmt.Printf("at=%q partition=%d max=%d\n",
"acquired-lock", p, max)
rows.Close()
return p, nil
}
}
rows.Close()
}
fmt.Printf("at=%q\n", "waiting-for-partition-lock")
time.Sleep(time.Second * 10)
}
return 0, errors.New("Unable to lock partition.")
}
开发者ID:ericfode,项目名称:l2met,代码行数:28,代码来源:utils.go
示例3: Hash
func (b *backend) Hash(ignores map[IgnoreKey]struct{}) (uint32, error) {
h := crc32.New(crc32.MakeTable(crc32.Castagnoli))
b.mu.RLock()
defer b.mu.RUnlock()
err := b.db.View(func(tx *bolt.Tx) error {
c := tx.Cursor()
for next, _ := c.First(); next != nil; next, _ = c.Next() {
b := tx.Bucket(next)
if b == nil {
return fmt.Errorf("cannot get hash of bucket %s", string(next))
}
h.Write(next)
b.ForEach(func(k, v []byte) error {
bk := IgnoreKey{Bucket: string(next), Key: string(k)}
if _, ok := ignores[bk]; !ok {
h.Write(k)
h.Write(v)
}
return nil
})
}
return nil
})
if err != nil {
return 0, err
}
return h.Sum32(), nil
}
开发者ID:CliffYuan,项目名称:etcd,代码行数:31,代码来源:backend.go
示例4: crc32_castagnoli
func (e *Engine) crc32_castagnoli() error {
data, err := computeHash(crc32.New(crc32.MakeTable(crc32.Castagnoli)), e.stack.Pop())
if err == nil {
e.stack.Push(data)
}
return err
}
开发者ID:ancientlore,项目名称:hashsrv,代码行数:7,代码来源:hash.go
示例5: crc32_koopman
func (e *Engine) crc32_koopman() error {
data, err := computeHash(crc32.New(crc32.MakeTable(crc32.Koopman)), e.stack.Pop())
if err == nil {
e.stack.Push(data)
}
return err
}
开发者ID:ancientlore,项目名称:hashsrv,代码行数:7,代码来源:hash.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng