本文整理汇总了Golang中hash/crc64.MakeTable函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeTable函数的具体用法?Golang MakeTable怎么用?Golang MakeTable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakeTable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: makeHash
func makeHash(name string) hash.Hash {
switch strings.ToLower(name) {
case "ripemd160":
return ripemd160.New()
case "md4":
return md4.New()
case "md5":
return md5.New()
case "sha1":
return sha1.New()
case "sha256":
return sha256.New()
case "sha384":
return sha512.New384()
case "sha3-224":
return sha3.New224()
case "sha3-256":
return sha3.New256()
case "sha3-384":
return sha3.New384()
case "sha3-512":
return sha3.New512()
case "sha512":
return sha512.New()
case "sha512-224":
return sha512.New512_224()
case "sha512-256":
return sha512.New512_256()
case "crc32-ieee":
return crc32.NewIEEE()
case "crc64-iso":
return crc64.New(crc64.MakeTable(crc64.ISO))
case "crc64-ecma":
return crc64.New(crc64.MakeTable(crc64.ECMA))
case "adler32":
return adler32.New()
case "fnv32":
return fnv.New32()
case "fnv32a":
return fnv.New32a()
case "fnv64":
return fnv.New64()
case "fnv64a":
return fnv.New64a()
case "xor8":
return new(xor8)
case "fletch16":
return &fletch16{}
}
return nil
}
示例3: NewSpecialCollectionCache
func NewSpecialCollectionCache(intent *intents.Intent, demux *Demultiplexer) *SpecialCollectionCache {
return &SpecialCollectionCache{
Intent: intent,
Demux: demux,
hash: crc64.New(crc64.MakeTable(crc64.ECMA)),
}
}
示例4: hashcrc64
func hashcrc64(s []byte) []byte {
var tab = crc64.MakeTable(crc64.ECMA)
h := crc64.New(tab)
h.Write(s)
return h.Sum(nil)
}
示例5: main
func main() {
var ECMATable = crc64.MakeTable(crc64.ECMA)
h := crc64.New(ECMATable)
h.Write([]byte("test"))
v := h.Sum64()
fmt.Println(v)
}
示例6: loop
func (v *VagrantShareRemoteWatcher) loop(ctx context.Context) {
table := crc64.MakeTable(crc64.ECMA)
var lastCheckSum uint64 = 0
for {
go func() {
checkSum, descriptor, err := v.downloadJson(table)
if err != nil {
v.OnError <- err
} else {
if lastCheckSum != checkSum {
v.Updated <- descriptor
lastCheckSum = checkSum
}
}
}()
select {
case <-ctx.Done():
return
case <-v.clock.After(v.periodInSeconds):
// continue
}
}
}
示例7: process_file
func process_file(filename string, complete chan Sumlist) {
sumlist := Sumlist{}
sumlist.filename = filename
// Open the file and bail if we fail
infile, err := os.Open(filename)
if err != nil {
log.Printf("Unable to open %s: %s", filename, err)
complete <- sumlist
return
}
defer infile.Close()
// Create the checksum objects
if flag_crc32 {
sumlist.sums = append(sumlist.sums, Checksum{"CRC32", crc32.New(crc32.IEEETable)})
}
if flag_crc64 {
sumlist.sums = append(sumlist.sums, Checksum{"CRC64", crc64.New(crc64.MakeTable(crc64.ISO))})
}
if flag_sha224 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA224", sha256.New224()})
}
if flag_sha256 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA256", sha256.New()})
}
if flag_sha384 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA384", sha512.New384()})
}
if flag_sha512 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA512", sha512.New()})
}
// Create our file reader
reader := bufio.NewReader(infile)
// Start a buffer and loop to read the entire file
buf := make([]byte, 4096)
for {
read_count, err := reader.Read(buf)
// If we get an error that is not EOF, then we have a problem
if err != nil && err != io.EOF {
log.Printf("Unable to open %s: %s", filename, err)
complete <- sumlist
return
}
// If the returned size is zero, we're at the end of the file
if read_count == 0 {
break
}
// Add the buffer contents to the checksum calculation
for _, sum := range sumlist.sums {
sum.hashFunc.Write(buf[:read_count])
}
}
complete <- sumlist
}
示例8: crc64_ecma
func (e *Engine) crc64_ecma() error {
data, err := computeHash(crc64.New(crc64.MakeTable(crc64.ECMA)), e.stack.Pop())
if err == nil {
e.stack.Push(data)
}
return err
}
示例9: main
func main() {
m := map[string]hash.Hash{
"had": adler32.New(),
"hc32": crc32.NewIEEE(),
"hc64e": crc64.New(crc64.MakeTable(crc64.ECMA)),
"hc64i": crc64.New(crc64.MakeTable(crc64.ISO)),
"hf32": fnv.New32(),
"hf32a": fnv.New32a(),
"hf64": fnv.New64(),
"hf64a": fnv.New64a(),
}
for n, h := range m {
runtime.GC()
testHash(n, h)
}
}
示例10: archiveWriter
func (a *Archiver) archiveWriter() error {
hash := crc64.New(crc64.MakeTable(crc64.ECMA))
output := io.MultiWriter(a.output, hash)
blockCount := 0
_, err := output.Write(fastArchiverHeader)
if err != nil {
return err
}
for block := range a.blockQueue {
err = block.writeBlock(output)
blockCount += 1
if err == nil && (blockCount%1000) == 0 {
err = writeChecksumBlock(hash, output)
}
if err != nil {
return err
}
}
return writeChecksumBlock(hash, output)
}
示例11: TestUseCrc
func TestUseCrc(t *testing.T) {
table := crc64.MakeTable(crc64.ISO)
h := crc64.New(table)
input := "someUniqueId"
io.WriteString(h, input)
sum1 := h.Sum64()
h.Reset()
input = "someOtherId"
io.WriteString(h, input)
sum2 := h.Sum64()
if sum1 == sum2 {
t.Errorf("Sums shouldn't match [%x] [%x]\n", sum1, sum2)
t.Fail()
return
}
h.Reset()
input = "someUniqueId"
io.WriteString(h, input)
sum3 := h.Sum64()
if sum1 != sum3 {
t.Errorf("Sums should match [%x] [%x]\n", sum1, sum3)
t.Fail()
return
}
}
示例12: hash
func (h *HashTable) hash(k []byte) uint64 {
hash := crc64.New(crc64.MakeTable(crc64.ISO))
_, _ = hash.Write(k)
return hash.Sum64() % uint64(len(h.data))
}
示例13: init
func init() {
// Create the hashing function.
hasher := crc64.New(crc64.MakeTable(crc64.ECMA))
h := func(s string) uint64 {
hasher.Reset()
hasher.Write([]byte(s))
return hasher.Sum64()
}
// Get the current user name.
osU, err := user.Current()
u := "UNKNOW"
if err == nil {
u = osU.Username
}
// Create the constant to make build a unique ID.
start := uint64(time.Now().UnixNano())
user := h(u)
pid := uint64(os.Getpid())
// Initialize the channel and blank node type.
nextVal, tBlank = make(chan string, chanSize), Type("/_")
enc := base64.StdEncoding
go func() {
cnt := uint64(0)
for {
bs := []byte(fmt.Sprintf("%x:%x:%x:%x", start, user, pid, cnt))
nextVal <- enc.EncodeToString(bs)
cnt++
}
}()
}
示例14: file
func file(fn string) {
ext := path.Ext(fn)
if ext == ".go" {
return
}
in, err := ioutil.ReadFile(fn)
if err != nil {
panic(err)
}
out, err := os.Create(fn + ".go")
if err != nil {
panic(err)
}
defer out.Close()
fmt.Fprintf(out, `package resource
func init() {
Resource[%q] = []byte{`, filepath.Base(fn))
for i, b := range in {
if i == 0 {
fmt.Fprintf(out, `%d`, b)
} else {
fmt.Fprintf(out, `, %d`, b)
}
}
hash := crc64.New(crc64.MakeTable(crc64.ISO))
hash.Write(in)
fmt.Fprintf(out, "}\n\tHash[%q] = \"W/\\\"%d\\\"\"\n}\n", filepath.Base(fn), hash.Sum64())
}
示例15: newFilter64
func newFilter64(m, k uint64) *filter64 {
return &filter64{
m: m,
k: k,
h: fnv.New64(),
oh: crc64.New(crc64.MakeTable(crc64.ECMA)),
}
}