Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use goroutines in SetValue #404

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions BitSliceIndexing/bsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,14 @@ func (b *BSI) SetValue(columnID uint64, value int64) {
}
}

var wg sync.WaitGroup

exists := b.eBM.Contains(uint32(columnID))
for i := 0; i < b.BitCount(); i++ {
wg.Add(1)
go func(j int) {
defer wg.Done()
if uint64(value)&(1<<uint64(j)) > 0 {
b.bA[j].Add(uint32(columnID))
} else {
b.bA[j].Remove(uint32(columnID))
}
}(i)
if uint64(value)&(1<<uint64(i)) > 0 {
b.bA[i].Add(uint32(columnID))
} else if exists {
b.bA[i].Remove(uint32(columnID))
}
}
wg.Wait()
b.eBM.Add(uint32(columnID))
}

Expand Down Expand Up @@ -264,7 +258,6 @@ type task struct {
// For the RANGE parameter the comparison criteria is >= valueOrStart and <= end.
// The parallelism parameter indicates the number of CPU threads to be applied for processing. A value
// of zero indicates that all available CPU resources will be potentially utilized.
//
func (b *BSI) CompareValue(parallelism int, op Operation, valueOrStart, end int64,
foundSet *roaring.Bitmap) *roaring.Bitmap {

Expand Down Expand Up @@ -524,7 +517,6 @@ func (b *BSI) minOrMax(op Operation, batch []uint32, resultsChan chan int64, wg

// Sum all values contained within the foundSet. As a convenience, the cardinality of the foundSet
// is also returned (for calculating the average).
//
func (b *BSI) Sum(foundSet *roaring.Bitmap) (sum int64, count uint64) {

count = foundSet.GetCardinality()
Expand Down Expand Up @@ -800,7 +792,6 @@ func (b *BSI) addDigit(foundSet *roaring.Bitmap, i int) {
// contained within the input BSI. Given that for BSIs, different columnIDs can have the same value. TransposeWithCounts
// is useful for situations where there is a one-to-many relationship between the vectored integer sets. The resulting BSI
// contains the number of times a particular value appeared in the input BSI as an integer count.
//
func (b *BSI) TransposeWithCounts(parallelism int, foundSet *roaring.Bitmap) *BSI {

return parallelExecutorBSIResults(parallelism, b, transposeWithCounts, foundSet, true)
Expand Down
35 changes: 24 additions & 11 deletions BitSliceIndexing/bsi_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package roaring

import (
"fmt"
"github.com/RoaringBitmap/roaring"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
"math/rand"
"os"
"testing"
"time"
"fmt"
"os"
)

func TestSetAndGet(t *testing.T) {
Expand Down Expand Up @@ -264,47 +264,47 @@ func TestNewBSIRetainSet(t *testing.T) {
func TestLargeFile(t *testing.T) {

datEBM, err := ioutil.ReadFile("./testdata/age/EBM")
if(err != nil) {
if err != nil {
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
return
}
dat1, err := ioutil.ReadFile("./testdata/age/1")
if(err != nil) {
if err != nil {
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
return
}
dat2, err := ioutil.ReadFile("./testdata/age/2")
if(err != nil) {
if err != nil {
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
return
}
dat3, err := ioutil.ReadFile("./testdata/age/3")
if(err != nil) {
if err != nil {
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
return
}
dat4, err := ioutil.ReadFile("./testdata/age/4")
if(err != nil) {
if err != nil {
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
return
}
dat5, err := ioutil.ReadFile("./testdata/age/5")
if(err != nil) {
if err != nil {
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
return
}
dat6, err := ioutil.ReadFile("./testdata/age/6")
if(err != nil) {
if err != nil {
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
return
}
dat7, err := ioutil.ReadFile("./testdata/age/7")
if(err != nil) {
if err != nil {
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
return
}
dat8, err := ioutil.ReadFile("./testdata/age/8")
if(err != nil) {
if err != nil {
fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
return
}
Expand Down Expand Up @@ -453,3 +453,16 @@ func TestMinMaxWithRandom(t *testing.T) {
assert.Equal(t, bsi.MinValue, bsi.MinMax(0, MIN, bsi.GetExistenceBitmap()))
assert.Equal(t, bsi.MaxValue, bsi.MinMax(0, MAX, bsi.GetExistenceBitmap()))
}

func BenchmarkSetRoaring(b *testing.B) {
b.StopTimer()
r := rand.New(rand.NewSource(0))
sz := 100_000_000
s := NewDefaultBSI()
b.StartTimer()
for i := 0; i < b.N; i++ {
for j := 0; j < 100; j++ {
s.SetValue(uint64(r.Int31n(int32(sz))), int64(r.Int31n(int32(sz))))
}
}
}
Loading