Skip to content

Commit

Permalink
feature: introduces MoreKeys method to compare bitmaps' number of key…
Browse files Browse the repository at this point in the history
…s/containers
  • Loading branch information
aliszka committed Dec 5, 2024
1 parent 08464f0 commit e883bff
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bitmap_opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,12 @@ func andNotSelectedContainers(a, b *Bitmap, ai, an, bi, bn int, containerBuf []u
}
}
}

func (dst *Bitmap) MoreKeys(src *Bitmap) bool {
if dst != nil {
if src == nil || dst.keys.numKeys() > src.keys.numKeys() {
return true
}
}
return false
}
46 changes: 46 additions & 0 deletions bitmap_opt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,52 @@ func TestIssue_Or_NotMergeContainers(t *testing.T) {
})
}

func TestMoreKeys(t *testing.T) {
var bmNil *Bitmap

bm1Key := NewBitmap()
bm1Key.Set(1)

bm2Keys := NewBitmap()
bm2Keys.Set(1)
bm2Keys.Set(1 + uint64(maxCardinality))

bm3Keys := NewBitmap()
bm3Keys.Set(1)
bm3Keys.Set(1 + uint64(maxCardinality))
bm3Keys.Set(1 + uint64(maxCardinality)*2)

t.Run("more keys", func(t *testing.T) {
for _, bms := range [][2]*Bitmap{
{bm1Key, bmNil},
{bm2Keys, bmNil},
{bm2Keys, bm1Key},
{bm3Keys, bmNil},
{bm3Keys, bm1Key},
{bm3Keys, bm2Keys},
} {
require.True(t, bms[0].MoreKeys(bms[1]))
}
})

t.Run("no more keys", func(t *testing.T) {
for _, bms := range [][2]*Bitmap{
{bmNil, bmNil},
{bmNil, bm1Key},
{bmNil, bm2Keys},
{bmNil, bm3Keys},
{bm1Key, bm1Key},
{bm1Key, bm2Keys},
{bm1Key, bm3Keys},
{bm2Keys, bm2Keys},
{bm2Keys, bm3Keys},
{bm3Keys, bm3Keys},
} {
require.False(t, bms[0].MoreKeys(bms[1]))
}
})
}

func TestMergeToSuperset(t *testing.T) {
run := func(t *testing.T, bufs [][]uint16) {
containerThreshold := uint64(math.MaxUint16 + 1)
Expand Down

0 comments on commit e883bff

Please sign in to comment.