Skip to content

Commit

Permalink
atg. fix integer overflow problem
Browse files Browse the repository at this point in the history
  • Loading branch information
glycerine committed Dec 16, 2016
1 parent 5baee8f commit d2a373e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
17 changes: 4 additions & 13 deletions arraycontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,27 +514,18 @@ 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())

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
}

Expand Down
10 changes: 7 additions & 3 deletions bitmapcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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++ {
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions example_roaring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 3 additions & 1 deletion rlei.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion roaring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d2a373e

Please sign in to comment.