added clear routine for fragment container

This commit is contained in:
Todd Gruben 2014-01-14 15:10:43 -06:00
parent 5315f75657
commit 172eb12932
5 changed files with 36 additions and 3 deletions

View file

@ -31,7 +31,6 @@ type Brand struct {
func NewBrand(db string, slice int, s Storage, threshold_len int, threshold int, skipp int) *Brand {
f := new(Brand)
f.bitmap_cache = make(map[uint64]*Rank)
f.storage = s
f.slice = slice
f.db = db
@ -40,10 +39,14 @@ func NewBrand(db string, slice int, s Storage, threshold_len int, threshold int,
f.threshold_length = threshold_len
f.threshold_idx = threshold
f.skip = skipp
f.Clear() //alloc the cache
return f
}
func (self *Brand) Clear() bool {
self.bitmap_cache = make(map[uint64]*Rank)
return true
}
func (self *Brand) Get(bitmap_id uint64) IBitmap {
bm, ok := self.bitmap_cache[bitmap_id]
if ok {

View file

@ -191,3 +191,14 @@ func NewTopN(b BitmapHandle, n int) *CmdTopN {
func (self *CmdTopN) Execute(f *Fragment) Calculation {
return f.TopN(self.bitmap, self.n)
}
type CmdClear struct {
*Responder
}
func NewClear() *CmdClear {
return &CmdClear{NewResponder("Clear")}
}
func (self *CmdClear) Execute(f *Fragment) Calculation {
return f.impl.Clear()
}

View file

@ -123,6 +123,15 @@ func (self *FragmentContainer) SetBit(frag_id SUUID, bitmap_id uint64, pos uint6
return false, errors.New("Invalid Bitmap Handle")
}
func (self *FragmentContainer) Clear(frag_id SUUID) (bool, error) {
if fragment, found := self.GetFragment(frag_id); found {
request := NewClear()
fragment.requestChan <- request
return request.Response().answer.(bool), nil
}
return false, errors.New("Invalid Fragment ID")
}
func (self *FragmentContainer) AddFragment(db string, frame string, slice int, id SUUID) {
log.Println("ADD FRAGMENT", frame)
f := NewFragment(id, db, slice, frame)
@ -134,6 +143,7 @@ type Pilosa interface {
Get(id uint64) IBitmap
SetBit(id uint64, bit_pos uint64) bool
TopN(b IBitmap, n int) []Pair
Clear() bool
}
type Fragment struct {

View file

@ -132,5 +132,9 @@ func TestFragment(t *testing.T) {
So(1, ShouldEqual, 1)
})
*/
Convey("Clear ", t, func() {
res, _ := dummy.Clear(general)
So(res, ShouldEqual, true)
})
}

View file

@ -11,13 +11,18 @@ type General struct {
func NewGeneral(db string, slice int, s Storage) *General {
f := new(General)
f.bitmap_cache = lru.New(10000)
f.storage = s
f.slice = slice
f.db = db
f.Clear()
//f.bitmap_cache = lru.New(10000)
return f
}
func (self *General) Clear() bool {
self.bitmap_cache = lru.New(10000)
return true
}
func (self *General) Get(bitmap_id uint64) IBitmap {
bm, ok := self.bitmap_cache.Get(bitmap_id)