diff --git a/enterprise/b/containers_btree.go b/enterprise/b/containers_btree.go index 257134a82..ccb856d18 100644 --- a/enterprise/b/containers_btree.go +++ b/enterprise/b/containers_btree.go @@ -150,6 +150,12 @@ func (btc *BTreeContainers) Size() int { return btc.tree.Len() } +func (btc *BTreeContainers) Reset() { + btc.tree = TreeNew(cmp) + btc.lastKey = 0 + btc.lastContainer = nil +} + func (btc *BTreeContainers) Iterator(key uint64) (citer roaring.ContainerIterator, found bool) { e, ok := btc.tree.Seek(key) if ok { diff --git a/roaring/containers.go b/roaring/containers.go index 08c8d25eb..1cf366efc 100644 --- a/roaring/containers.go +++ b/roaring/containers.go @@ -124,6 +124,13 @@ func (sc *SliceContainers) Size() int { } +func (sc *SliceContainers) Reset() { + sc.keys = sc.keys[:0] + sc.containers = sc.containers[:0] + sc.lastContainer = nil + sc.lastKey = 0 +} + func (sc *SliceContainers) seek(key uint64) (int, bool) { i := search64(sc.keys, key) found := true diff --git a/roaring/roaring.go b/roaring/roaring.go index fafce4d59..42d06eb50 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -93,6 +93,9 @@ 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) + //Reset will clear the containers collection to allow for recycling during snapshot + Reset() + } type ContainerIterator interface { @@ -635,7 +638,7 @@ func (b *Bitmap) UnmarshalBinary(data []byte) error { keyN := binary.LittleEndian.Uint32(data[4:8]) headerSize := headerBaseSize - + b.Containers.Reset() // Descriptive header section: Read container keys and cardinalities. for i, buf := 0, data[headerSize:]; i < int(keyN); i, buf = i+1, buf[12:] { b.Containers.PutContainerValues(