本文整理汇总了Golang中hash/fnv.New64函数的典型用法代码示例。如果您正苦于以下问题:Golang New64函数的具体用法?Golang New64怎么用?Golang New64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkFnv64
func BenchmarkFnv64(b *testing.B) {
h := fnv.New64()
for i := 0; i < b.N; i++ {
h.Write(in)
h.Sum(nil)
}
}
示例2: Example
func Example() {
// As usual in examples, this ignores all errors. Don't do this in your program.
// setup and find start point for centering
s := "Hello, World!"
size := image.Rect(0, 0, 120, 20)
dst := image.NewRGBA(size)
c := freetype.NewContext()
c.SetFont(font)
c.SetFontSize(14.0)
c.SetSrc(image.NewUniform(color.Black))
c.SetDst(dst)
start, _ := fontutil.CenterX(c, s, size) // CenterX calls c.SetClip(size)
// perform draw at start.X + y 16
c.DrawString(s, start.Add(freetype.Pt(0, 16)))
// write the image out to a file
// out, _ := os.Create("helloworld.png")
// defer out.Close()
// write image to hash for testing purposes
out := fnv.New64()
_ = png.Encode(out, dst)
fmt.Printf("Hash of compressed image: %x", out.Sum64())
// Output: Hash of compressed image: fa83a1b8d8abf5f2
}
示例3: newFilter
func newFilter(m, k uint32) *filter {
return &filter{
m: m,
k: k,
h: fnv.New64(),
}
}
示例4: cmdServerNick
func (i *IRCServer) cmdServerNick(s *Session, reply *Replyctx, msg *irc.Message) {
// e.g. “NICK OperServ 1 1422134861 services localhost.net services.localhost.net 0 :Operator Server”
// <nickname> <hopcount> <username> <host> <servertoken> <umode> <realname>
// Could be either a nickchange or the introduction of a new user.
if len(msg.Params) == 1 {
// TODO(secure): handle nickchanges. not sure when/if those are used. botserv maybe?
return
}
if _, ok := i.nicks[NickToLower(msg.Params[0])]; ok {
i.sendServices(reply, &irc.Message{
Prefix: i.ServerPrefix,
Command: irc.ERR_NICKNAMEINUSE,
Params: []string{"*", msg.Params[0]},
Trailing: "Nickname is already in use",
})
return
}
h := fnv.New64()
h.Write([]byte(msg.Params[0]))
id := types.RobustId{
Id: s.Id.Id,
Reply: int64(h.Sum64()),
}
i.CreateSession(id, "")
ss := i.sessions[id]
ss.Nick = msg.Params[0]
i.nicks[NickToLower(ss.Nick)] = ss
ss.Username = msg.Params[3]
ss.Realname = msg.Trailing
ss.updateIrcPrefix()
}
示例5: hash
func hash(s ...[]byte) uint64 {
h := fnv.New64()
for _, b := range s {
h.Write(b)
}
return h.Sum64()
}
示例6: AddTable
func (m *SchemaSource) AddTable(tbl *Table) {
hash := fnv.New64()
if m.Schema != nil {
// Do id's need to be unique across schemas? seems bit overkill
//hash.Write([]byte(m.Name + tbl.Name))
hash.Write([]byte(tbl.Name))
m.Schema.addTable(tbl)
} else {
hash.Write([]byte(tbl.Name))
//u.Warnf("no SCHEMA for table!!!!!! %#v", tbl)
}
// create consistent-hash-id of this table name, and or table+schema
tbl.tblId = hash.Sum64()
m.tableMap[tbl.Name] = tbl
if m.Conf != nil && m.Conf.PartitionCt > 0 {
tbl.PartitionCt = m.Conf.PartitionCt
} else if m.Conf != nil {
for _, pt := range m.Conf.Partitions {
if tbl.Name == pt.Table && tbl.Partition == nil {
tbl.Partition = pt
}
}
}
//u.Infof("add table: %v partitionct:%v conf:%+v", tbl.Name, tbl.PartitionCt, m.Conf)
m.AddTableName(tbl.Name)
}
示例7: fnv64
func (e *Engine) fnv64() error {
data, err := computeHash(fnv.New64(), e.stack.Pop())
if err == nil {
e.stack.Push(data)
}
return err
}
示例8: getHeadHash
func (f *Ftail) getHeadHash(fname string, getLength int64) (hash string, length int64, err error) {
f.headHash = fnv.New64()
f.head = []byte{}
if f.MaxHeadHashSize == 0 || f.Pos.Name == "" {
return "", 0, nil
}
var readFile *os.File
readFile, err = os.Open(fname)
if err != nil {
return
}
defer func() {
if err := readFile.Close(); err != nil {
log.Printf("readFile.Close err:%s", err)
}
}()
tee := io.TeeReader(io.LimitReader(readFile, getLength), f.headHash)
f.head, err = ioutil.ReadAll(tee)
length = int64(len(f.head))
//length, err = io.CopyN(f.headHash, readFile, getLength)
switch err {
case nil:
case io.EOF:
err = nil
default:
return
}
hash = strconv.FormatUint(f.headHash.Sum64(), 16)
return
}
示例9: AddInvertRecord
func (this *MiniIndex) AddInvertRecord(ir InvertRecord) error {
this.stats.AddDocId(ir.DocId)
for _, ire := range ir.Inverts {
fmt.Println(ire)
invertType := ire.Type
for _, kv := range ire.Fields {
term := kv.K
payload := kv.V
//make uint64 sign
h := fnv.New64()
io.WriteString(h, invertType+"_"+term) //term_iphone
termSign := TermSign(h.Sum64())
fmt.Printf("termSign: %v\n", termSign)
//push back to invert list
invertNode := InvertNode{ir.DocId, payload}
this.rwLock.Lock()
invertList, ok := this.rawIndex[termSign]
if !ok {
var newInvertList InvertList
newInvertList.Term = term
newInvertList.Type = invertType
invertList = newInvertList
}
invertList.InvertNodes = append(invertList.InvertNodes, invertNode)
this.rawIndex[termSign] = invertList
this.rwLock.Unlock()
this.stats.AddSign(termSign)
}
}
return nil
}
示例10: BenchmarkFnv64MultiWrites
func BenchmarkFnv64MultiWrites(b *testing.B) {
h := fnv.New64()
for i := 0; i < b.N; i++ {
h.Write(in)
}
_ = h.Sum64()
}
示例11: NewBloomFilter
// Returns a new BloomFilter object, if you pass the
// number of Hash Functions to use and the maximum
// size of the Bloom Filter
func NewBloomFilter(numHashFuncs, bfSize int) *BloomFilter {
bf := new(BloomFilter)
bf.bitmap = make([]bool, bfSize)
bf.k, bf.m = numHashFuncs, bfSize
bf.n = 0
bf.hashfn = fnv.New64()
return bf
}
示例12: newFilter64
func newFilter64(m, k uint64) *filter64 {
return &filter64{
m: m,
k: k,
h: fnv.New64(),
oh: crc64.New(crc64.MakeTable(crc64.ECMA)),
}
}
示例13: benchmarkFnvSFilterAdd
func benchmarkFnvSFilterAdd(b *testing.B, k int) {
f := NewFilter(fnv.New64(), k)
b.ResetTimer()
for i := 0; i < b.N; i++ {
f.Add(randSeed())
b.SetBytes(10)
}
}
示例14: NewCountingBloomFilter
// Creates a new Counting Bloom Filter
func NewCountingBloomFilter(numHashFuncs, cbfSize int) *CountingBloomFilter {
cbf := new(CountingBloomFilter)
cbf.counts = make([]uint8, cbfSize)
cbf.k, cbf.m = numHashFuncs, cbfSize
cbf.n = 0
cbf.hashfn = fnv.New64()
return cbf
}
示例15: BenchmarkFnv64VeryShort
func BenchmarkFnv64VeryShort(b *testing.B) {
k := []byte("Test-key-100")
for i := 0; i < b.N; i++ {
h := fnv.New64()
h.Write(k)
h.Sum(nil)
}
}