diff --git a/arraycontainer.go b/arraycontainer.go index ddac9257..db80fb91 100644 --- a/arraycontainer.go +++ b/arraycontainer.go @@ -514,7 +514,7 @@ func (ac *arrayContainer) iandNot(a container) container { } func (ac *arrayContainer) iandNotRun16(rc *runContainer16) container { - //p("arrayContainer.iandNotRun16() starting") + //p("arrayContainer.iandNotRun16() starting; rc = %s", rc) rcb := rc.toBitmapContainer() //p("rcb has size %v", rcb.getCardinality()) @@ -522,19 +522,10 @@ func (ac *arrayContainer) iandNotRun16(rc *runContainer16) container { acb := ac.toBitmapContainer() //p("acb has size %v", acb.getCardinality()) - anew := acb.andNotBitmap(rcb) - //p("anew has size %v", anew.getCardinality()) + acb.iandNotBitmapSurely(rcb) + //p("after iandNotBit, acb has size %v", acb.getCardinality()) - switch x := anew.(type) { - case *arrayContainer: - *ac = *x - case *bitmapContainer: - *ac = *(x.toArrayContainer()) - case *runContainer16: - *ac = *(x.toArrayContainer()) - default: - panic("unsupported container type") - } + *ac = *(acb.toArrayContainer()) return ac } diff --git a/bitmapcontainer.go b/bitmapcontainer.go index a845ae17..d32fb70a 100644 --- a/bitmapcontainer.go +++ b/bitmapcontainer.go @@ -585,13 +585,13 @@ func (bc *bitmapContainer) andNotRun16(rc *runContainer16) container { } func (bc *bitmapContainer) iandNot(a container) container { - p("bitmapContainer.iandNot() starting") + //p("bitmapContainer.iandNot() starting") switch x := a.(type) { case *arrayContainer: return bc.iandNotArray(x) case *bitmapContainer: - return bc.iandNotBitmap(x) + return bc.iandNotBitmapSurely(x) case *runContainer16: return bc.iandNotRun16(x) } @@ -649,7 +649,10 @@ func (bc *bitmapContainer) iandNotBitmapSurely(value2 *bitmapContainer) *bitmapC return bc } -func (bc *bitmapContainer) iandNotBitmap(value2 *bitmapContainer) container { +// warning, this function may not actually modify the bc array in place! +// TODO: delete? Mostly replaced with iandNotBitmapSurely +/* +func (bc *bitmapContainer) iandNotBitmapSCARY(value2 *bitmapContainer) container { newCardinality := int(popcntMaskSlice(bc.bitmap, value2.bitmap)) if newCardinality > arrayDefaultMaxSize { for k := 0; k < len(bc.bitmap); k++ { @@ -662,6 +665,7 @@ func (bc *bitmapContainer) iandNotBitmap(value2 *bitmapContainer) container { fillArrayANDNOT(ac.content, bc.bitmap, value2.bitmap) return ac } +*/ func (bc *bitmapContainer) contains(i uint16) bool { //testbit x := int(i) diff --git a/example_roaring_test.go b/example_roaring_test.go index 3861c99c..6efeb1ed 100644 --- a/example_roaring_test.go +++ b/example_roaring_test.go @@ -112,11 +112,13 @@ func TestExample2_roaring061(t *testing.T) { for i := uint32(0); i < 10000; i += 3 { rb1.Add(i) } - fmt.Printf("\nrb1card before doing AndNot(rb3): %v\n", - rb1.GetCardinality()) + fmt.Printf("\n rb1card before doing AndNot(rb3): %v, rb3card=%v\n", + rb1.GetCardinality(), rb3.GetCardinality()) rb1.AndNot(rb3) rb1card := rb1.GetCardinality() if rb1card != 1 { + //rb1.RunOptimize() + //fmt.Printf("\n rb1 = %s\n", rb1) t.Errorf("Only the value 0 should survive the andNot; rb1card = %v", rb1card) } } diff --git a/rlei.go b/rlei.go index 01b122de..11c9253e 100644 --- a/rlei.go +++ b/rlei.go @@ -545,10 +545,12 @@ func (rc *runContainer16) andNotBitmap(bc *bitmapContainer) container { } func (rc *runContainer16) toBitmapContainer() *bitmapContainer { + p("run16 toBitmap starting; rc has %v ranges", len(rc.iv)) bc := newBitmapContainer() for i := range rc.iv { - bc.iaddRange(int(rc.iv[i].start), int(rc.iv[i].last+1)) + bc.iaddRange(int(rc.iv[i].start), int(rc.iv[i].last)+1) } + bc.computeCardinality() return bc } diff --git a/roaring.go b/roaring.go index 66a0c535..5ab5d105 100644 --- a/roaring.go +++ b/roaring.go @@ -1005,7 +1005,7 @@ func (rb *Bitmap) AddRange(rangeStart, rangeEnd uint64) { i := rb.highlowcontainer.getIndex(hb) if i >= 0 { - c := rb.highlowcontainer.getWritableContainerAtIndex(i).iaddRange(int(containerStart), int(containerLast+1)) + c := rb.highlowcontainer.getWritableContainerAtIndex(i).iaddRange(int(containerStart), int(containerLast)+1) rb.highlowcontainer.setContainerAtIndex(i, c) } else { // *think* the range of ones must never be // empty.