Skip to content

Commit 72267ff

Browse files
committed
Add BSI.Retain
1 parent 6e38489 commit 72267ff

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

roaring64/bsi64.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,20 @@ func (b *BSI) ClearValues(foundSet *Bitmap) {
990990
wg.Wait()
991991
}
992992

993+
// Retains only values found in retain. Returns how many values were not retained.
994+
func (b *BSI) Retain(retain *Bitmap) (dropped uint64) {
995+
preCard := b.eBM.GetCardinality()
996+
b.eBM.And(retain)
997+
dropped = preCard - b.eBM.GetCardinality()
998+
if dropped == 0 {
999+
return
1000+
}
1001+
for i := range b.bA {
1002+
b.bA[i].And(retain)
1003+
}
1004+
return
1005+
}
1006+
9931007
// NewBSIRetainSet - Construct a new BSI from a clone of existing BSI, retain only values contained in foundSet
9941008
func (b *BSI) NewBSIRetainSet(foundSet *Bitmap) *BSI {
9951009

0 commit comments

Comments
 (0)