Refactor roaring repair operations

This commit is contained in:
Richard Artoul 2018-11-30 19:23:59 -05:00
parent 34b1f2199f
commit 71621e60ba
2 changed files with 16 additions and 6 deletions

View file

@ -156,11 +156,9 @@ func (sc *sliceContainers) Iterator(key uint64) (citer ContainerIterator, found
return &sliceIterator{e: sc, i: i}, found
}
func (sc *sliceContainers) repairBitmaps() {
func (sc *sliceContainers) Repair() {
for _, c := range sc.containers {
if c.isBitmap() {
c.bitmapRepair()
}
c.Repair()
}
}

View file

@ -98,8 +98,12 @@ type Containers interface {
Count() uint64
//Reset will clear the containers collection to allow for recycling during snapshot
// Reset will clear the containers collection to allow for recycling during snapshot
Reset()
// Repair will repair the cardinality of any containers whose cardinality were corrupted
// due to optimized operations.
Repair()
}
type ContainerIterator interface {
@ -687,7 +691,7 @@ func (b *Bitmap) unionIntoTarget(target *Bitmap, others ...*Bitmap) {
// n (container cardinality) to fall out of sync, and then at the very end we perform
// a "Repair" to recalculate all the container values. That way we never popcount()
// an entire bitmap container more than once per bulk union operation.
target.Containers.(*sliceContainers).repairBitmaps()
target.Containers.Repair()
}
// Difference returns the difference of b and other.
@ -2091,6 +2095,14 @@ func (c *Container) check() error {
return a
}
// Repair repairs the cardinality of c if it has been corrupted by
// optimized operations.
func (c *Container) Repair() {
if c.isBitmap() {
c.bitmapRepair()
}
}
func (c *Container) bitmapRepair() {
n := int32(0)
// Manually unroll loop to make it a little faster.