WIP count optimization

This commit is contained in:
Todd Gruben 2018-06-07 10:49:45 -05:00
parent a04e5c8a9b
commit 89da69e6a5
2 changed files with 11 additions and 6 deletions

View file

@ -124,6 +124,14 @@ func (sc *SliceContainers) Size() int {
}
func (sc *SliceContainers) Count() uint64 {
n := uint64(0)
for i := range sc.containers {
n += uint64(sc.containers[i].n)
}
return n
}
func (sc *SliceContainers) seek(key uint64) (int, bool) {
i := search64(sc.keys, key)
found := true
@ -153,6 +161,7 @@ func (si *SliceIterator) Next() bool {
si.key = si.e.keys[si.i]
si.value = si.e.containers[si.i]
si.i++
return true
}

View file

@ -93,6 +93,7 @@ type Containers interface {
// return the first container at or after key. found will be true if a
// container is found at key.
Iterator(key uint64) (citer ContainerIterator, found bool)
Count() uint64
}
type ContainerIterator interface {
@ -218,12 +219,7 @@ func (b *Bitmap) Max() uint64 {
// Count returns the number of bits set in the bitmap.
func (b *Bitmap) Count() (n uint64) {
citer, _ := b.Containers.Iterator(0)
for citer.Next() {
_, c := citer.Value()
n += uint64(c.n)
}
return n
return b.Containers.Count()
}
// CountRange returns the number of bits set between [start, end).