Commit fe4f8ad2 authored by Brian Tiger Chow's avatar Brian Tiger Chow

expose O(1) len

parent 3c044d23
......@@ -7,13 +7,14 @@ import (
)
type ThreadSafe struct {
lk sync.RWMutex
Wantlist
lk sync.RWMutex
Wantlist Wantlist
}
// not threadsafe
type Wantlist struct {
set map[u.Key]Entry
// TODO provide O(1) len accessor if cost becomes an issue
}
type Entry struct {
......@@ -74,6 +75,16 @@ func (w *ThreadSafe) SortedEntries() []Entry {
return w.Wantlist.SortedEntries()
}
func (w *ThreadSafe) Len() int {
w.lk.RLock()
defer w.lk.RUnlock()
return w.Wantlist.Len()
}
func (w *Wantlist) Len() int {
return len(w.set)
}
func (w *Wantlist) Add(k u.Key, priority int) {
if _, ok := w.set[k]; ok {
return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment