implemented count optimization for btree

This commit is contained in:
Todd Gruben 2018-06-19 11:01:00 -05:00
parent 1488ac0e3a
commit aa71c08f12
2 changed files with 15 additions and 0 deletions

View file

@ -121,6 +121,16 @@ func (btc *BTreeContainers) GetOrCreate(key uint64) *roaring.Container {
return btc.lastContainer
}
func (btc *BTreeContainers) Count() (n uint64) {
e, _ := btc.tree.Seek(0)
_, c, err := e.Next()
for err != io.EOF {
n += uint64(c.N())
_, c, err = e.Next()
}
return
}
func (btc *BTreeContainers) Clone() roaring.Containers {
nbtc := NewBTreeContainers()

View file

@ -1026,6 +1026,11 @@ func (c *Container) Mapped() bool {
return c.mapped
}
// N returns the cached bit count of the container
func (c *Container) N() int {
return c.n
}
// Update updates the container
func (c *Container) Update(containerType byte, n int, mapped bool) {
c.containerType = containerType