From f741623420bff88edcff3be463110fa8301fb725 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Thu, 19 Dec 2013 14:17:19 -0600 Subject: [PATCH] added list gethandle operation --- index/commands.go | 18 ++++++++++++++++++ index/fragment_container.go | 10 ++++++++++ index/fragment_container_test.go | 7 +++++++ 3 files changed, 35 insertions(+) diff --git a/index/commands.go b/index/commands.go index 4540330ce..197a83eca 100644 --- a/index/commands.go +++ b/index/commands.go @@ -170,3 +170,21 @@ func (self *CmdEmpty) Execute(f *Fragment) Calculation { result := NewBitmap() return f.AllocHandle(result) } + +type CmdGetList struct { + *Responder + bitmap_ids []uint64 +} + +func NewGetList(bitmap_ids []uint64) *CmdGetList { + return &CmdGetList{NewResponder("GetList"), bitmap_ids} +} + +func (self *CmdGetList) Execute(f *Fragment) Calculation { + ret := make([]BitmapHandle, len(self.bitmap_ids)) + for i, v := range self.bitmap_ids { + ret[i] = f.NewHandle(v) + } + + return ret +} diff --git a/index/fragment_container.go b/index/fragment_container.go index 78bfdb914..4fda87cb4 100644 --- a/index/fragment_container.go +++ b/index/fragment_container.go @@ -58,6 +58,16 @@ func (self *FragmentContainer) Get(frag_id SUUID, bitmap_id uint64) (BitmapHandl } return 0, errors.New("Invalid Bitmap Handle") } + +func (self *FragmentContainer) GetList(frag_id SUUID, bitmap_id []uint64) ([]BitmapHandle, error) { + if fragment, found := self.GetFragment(frag_id); found { + request := NewGetList(bitmap_id) + fragment.requestChan <- request + return request.Response().answer.([]BitmapHandle), nil + } + return nil, errors.New("Invalid Bitmap Handle") +} + func (self *FragmentContainer) Count(frag_id SUUID, bitmap BitmapHandle) (uint64, error) { if fragment, found := self.GetFragment(frag_id); found { request := NewCount(bitmap) diff --git a/index/fragment_container_test.go b/index/fragment_container_test.go index 1561c6fea..396c1ad45 100644 --- a/index/fragment_container_test.go +++ b/index/fragment_container_test.go @@ -68,4 +68,11 @@ func TestServer(t *testing.T) { before, _ := dummy.Count(id, bh) So(before, ShouldEqual, 0) }) + + Convey("GetList ", t, func() { + bhs, _ := dummy.GetList(id, []uint64{1234, 4321, 789}) + result, _ := dummy.Union(id, bhs) + num, _ := dummy.Count(id, result) + So(num, ShouldNotEqual, 2) + }) }