mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 03:47:51 +00:00
added AND_NOT operation and supporting tests
This commit is contained in:
parent
9137b45b46
commit
2fd9d1db26
3 changed files with 78 additions and 3 deletions
|
|
@ -222,6 +222,59 @@ func Union(a_bm IBitmap, b_bm IBitmap) IBitmap {
|
|||
return output
|
||||
}
|
||||
|
||||
func AND_NOT(a_bm IBitmap, b_bm IBitmap) IBitmap {
|
||||
var a = a_bm.Min()
|
||||
var b = b_bm.Min()
|
||||
defer a.Close()
|
||||
defer b.Close()
|
||||
output := CreateRBBitmap()
|
||||
var o_last_Key = uint64(0)
|
||||
|
||||
if o_last_Key != 0{
|
||||
o_last_Key = uint64(0)
|
||||
}
|
||||
|
||||
for {
|
||||
if a.Limit() && b.Limit() {
|
||||
break
|
||||
} else if a.Limit() {
|
||||
break
|
||||
} else if b.Limit() {
|
||||
var a_node = a.Item()
|
||||
var o_node = &Chunk{a_node.Key, a_node.Value}
|
||||
output.AddChunk(o_node)
|
||||
o_last_Key = o_node.Key
|
||||
a = a.Next()
|
||||
} else if a.Item().Key < b.Item().Key {
|
||||
var a_node = a.Item()
|
||||
var o_node = &Chunk{a_node.Key, a_node.Value}
|
||||
output.AddChunk(o_node)
|
||||
o_last_Key = o_node.Key
|
||||
a = a.Next()
|
||||
} else if a.Item().Key > b.Item().Key {
|
||||
var b_node = b.Item()
|
||||
o_last_Key = b_node.Key
|
||||
b = b.Next()
|
||||
} else if a.Item().Key == b.Item().Key {
|
||||
var a_node = a.Item()
|
||||
var b_node = BlockArray_invert(&b.Item().Value) //probably need to copy this out
|
||||
var o = BlockArray_intersection(&a_node.Value, &b_node)
|
||||
var o_node = &Chunk{a_node.Key, o}
|
||||
//could not add if all zero
|
||||
if o_node.Value.bitcount()>0{
|
||||
output.AddChunk(o_node)
|
||||
}
|
||||
o_last_Key = o_node.Key
|
||||
a = a.Next()
|
||||
b = b.Next()
|
||||
} else {
|
||||
log.Println("NEVER SHOULD BE HERE")
|
||||
break
|
||||
}
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
type ChunkIterator interface {
|
||||
Limit() bool
|
||||
Item() *Chunk
|
||||
|
|
|
|||
|
|
@ -19,6 +19,25 @@ func TestCount(t *testing.T) {
|
|||
t.Errorf("Count (%d) no equal 4096",bc1)
|
||||
}
|
||||
|
||||
}
|
||||
func TestANDNOT(t *testing.T){
|
||||
bm1:= CreateRBBitmap()
|
||||
bm2:= CreateRBBitmap()
|
||||
SetBit(bm1,1)
|
||||
//SetBit(bm2,2)
|
||||
all:= AND_NOT(bm1,bm2)
|
||||
res :=BitCount(all)
|
||||
if res != 1{
|
||||
t.Errorf("SHOULD BE 1 => %d",res)
|
||||
}
|
||||
|
||||
SetBit(bm2,1)
|
||||
all= AND_NOT(bm1,bm2)
|
||||
res =BitCount(all)
|
||||
if res != 0{
|
||||
t.Errorf("SHOULD BE 0 => %d",res)
|
||||
}
|
||||
|
||||
}
|
||||
func TestUnion(t *testing.T) {
|
||||
even:= CreateRBBitmap()
|
||||
|
|
|
|||
|
|
@ -24,11 +24,14 @@ func NewCassStorage() Storage{
|
|||
cluster.Consistency = gocql.Quorum
|
||||
//cluster.ProtoVersion = 1
|
||||
// cluster.CQLVersion = "3.0.0"
|
||||
session, err := cluster.CreateSession()
|
||||
if err != nil {
|
||||
// session, err := cluster.CreateSession()
|
||||
session := cluster.CreateSession()
|
||||
/* if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err = session.Query("USE hotbox").Exec(); err != nil {
|
||||
*/
|
||||
err := session.Query("USE hotbox").Exec()
|
||||
if err != nil {
|
||||
}
|
||||
obj.db = session
|
||||
return obj
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue