Skip to content

Commit

Permalink
preload bsi
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Oct 15, 2024
1 parent 13165e1 commit f9c2c71
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 69 deletions.
14 changes: 7 additions & 7 deletions internal/bsi/bsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewBitmap() *Bitmap {
// It depends upon the bitmap libraries. It is not thread safe, so
// upstream concurrency guards must be provided.
type BSI struct {
source Source
Source Source
}

// NewBSI constructs a new BSI. Note that it is your responsibility to ensure that
Expand All @@ -48,7 +48,7 @@ func NewBSI(maxValue int64, minValue int64) *BSI {
for i := range bitsz + 1 {
src.GetOrCreate(i)
}
return &BSI{source: src}
return &BSI{Source: src}
}

// NewDefaultBSI constructs an auto-sized BSI
Expand All @@ -57,7 +57,7 @@ func NewDefaultBSI() *BSI {
}

func (b *BSI) Reset() {
if s, ok := b.source.(Reset); ok {
if s, ok := b.Source.(Reset); ok {
s.Reset()
}
}
Expand Down Expand Up @@ -424,17 +424,17 @@ func (b *BSI) String() string {
}

func (b *BSI) muex() *roaring.Bitmap {
return b.source.GetOrCreate(0)
return b.Source.GetOrCreate(0)
}

func (b *BSI) ex() *roaring.Bitmap {
return b.source.Get(0)
return b.Source.Get(0)
}

func (b *BSI) must(i int) *roaring.Bitmap {
return b.source.GetOrCreate(i + 1)
return b.Source.GetOrCreate(i + 1)
}

func (b *BSI) get(i int) *roaring.Bitmap {
return b.source.Get(i + 1)
return b.Source.Get(i + 1)
}
61 changes: 0 additions & 61 deletions internal/bsi/kv.go

This file was deleted.

35 changes: 35 additions & 0 deletions internal/ro2/source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ro2

import (
"github.com/vinceanalytics/vince/internal/bsi"
"github.com/vinceanalytics/vince/internal/encoding"
"github.com/vinceanalytics/vince/internal/models"
"github.com/vinceanalytics/vince/internal/roaring"
)

type KV []*roaring.Bitmap

func NewKV(tx *Tx, ts, shard uint64, field models.Field) *bsi.BSI {
key := encoding.Bitmap(ts, shard, field, 0,
make([]byte, encoding.BitmapKeySize))
kv := make(KV, 0, 64)
prefix := key[:len(key)-1]
it := tx.Iter()
for it.Seek(key); it.ValidForPrefix(prefix); it.Next() {
value, _ := it.Item().ValueCopy(nil)
b := roaring.FromBuffer(value)
kv = append(kv, b)
}
return &bsi.BSI{Source: kv}
}

var _ bsi.Source = (*KV)(nil)

func (kv KV) GetOrCreate(i int) *roaring.Bitmap { return nil }

func (kv KV) Get(i int) *roaring.Bitmap {
if i < len(kv) {
return kv[i]
}
return nil
}
2 changes: 1 addition & 1 deletion internal/ro2/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (tx *Tx) Bitmap(shard, view uint64, field models.Field) *bsi.BSI {
if b, ok := tx.bsi[key]; ok {
return b
}
b := bsi.NewKV(tx.tx, view, shard, field)
b := NewKV(tx, view, shard, field)
tx.bsi[key] = b
return b
}
Expand Down

0 comments on commit f9c2c71

Please sign in to comment.