mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 19:37:51 +00:00
Merge pull request #1365 from tgruben/slicecount-optimization
WIP count optimization
This commit is contained in:
commit
07480830da
3 changed files with 26 additions and 6 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
@ -1030,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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue