From 4190b720dc6efed49c8454a517b43404dd65313e Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Mon, 28 Jul 2014 19:22:48 +0000 Subject: [PATCH] performance enhancement for Difference --- index/bitmap.go | 17 +++++++++++++++-- index/storage_test.go | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/index/bitmap.go b/index/bitmap.go index 881c50a6e..b4210f353 100644 --- a/index/bitmap.go +++ b/index/bitmap.go @@ -121,6 +121,14 @@ func BlockArray_intersection(a *BlockArray, b *BlockArray) BlockArray { return o } +func BlockArray_difference(a *BlockArray, b *BlockArray) BlockArray { + var o = BlockArray{} + for i, _ := range a.Block { + o.Block[i] = a.Block[i] &^ b.Block[i] + } + return o +} + func (s *BlockArray) set_bit(BlockIndex uint8, bit uint8) bool { val := s.Block[BlockIndex] & (1 << bit) s.Block[BlockIndex] |= 1 << bit @@ -295,9 +303,14 @@ func Difference(a_bm IBitmap, b_bm IBitmap) IBitmap { 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 b_node = BlockArray_invert(&b.Item().Value) //probably need to copy this out + //var o = BlockArray_intersection(&a_node.Value, &b_node) + + var b_node = b.Item().Value + var o = BlockArray_difference(&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) diff --git a/index/storage_test.go b/index/storage_test.go index 9a1d00e11..69dd22b3a 100644 --- a/index/storage_test.go +++ b/index/storage_test.go @@ -6,7 +6,7 @@ import ( // "io/ioutil" // "time" - "github.com/davecgh/go-spew/spew" + . "github.com/smartystreets/goconvey/convey" ) @@ -58,7 +58,7 @@ func TestStorage(t *testing.T) { fmt.Println("FETCH") bm, _ := storage.Fetch(bitmap_id, db, frame, slice) - spew.Dump(bm) + //spew.Dump(bm) SetBit(bm, 0) SetBit(bm, 1) SetBit(bm, 2)