func BenchmarkGotomic(b *testing.B) { h := gotomic.NewHash() b.RunParallel(func(pb *testing.PB) { for pb.Next() { key := uint64(rand.Int63()) _, has := h.Get(gotomic.IntKey(key)) if !has { l := posting.NewList() h.Put(gotomic.IntKey(key), l) } } }) }
func (s GotomicMap) Get(key uint32) (uint32, bool) { val, found := s.h.Get(gotomic.IntKey(key)) if val == nil { return 0, false } return uint32(val.(gotomic.IntKey)), found }
func (l *List) init(key []byte, pstore *store.Store, clog *commit.Logger) { l.Lock() defer l.Unlock() defer l.wg.Done() if len(empty) == 0 { glog.Fatal("empty should have some bytes.") } l.key = key l.pstore = pstore l.clog = clog posting := l.getPostingList() l.maxMutationTs = posting.CommitTs() l.hash = farm.Fingerprint32(key) l.ghash = gotomic.IntKey(farm.Fingerprint64(key)) l.mlayer = make(map[int]types.Posting) if clog == nil { return } glog.Debug("Starting stream entries...") err := clog.StreamEntries(posting.CommitTs()+1, l.hash, func(hdr commit.Header, buffer []byte) { uo := flatbuffers.GetUOffsetT(buffer) m := new(types.Posting) m.Init(buffer, uo) if m.Ts() > l.maxMutationTs { l.maxMutationTs = m.Ts() } glog.WithFields(logrus.Fields{ "uid": m.Uid(), "source": string(m.Source()), "ts": m.Ts(), }).Debug("Got entry from log") l.mergeMutation(m) }) if err != nil { glog.WithError(err).Error("While streaming entries.") } glog.Debug("Done streaming entries.") }
func GetOrCreate(key []byte, pstore *store.Store) *List { stopTheWorld.RLock() defer stopTheWorld.RUnlock() uid := farm.Fingerprint64(key) ukey := gotomic.IntKey(uid) lp, _ := lhmap.Get(ukey) if lp != nil { return lp.(*List) } l := NewList() if inserted := lhmap.PutIfMissing(ukey, l); inserted { l.init(key, pstore, clog) return l } else { lp, _ = lhmap.Get(ukey) return lp.(*List) } }
func (s GotomicMap) Put(key, val uint32) { s.h.Put(gotomic.IntKey(key), gotomic.IntKey(val)) }