diff --git a/index/commands.go b/index/commands.go index 4f27c7483..cfc2be479 100644 --- a/index/commands.go +++ b/index/commands.go @@ -259,3 +259,18 @@ func (self *CmdLoadRequest) Execute(f *Fragment) Calculation { f.impl.Get(self.bitmap_id) return 0 } + +type CmdRange struct { + *Responder + bitmap_id uint64 + start_time time.Time + end_time time.Time +} + +func NewRange(bitmap_id uint64, start, end time.Time) *CmdRange { + return &CmdRange{NewResponder("Range"), bitmap_id, start, end} +} + +func (self *CmdRange) Execute(f *Fragment) Calculation { + return f.build_time_range_bitmap(self.bitmap_id, self.start_time, self.end_time) +} diff --git a/index/fragment_container.go b/index/fragment_container.go index 1abd38724..ef1a98022 100644 --- a/index/fragment_container.go +++ b/index/fragment_container.go @@ -137,6 +137,17 @@ func (self *FragmentContainer) Get(frag_id util.SUUID, bitmap_id uint64) (Bitmap return 0, errors.New("Invalid Bitmap Handle") } +func (self *FragmentContainer) Range(frag_id util.SUUID, bitmap_id uint64, start, end time.Time) (BitmapHandle, error) { + if fragment, found := self.GetFragment(frag_id); found { + request := NewRange(bitmap_id, start, end) + fragment.requestChan <- request + result := request.Response() + util.SendTimer("fragmant_container_Range", result.exec_time.Nanoseconds()) + return result.answer.(BitmapHandle), nil + } + return 0, errors.New("Invalid Bitmap Handle") +} + func (self *FragmentContainer) TopN(frag_id util.SUUID, bh BitmapHandle, n int, categories []uint64) ([]Pair, error) { if fragment, found := self.GetFragment(frag_id); found { request := NewTopN(bh, n, categories) @@ -327,6 +338,18 @@ func (self *Fragment) union(bitmaps []BitmapHandle) BitmapHandle { } return self.AllocHandle(result) } +func (self *Fragment) build_time_range_bitmap(bitmap_id uint64, start, end time.Time) BitmapHandle { + result := NewBitmap() + for i, bid := range GetRange(start, end, bitmap_id) { + bm := self.impl.Get(bid) + if i == 0 { + result = bm + } else { + result = Union(result, bm) + } + } + return self.AllocHandle(result) +} func (self *Fragment) intersect(bitmaps []BitmapHandle) BitmapHandle { var result IBitmap