mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-11 23:31:03 +00:00
changed SetBit to operate only on bitmap_id, setbit will create a bitmap record now
This commit is contained in:
parent
781ecd0ce4
commit
6edb519ecb
4 changed files with 24 additions and 16 deletions
|
|
@ -110,18 +110,17 @@ type BitArgs struct {
|
|||
Bit_pos uint64
|
||||
}
|
||||
type CmdSetBit struct {
|
||||
meta *Responder
|
||||
bitmap BitmapHandle
|
||||
bit_pos uint64
|
||||
meta *Responder
|
||||
bitmap_id uint64
|
||||
bit_pos uint64
|
||||
}
|
||||
|
||||
func NewSetBit(bitmap BitmapHandle, bit_pos uint64) *CmdSetBit {
|
||||
result := &CmdSetBit{NewResponder("SetBit"), bitmap, bit_pos}
|
||||
func NewSetBit(bitmap_id uint64, bit_pos uint64) *CmdSetBit {
|
||||
result := &CmdSetBit{NewResponder("SetBit"), bitmap_id, bit_pos}
|
||||
return result
|
||||
}
|
||||
func (cmd *CmdSetBit) Execute(f *Fragment) Calculation {
|
||||
bitmap, _ := f.getBitmap(cmd.bitmap)
|
||||
return SetBit(bitmap, cmd.bit_pos)
|
||||
return f.impl.SetBit(cmd.bitmap_id, cmd.bit_pos)
|
||||
}
|
||||
func (cmd *CmdSetBit) GetResponder() *Responder {
|
||||
return cmd.meta
|
||||
|
|
|
|||
|
|
@ -30,3 +30,7 @@ func (f *General) Get(bitmap_id uint64) IBitmap {
|
|||
f.bitmap_cache.Add(bitmap_id, bm)
|
||||
return bm.(*Bitmap)
|
||||
}
|
||||
func (f *General) SetBit(bitmap_id uint64, bit_pos uint64) bool {
|
||||
bm := f.Get(bitmap_id)
|
||||
return SetBit(bm, bit_pos)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ func (a *FragmentContainer) Count(frag_guid *uuid.UUID, bitmap BitmapHandle) (ui
|
|||
return 0, errors.New("Invalid Bitmap Handle")
|
||||
}
|
||||
|
||||
func (a *FragmentContainer) SetBit(frag_guid *uuid.UUID, bitmap BitmapHandle, pos uint64) (bool, error) {
|
||||
func (a *FragmentContainer) SetBit(frag_guid *uuid.UUID, bitmap_id uint64, pos uint64) (bool, error) {
|
||||
if fragment, found := a.GetFragment(frag_guid); found {
|
||||
request := NewSetBit(bitmap, pos)
|
||||
request := NewSetBit(bitmap_id, pos)
|
||||
fragment.requestChan <- request
|
||||
return request.GetResponder().Response().answer.(bool), nil
|
||||
}
|
||||
|
|
@ -75,6 +75,7 @@ func (a *FragmentContainer) AddFragment(frame string, db string, slice int, guid
|
|||
|
||||
type Pilosa interface {
|
||||
Get(id uint64) IBitmap
|
||||
SetBit(id uint64, bit_pos uint64) bool
|
||||
}
|
||||
|
||||
type Fragment struct {
|
||||
|
|
|
|||
|
|
@ -21,21 +21,25 @@ func TestServer(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("SetBit/Count 1 1", t, func() {
|
||||
bh, _ := dummy.Get(id, 1234)
|
||||
changed, _ := dummy.SetBit(id, bh, 1)
|
||||
// bh, _ := dummy.Get(id, 1234)
|
||||
bi1 := uint64(1234)
|
||||
changed, _ := dummy.SetBit(id, bi1, 1)
|
||||
So(changed, ShouldEqual, true)
|
||||
changed, _ = dummy.SetBit(id, bh, 1)
|
||||
changed, _ = dummy.SetBit(id, bi1, 1)
|
||||
So(changed, ShouldEqual, false)
|
||||
bh, _ := dummy.Get(id, bi1)
|
||||
num, _ := dummy.Count(id, bh)
|
||||
So(num, ShouldEqual, 1)
|
||||
})
|
||||
|
||||
Convey("Union/Intersect", t, func() {
|
||||
bh1, _ := dummy.Get(id, 1234)
|
||||
// dummy.SetBit(id, bh1, 1)
|
||||
bi1 := uint64(1234)
|
||||
bi2 := uint64(4321)
|
||||
|
||||
bh2, _ := dummy.Get(id, 4321)
|
||||
dummy.SetBit(id, bh2, 2)
|
||||
dummy.SetBit(id, bi2, 2) //set_bit creates the bitmap
|
||||
|
||||
bh1, _ := dummy.Get(id, bi1)
|
||||
bh2, _ := dummy.Get(id, bi2)
|
||||
|
||||
handles := []BitmapHandle{bh1, bh2}
|
||||
result, _ := dummy.Union(id, handles)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue