Golang hash.Hash32 type examples
package hash
Hash32 is the common interface implemented by all 32-bit hash functions.
Golang hash.Hash32 type usage examples
Example 1:
type marvin struct {
seed uint64
lo, hi uint32
t [4]byte // as-yet-unprocessed bytes
rem int // how many bytes in t[] are valid
}
// NewMarvin32 returns a new hash.Hash32 object computing Microsoft's InternalMarvin32HashString seeded hash.
func NewMarvin32(seed uint64) hash.Hash32 {
m := new(marvin)
m.seed = seed
m.Reset()
return m
}
Example 2:
package main
import (
"fmt"
"hash"
)
// demo for hash.Hash32 purpose.
// ** -- you need to write your own Write(), reset(), Size, Blocksize and Sum32 inner functions -- **
// fakeHash32 is a dummy Hash32 that always returns 0.
type fakeHash32 struct {
hash.Hash32
}
func (fakeHash32) Write(p []byte) (int, error) { return len(p), nil }
func (fakeHash32) Sum32() uint32 { return 0 }
func main() {
var h hash.Hash32 = fakeHash32{}
h.Write([]byte("abc123")) // just a dummy Write
fmt.Printf("%d \n", h.Sum32()) // will return 0
}
References :
Advertisement
Something interesting
Tutorials
+6.4k CodeIgniter : form input set_value cause " to become & quot
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+22.2k Golang : Convert seconds to minutes and remainder seconds
+15.7k Golang : Get checkbox or extract multipart form data value example
+15k Golang : Search folders for file recursively with wildcard support
+8.7k Golang : Find duplicate files with filepath.Walk
+9.7k Golang : Format strings to SEO friendly URL example
+6.2k Linux/Unix : Commands that you need to be careful about
+6.1k Golang : Grab news article text and use NLP to get each paragraph's sentences
+9.5k Golang : Get all countries currencies code in JSON format
+19.1k Golang : Display list of time zones with GMT
+5.3k Golang : How to deal with configuration data?