Example #1
0
func BenchmarkFnv64(b *testing.B) {
	h := fnv.New64()
	for i := 0; i < b.N; i++ {
		h.Write(in)
		h.Sum(nil)
	}
}
Example #2
0
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
}
Example #3
0
func newFilter(m, k uint32) *filter {
	return &filter{
		m: m,
		k: k,
		h: fnv.New64(),
	}
}
Example #4
0
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()
}
Example #5
0
func hash(s ...[]byte) uint64 {
	h := fnv.New64()
	for _, b := range s {
		h.Write(b)
	}
	return h.Sum64()
}
Example #6
0
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)
}
Example #7
0
func (e *Engine) fnv64() error {
	data, err := computeHash(fnv.New64(), e.stack.Pop())
	if err == nil {
		e.stack.Push(data)
	}
	return err
}
Example #8
0
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
}
Example #9
0
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
}
Example #10
0
func BenchmarkFnv64MultiWrites(b *testing.B) {
	h := fnv.New64()
	for i := 0; i < b.N; i++ {
		h.Write(in)
	}
	_ = h.Sum64()
}
Example #11
0
// 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
}
Example #12
0
func newFilter64(m, k uint64) *filter64 {
	return &filter64{
		m:  m,
		k:  k,
		h:  fnv.New64(),
		oh: crc64.New(crc64.MakeTable(crc64.ECMA)),
	}
}
Example #13
0
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)
	}
}
Example #14
0
// 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
}
Example #15
0
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)
	}
}
Example #16
0
func New(numHashFn, bfSize int) *BloomFilter {
	return &BloomFilter{
		bitVector: make([]bool, bfSize),
		k:         numHashFn,
		m:         bfSize,
		n:         0,
		hashFn:    fnv.New64(),
	}
}
Example #17
0
func new_docsummary(n *html.Node, images []boiler_image) *DocumentSummary {
	f := fnv.New64()
	rtn := new_docsummary_internal(n, f)
	rtn.Hash = f.Sum64()
	for _, img := range images {
		rtn.Images = append(rtn.Images, MediaSummary{img.url, img.alt, img.width, img.height})
	}
	return rtn
}
Example #18
0
// NewBloomFilter creates a new Bloom filter optimized to store n items with a
// specified target false-positive rate.
func NewBloomFilter(n uint, fpRate float64) *BloomFilter {
	m := OptimalM(n, fpRate)
	return &BloomFilter{
		buckets: NewBuckets(m, 1),
		hash:    fnv.New64(),
		m:       m,
		k:       OptimalK(fpRate),
	}
}
Example #19
0
func newTestFilter(k int, log uint) (f *filter, hashes []sHash) {
	bh := fnv.New64()
	for i := 0; i < k; i++ {
		hashes = append(hashes, newsHash(bh))
	}

	f = newFilter(log, k)
	return
}
Example #20
0
func (m *SqlDriverMessageMap) SetKeyHashed(key string) {
	m.keyVal = key
	// Do we want to use SipHash here
	hasher64 := fnv.New64()
	hasher64.Write([]byte(key))
	//idOld := m.IdVal
	m.IdVal = hasher64.Sum64()
	//u.Warnf("old:%v new:%v  set key hashed: %v", idOld, m.IdVal, m.row)
}
Example #21
0
func BenchmarkFnv64MultiWrites(b *testing.B) {
	var bv uint64
	h := fnv.New64()
	for i := 0; i < b.N; i++ {
		h.Write(in)
		bv += h.Sum64()
		h.Reset()
	}
}
Example #22
0
// hashAnything turns anything into a uint64 via a fnv hash
func hashAnything(i interface{}) uint64 {
	v := fnv.New64()
	if x, ok := i.(Byteser); ok {
		v.Write(x.Bytes())
	} else {
		v.Write(iToBytes(i))
	}
	return v.Sum64()
}
Example #23
0
File: util.go Project: mdmarek/grid
// NewSeed generate a seed by running time.Now().UnixNano()
// through 1,000 rounds of an FNV hash.
func NewSeed() int64 {
	h := fnv.New64()
	for i := 0; i < 1000; i++ {
		b := make([]byte, binary.MaxVarintLen64)
		binary.PutVarint(b, time.Now().UnixNano())
		h.Write(b)
	}
	return int64(h.Sum64())
}
Example #24
0
func uniqueName(fids []frameId) string {
	var b []byte
	for i := range fids {
		b = append(b, byte(fids[i].facing))
		b = append(b, byte(fids[i].node))
	}
	h := fnv.New64()
	h.Write(b)
	return fmt.Sprintf("%x.gob", h.Sum64())
}
Example #25
0
// ID with which you can identify a daemon connection to the same SMTP server
// independent of the scope ID.
func (dm *Daemon) ID() uint64 {
	var h hash.Hash64
	h = fnv.New64()
	data := []byte(dm.getHost() + strconv.Itoa(dm.getPort()) + dm.getUsername())
	if _, err := h.Write(data); err != nil {
		log.Error("mail.daemon.ID", "err", err, "hashWrite", string(data))
		return 0
	}
	return h.Sum64()
}
Example #26
0
func BenchmarkFnv64VeryShort(b *testing.B) {
	var bv []byte
	k := []byte("Test-key-100")
	for i := 0; i < b.N; i++ {
		h := fnv.New64()
		h.Write(k)
		bv = h.Sum(nil)
	}
	benchValByte = bv
}
Example #27
0
func BenchmarkFnv64(b *testing.B) {
	var bv []byte
	h := fnv.New64()
	for i := 0; i < b.N; i++ {
		h.Write(in)
		bv = h.Sum(nil)
		h.Reset()
	}
	benchValByte = bv
}
Example #28
0
func BenchmarkFnvHash(b *testing.B) {
	const bytes = 1024
	s := newsHash(fnv.New64())
	dat := make([]byte, bytes)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		s.Hash(dat)
		b.SetBytes(bytes)
	}
}
Example #29
0
func hashcolor(s string) string {
	hash := fnv.New64()
	fmt.Fprint(hash, s)
	i := hash.Sum64()

	r := (i & 0xFF0000) >> 16
	g := (i & 0x00FF00) >> 8
	b := i & 0x0000FF
	return fmt.Sprintf("#%X%X%X", r, g, b)
}
Example #30
0
func MakeCMSDirect(size uint32, numHash uint32, seed int64, updateF UpdateFn, readF ReadFn) *CountMin {
	mat := make([][]*CMElement, numHash)
	for i, _ := range mat {
		mat[i] = make([]*CMElement, size)
		for j, _ := range mat[i] {
			mat[i][j] = &CMElement{}
		}
	}
	return &CountMin{mat, size, numHash, fnv.New64(), updateF, readF}
}