From 6edb519ecb93e8ab553cb07693c7fde05b8c1253 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Tue, 17 Dec 2013 10:08:52 -0600 Subject: [PATCH] changed SetBit to operate only on bitmap_id, setbit will create a bitmap record now --- index/commands.go | 13 ++++++------- index/general.go | 4 ++++ index/server.go | 5 +++-- index/server_test.go | 18 +++++++++++------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/index/commands.go b/index/commands.go index 297656e7b..7447c58a7 100644 --- a/index/commands.go +++ b/index/commands.go @@ -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 diff --git a/index/general.go b/index/general.go index 582b248de..3b1a9d209 100644 --- a/index/general.go +++ b/index/general.go @@ -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) +} diff --git a/index/server.go b/index/server.go index 2e934e755..627a8dd56 100644 --- a/index/server.go +++ b/index/server.go @@ -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 { diff --git a/index/server_test.go b/index/server_test.go index 216045f2b..52affec5a 100644 --- a/index/server_test.go +++ b/index/server_test.go @@ -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)