Skip to content

Commit

Permalink
Add BatchValueBig method and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
gamolina committed Oct 23, 2024
1 parent f0d4a75 commit b6d009d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
21 changes: 16 additions & 5 deletions roaring64/bsi64.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ type task struct {
op Operation
valueOrStart *big.Int
end *big.Int
values map[int64]struct{}
values map[string]struct{}
bits *Bitmap
}

Expand Down Expand Up @@ -897,10 +897,21 @@ func (b *BSI) WriteTo(w io.Writer) (n int64, err error) {

// BatchEqual returns a bitmap containing the column IDs where the values are contained within the list of values provided.
func (b *BSI) BatchEqual(parallelism int, values []int64) *Bitmap {
//convert list of int64 values to big.Int(s)
bigValues := make([]*big.Int, len(values))
for i, v := range values {
bigValues[i] = big.NewInt(v)
}
return b.BatchEqualBig(parallelism, bigValues)
}


valMap := make(map[int64]struct{}, len(values))
// BatchEqual returns a bitmap containing the column IDs where the values are contained within the list of values provided.
func (b *BSI) BatchEqualBig(parallelism int, values []*big.Int) *Bitmap {

valMap := make(map[string]struct{}, len(values))
for i := 0; i < len(values); i++ {
valMap[values[i]] = struct{}{}
valMap[string(values[i].Bytes())] = struct{}{}
}
comp := &task{bsi: b, values: valMap}
return parallelExecutor(parallelism, comp, batchEqual, &b.eBM)
Expand All @@ -918,8 +929,8 @@ func batchEqual(e *task, batch []uint64, resultsChan chan *Bitmap,

for i := 0; i < len(batch); i++ {
cID := batch[i]
if value, ok := e.bsi.GetValue(uint64(cID)); ok {
if _, yes := e.values[int64(value)]; yes {
if value, ok := e.bsi.GetBigValue(uint64(cID)); ok {
if _, yes := e.values[string(value.Bytes())]; yes {
results.Add(cID)
}
}
Expand Down
15 changes: 15 additions & 0 deletions roaring64/bsi64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,21 @@ func TestAdd(t *testing.T) {

}

func TestBatchValueBig(t *testing.T) {
bsi := NewDefaultBSI()

// create a big value
bv := big.NewInt(Max64BitSigned)
bv.Mul(bv, big.NewInt(100))

// Populate large timestamp values
for i := 0; i <= 100; i++ {
bsi.SetBigValue(uint64(i), bv)
}
result := bsi.BatchEqualBig(0, []*big.Int{bv})
assert.Equal(t, uint64(101), result.GetCardinality())
}

func TestIncrementSimple(t *testing.T) {
bsi := setup()
bsi.IncrementAll()
Expand Down

0 comments on commit b6d009d

Please sign in to comment.