mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-06 10:57:51 +00:00
refactored commands to utilize anonymous fields
This commit is contained in:
parent
3c85487f04
commit
a4ed1d9a8c
2 changed files with 18 additions and 38 deletions
|
|
@ -39,11 +39,13 @@ type Calculation interface{}
|
|||
|
||||
type Command interface {
|
||||
Execute(*Fragment) Calculation
|
||||
GetResponder() *Responder
|
||||
QueryType() string
|
||||
Response() Result
|
||||
ResponseChannel() chan Result
|
||||
}
|
||||
|
||||
type CmdGet struct {
|
||||
meta *Responder
|
||||
*Responder
|
||||
bitmap_id uint64
|
||||
}
|
||||
|
||||
|
|
@ -51,15 +53,12 @@ func NewGet(bitmap_id uint64) *CmdGet {
|
|||
return &CmdGet{NewResponder("Get"), bitmap_id}
|
||||
}
|
||||
|
||||
func (cmd *CmdGet) GetResponder() *Responder {
|
||||
return cmd.meta
|
||||
}
|
||||
func (cmd *CmdGet) Execute(f *Fragment) Calculation {
|
||||
return f.NewHandle(cmd.bitmap_id)
|
||||
}
|
||||
|
||||
type CmdCount struct {
|
||||
meta *Responder
|
||||
*Responder
|
||||
bitmap BitmapHandle
|
||||
}
|
||||
|
||||
|
|
@ -67,16 +66,13 @@ func NewCount(bitmap_handle BitmapHandle) *CmdCount {
|
|||
return &CmdCount{NewResponder("Count"), bitmap_handle}
|
||||
}
|
||||
|
||||
func (cmd *CmdCount) GetResponder() *Responder {
|
||||
return cmd.meta
|
||||
}
|
||||
func (cmd *CmdCount) Execute(f *Fragment) Calculation {
|
||||
bm, _ := f.getBitmap(cmd.bitmap)
|
||||
return BitCount(bm)
|
||||
}
|
||||
|
||||
type CmdUnion struct {
|
||||
meta *Responder
|
||||
*Responder
|
||||
bitmap_ids []BitmapHandle
|
||||
}
|
||||
|
||||
|
|
@ -87,12 +83,9 @@ func NewUnion(bitmaps []BitmapHandle) *CmdUnion {
|
|||
func (cmd *CmdUnion) Execute(f *Fragment) Calculation {
|
||||
return f.union(cmd.bitmap_ids)
|
||||
}
|
||||
func (cmd *CmdUnion) GetResponder() *Responder {
|
||||
return cmd.meta
|
||||
}
|
||||
|
||||
type CmdIntersect struct {
|
||||
meta *Responder
|
||||
*Responder
|
||||
bitmaps []BitmapHandle
|
||||
}
|
||||
|
||||
|
|
@ -102,16 +95,13 @@ func NewIntersect(bh []BitmapHandle) *CmdIntersect {
|
|||
func (cmd *CmdIntersect) Execute(f *Fragment) Calculation {
|
||||
return f.intersect(cmd.bitmaps)
|
||||
}
|
||||
func (cmd *CmdIntersect) GetResponder() *Responder {
|
||||
return cmd.meta
|
||||
}
|
||||
|
||||
type BitArgs struct {
|
||||
Bitmap_id uint64
|
||||
Bit_pos uint64
|
||||
}
|
||||
type CmdSetBit struct {
|
||||
meta *Responder
|
||||
*Responder
|
||||
bitmap_id uint64
|
||||
bit_pos uint64
|
||||
}
|
||||
|
|
@ -123,12 +113,9 @@ func NewSetBit(bitmap_id uint64, bit_pos uint64) *CmdSetBit {
|
|||
func (cmd *CmdSetBit) Execute(f *Fragment) Calculation {
|
||||
return f.impl.SetBit(cmd.bitmap_id, cmd.bit_pos)
|
||||
}
|
||||
func (cmd *CmdSetBit) GetResponder() *Responder {
|
||||
return cmd.meta
|
||||
}
|
||||
|
||||
type CmdGetBytes struct {
|
||||
meta *Responder
|
||||
*Responder
|
||||
bitmap BitmapHandle
|
||||
}
|
||||
|
||||
|
|
@ -136,16 +123,13 @@ func NewGetBytes(bh BitmapHandle) *CmdGetBytes {
|
|||
return &CmdGetBytes{NewResponder("GetBytes"), bh}
|
||||
}
|
||||
|
||||
func (cmd *CmdGetBytes) GetResponder() *Responder {
|
||||
return cmd.meta
|
||||
}
|
||||
func (cmd *CmdGetBytes) Execute(f *Fragment) Calculation {
|
||||
bm, _ := f.getBitmap(cmd.bitmap)
|
||||
return bm.ToBytes()
|
||||
}
|
||||
|
||||
type CmdFromBytes struct {
|
||||
meta *Responder
|
||||
*Responder
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
|
|
@ -153,9 +137,6 @@ func NewFromBytes(bytes []byte) *CmdFromBytes {
|
|||
return &CmdFromBytes{NewResponder("FromBytes"), bytes}
|
||||
}
|
||||
|
||||
func (cmd *CmdFromBytes) GetResponder() *Responder {
|
||||
return cmd.meta
|
||||
}
|
||||
func (cmd *CmdFromBytes) Execute(f *Fragment) Calculation {
|
||||
result := NewBitmap()
|
||||
result.FromBytes(cmd.bytes)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func (self *FragmentContainer) Intersect(frag_id SUUID, bh []BitmapHandle) (Bitm
|
|||
if fragment, found := self.GetFragment(frag_id); found {
|
||||
request := NewIntersect(bh)
|
||||
fragment.requestChan <- request
|
||||
return request.GetResponder().Response().answer.(BitmapHandle), nil
|
||||
return request.Response().answer.(BitmapHandle), nil
|
||||
}
|
||||
return 0, errors.New("Invalid Bitmap Handle")
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ func (self *FragmentContainer) Union(frag_id SUUID, bh []BitmapHandle) (BitmapHa
|
|||
if fragment, found := self.GetFragment(frag_id); found {
|
||||
request := NewUnion(bh)
|
||||
fragment.requestChan <- request
|
||||
return request.GetResponder().Response().answer.(BitmapHandle), nil
|
||||
return request.Response().answer.(BitmapHandle), nil
|
||||
}
|
||||
return 0, errors.New("Invalid Bitmap Handle")
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ func (self *FragmentContainer) Get(frag_id SUUID, bitmap_id uint64) (BitmapHandl
|
|||
if fragment, found := self.GetFragment(frag_id); found {
|
||||
request := NewGet(bitmap_id)
|
||||
fragment.requestChan <- request
|
||||
return request.GetResponder().Response().answer.(BitmapHandle), nil
|
||||
return request.Response().answer.(BitmapHandle), nil
|
||||
}
|
||||
return 0, errors.New("Invalid Bitmap Handle")
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ func (self *FragmentContainer) Count(frag_id SUUID, bitmap BitmapHandle) (uint64
|
|||
if fragment, found := self.GetFragment(frag_id); found {
|
||||
request := NewCount(bitmap)
|
||||
fragment.requestChan <- request
|
||||
return request.GetResponder().Response().answer.(uint64), nil
|
||||
return request.Response().answer.(uint64), nil
|
||||
}
|
||||
return 0, errors.New("Invalid Bitmap Handle")
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ func (self *FragmentContainer) GetBytes(frag_id SUUID, bh BitmapHandle) ([]byte,
|
|||
if fragment, found := self.GetFragment(frag_id); found {
|
||||
request := NewGetBytes(bh)
|
||||
fragment.requestChan <- request
|
||||
return request.GetResponder().Response().answer.([]byte), nil
|
||||
return request.Response().answer.([]byte), nil
|
||||
}
|
||||
return nil, errors.New("Invalid Bitmap Handle")
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ func (self *FragmentContainer) FromBytes(frag_id SUUID, bytes []byte) (BitmapHan
|
|||
if fragment, found := self.GetFragment(frag_id); found {
|
||||
request := NewFromBytes(bytes)
|
||||
fragment.requestChan <- request
|
||||
return request.GetResponder().Response().answer.(BitmapHandle), nil
|
||||
return request.Response().answer.(BitmapHandle), nil
|
||||
}
|
||||
return 0, errors.New("Invalid Bitmap Handle")
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ func (self *FragmentContainer) SetBit(frag_id SUUID, bitmap_id uint64, pos uint6
|
|||
if fragment, found := self.GetFragment(frag_id); found {
|
||||
request := NewSetBit(bitmap_id, pos)
|
||||
fragment.requestChan <- request
|
||||
return request.GetResponder().Response().answer.(bool), nil
|
||||
return request.Response().answer.(bool), nil
|
||||
}
|
||||
return false, errors.New("Invalid Bitmap Handle")
|
||||
}
|
||||
|
|
@ -169,7 +169,6 @@ func (self *Fragment) ServeFragment() {
|
|||
for {
|
||||
req := <-self.requestChan
|
||||
start := time.Now()
|
||||
responder := req.GetResponder()
|
||||
answer := req.Execute(self)
|
||||
delta := time.Since(start)
|
||||
/*
|
||||
|
|
@ -179,7 +178,7 @@ func (self *Fragment) ServeFragment() {
|
|||
buffer.WriteString(fmt.Sprintf(`,"query type": "%s"`, responder.QueryType()))
|
||||
buffer.WriteString(fmt.Sprintf(`, "elapsed": "%s"}`, delta))
|
||||
*/
|
||||
responder.ResponseChannel() <- Result{answer, delta}
|
||||
req.ResponseChannel() <- Result{answer, delta}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue