Skip to content

Commit c96abf9

Browse files
committed
Correcting overflows.
1 parent f158f63 commit c96abf9

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

roaring.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,10 +1125,10 @@ func (rb *Bitmap) Flip(rangeStart, rangeEnd uint64) {
11251125
return
11261126
}
11271127

1128-
hbStart := highbits(uint32(rangeStart))
1129-
lbStart := lowbits(uint32(rangeStart))
1130-
hbLast := highbits(uint32(rangeEnd - 1))
1131-
lbLast := lowbits(uint32(rangeEnd - 1))
1128+
hbStart := uint32(highbits(uint32(rangeStart)))
1129+
lbStart := uint32(lowbits(uint32(rangeStart)))
1130+
hbLast := uint32(highbits(uint32(rangeEnd - 1)))
1131+
lbLast := uint32(lowbits(uint32(rangeEnd - 1)))
11321132

11331133
var max uint32 = maxLowBit
11341134
for hb := hbStart; hb <= hbLast; hb++ {
@@ -1141,7 +1141,7 @@ func (rb *Bitmap) Flip(rangeStart, rangeEnd uint64) {
11411141
containerLast = uint32(lbLast)
11421142
}
11431143

1144-
i := rb.highlowcontainer.getIndex(hb)
1144+
i := rb.highlowcontainer.getIndex(uint16(hb))
11451145

11461146
if i >= 0 {
11471147
c := rb.highlowcontainer.getWritableContainerAtIndex(i).inot(int(containerStart), int(containerLast)+1)
@@ -1152,7 +1152,7 @@ func (rb *Bitmap) Flip(rangeStart, rangeEnd uint64) {
11521152
}
11531153
} else { // *think* the range of ones must never be
11541154
// empty.
1155-
rb.highlowcontainer.insertNewKeyValueAt(-i-1, hb, rangeOfOnes(int(containerStart), int(containerLast)))
1155+
rb.highlowcontainer.insertNewKeyValueAt(-i-1, uint16(hb), rangeOfOnes(int(containerStart), int(containerLast)))
11561156
}
11571157
}
11581158
}
@@ -1178,24 +1178,24 @@ func (rb *Bitmap) AddRange(rangeStart, rangeEnd uint64) {
11781178
lbLast := uint32(lowbits(uint32(rangeEnd - 1)))
11791179

11801180
var max uint32 = maxLowBit
1181-
for hb := uint16(hbStart); hb <= uint16(hbLast); hb++ {
1181+
for hb := hbStart; hb <= hbLast; hb++ {
11821182
containerStart := uint32(0)
1183-
if hb == uint16(hbStart) {
1183+
if hb == hbStart {
11841184
containerStart = lbStart
11851185
}
11861186
containerLast := max
1187-
if hb == uint16(hbLast) {
1187+
if hb == hbLast {
11881188
containerLast = lbLast
11891189
}
11901190

1191-
i := rb.highlowcontainer.getIndex(hb)
1191+
i := rb.highlowcontainer.getIndex(uint16(hb))
11921192

11931193
if i >= 0 {
11941194
c := rb.highlowcontainer.getWritableContainerAtIndex(i).iaddRange(int(containerStart), int(containerLast)+1)
11951195
rb.highlowcontainer.setContainerAtIndex(i, c)
11961196
} else { // *think* the range of ones must never be
11971197
// empty.
1198-
rb.highlowcontainer.insertNewKeyValueAt(-i-1, hb, rangeOfOnes(int(containerStart), int(containerLast)))
1198+
rb.highlowcontainer.insertNewKeyValueAt(-i-1, uint16(hb), rangeOfOnes(int(containerStart), int(containerLast)))
11991199
}
12001200
}
12011201
}
@@ -1282,13 +1282,13 @@ func Flip(bm *Bitmap, rangeStart, rangeEnd uint64) *Bitmap {
12821282
}
12831283

12841284
answer := NewBitmap()
1285-
hbStart := highbits(uint32(rangeStart))
1286-
lbStart := lowbits(uint32(rangeStart))
1287-
hbLast := highbits(uint32(rangeEnd - 1))
1288-
lbLast := lowbits(uint32(rangeEnd - 1))
1285+
hbStart := uint32(highbits(uint32(rangeStart)))
1286+
lbStart := uint32(lowbits(uint32(rangeStart)))
1287+
hbLast := uint32(highbits(uint32(rangeEnd - 1)))
1288+
lbLast := uint32(lowbits(uint32(rangeEnd - 1)))
12891289

12901290
// copy the containers before the active area
1291-
answer.highlowcontainer.appendCopiesUntil(bm.highlowcontainer, hbStart)
1291+
answer.highlowcontainer.appendCopiesUntil(bm.highlowcontainer, uint16(hbStart))
12921292

12931293
var max uint32 = maxLowBit
12941294
for hb := hbStart; hb <= hbLast; hb++ {
@@ -1301,23 +1301,23 @@ func Flip(bm *Bitmap, rangeStart, rangeEnd uint64) *Bitmap {
13011301
containerLast = uint32(lbLast)
13021302
}
13031303

1304-
i := bm.highlowcontainer.getIndex(hb)
1305-
j := answer.highlowcontainer.getIndex(hb)
1304+
i := bm.highlowcontainer.getIndex(uint16(hb))
1305+
j := answer.highlowcontainer.getIndex(uint16(hb))
13061306

13071307
if i >= 0 {
13081308
c := bm.highlowcontainer.getContainerAtIndex(i).not(int(containerStart), int(containerLast)+1)
13091309
if c.getCardinality() > 0 {
1310-
answer.highlowcontainer.insertNewKeyValueAt(-j-1, hb, c)
1310+
answer.highlowcontainer.insertNewKeyValueAt(-j-1, uint16(hb), c)
13111311
}
13121312

13131313
} else { // *think* the range of ones must never be
13141314
// empty.
1315-
answer.highlowcontainer.insertNewKeyValueAt(-j-1, hb,
1315+
answer.highlowcontainer.insertNewKeyValueAt(-j-1, uint16(hb),
13161316
rangeOfOnes(int(containerStart), int(containerLast)))
13171317
}
13181318
}
13191319
// copy the containers after the active area.
1320-
answer.highlowcontainer.appendCopiesAfter(bm.highlowcontainer, hbLast)
1320+
answer.highlowcontainer.appendCopiesAfter(bm.highlowcontainer, uint16(hbLast))
13211321

13221322
return answer
13231323
}

0 commit comments

Comments
 (0)