From 2fd9d1db26d1f3419f5aac225c9716377128017f Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Wed, 20 Nov 2013 16:58:23 -0600 Subject: [PATCH] added AND_NOT operation and supporting tests --- index/bitmap.go | 53 +++++++++++++++++++++++++++++++++++++++++++ index/bitmap_test.go | 19 ++++++++++++++++ index/storage_cass.go | 9 +++++--- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/index/bitmap.go b/index/bitmap.go index 71bfc267b..ebd51f73c 100644 --- a/index/bitmap.go +++ b/index/bitmap.go @@ -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 diff --git a/index/bitmap_test.go b/index/bitmap_test.go index 00b1ed722..9b50e6067 100644 --- a/index/bitmap_test.go +++ b/index/bitmap_test.go @@ -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() diff --git a/index/storage_cass.go b/index/storage_cass.go index f4b6e3d7c..e052b373e 100644 --- a/index/storage_cass.go +++ b/index/storage_cass.go @@ -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