mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-06 08:35:55 +00:00
cleaned up some golint warnings
This commit is contained in:
parent
75a80768c3
commit
d62f18fcf9
2 changed files with 228 additions and 224 deletions
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// package roaring implements roaring bitmaps with support for incremental changes.
|
||||
// Package roaring implements roaring bitmaps with support for incremental changes.
|
||||
package roaring
|
||||
|
||||
import (
|
||||
|
|
@ -50,11 +50,15 @@ const (
|
|||
// bitmapN is the number of values in a container.bitmap.
|
||||
bitmapN = (1 << 16) / 64
|
||||
|
||||
// manual allocation size tuned to our average client data
|
||||
manualAlloc = 524288
|
||||
ContainerArray = byte(1)
|
||||
//ContainerArray indicates a container of bit position values
|
||||
ContainerArray = byte(1)
|
||||
|
||||
//ContainerBitmap indicates a container of bits packed in a uint64 array block
|
||||
ContainerBitmap = byte(2)
|
||||
ContainerRun = byte(3)
|
||||
|
||||
//ContainerRun indicates a container of run encoded bits
|
||||
ContainerRun = byte(3)
|
||||
|
||||
maxContainerVal = 0xffff
|
||||
)
|
||||
|
||||
|
|
@ -216,7 +220,7 @@ func (b *Bitmap) CountRange(start, end uint64) (n uint64) {
|
|||
} else {
|
||||
// Count first partial container and advance i so we don't recount it
|
||||
n += uint64(b.containers[i].countRange(int(lowbits(start)), maxContainerVal+1))
|
||||
i += 1
|
||||
i++
|
||||
}
|
||||
|
||||
// Count last container.
|
||||
|
|
@ -546,7 +550,7 @@ func (b *Bitmap) WriteTo(w io.Writer) (n int64, err error) {
|
|||
byte8 := make([]byte, 8)
|
||||
|
||||
// Build header before writing individual container blocks.
|
||||
// Metadata for each container is 8+2+2+4 = sizeof(key) + sizeof(container_type)+sizeof(cardinality) + sizeof(file offset)
|
||||
// Metadata for each container is 8+2+2+4 = sizeof(key) + sizeof(containerType)+sizeof(cardinality) + sizeof(file offset)
|
||||
// Cookie header section.
|
||||
|
||||
WriteUint32(w, byte4, cookie)
|
||||
|
|
@ -563,7 +567,7 @@ func (b *Bitmap) WriteTo(w io.Writer) (n int64, err error) {
|
|||
//assert(c.count() == c.n, "cannot write container count, mismatch: count=%d, n=%d", count, c.n)
|
||||
if c.n > 0 {
|
||||
WriteUint64(w, byte8, uint64(key))
|
||||
WriteUint16(w, byte2, uint16(c.container_type))
|
||||
WriteUint16(w, byte2, uint16(c.containerType))
|
||||
WriteUint16(w, byte2, uint16(c.n-1))
|
||||
}
|
||||
}
|
||||
|
|
@ -638,14 +642,14 @@ func (b *Bitmap) UnmarshalBinary(data []byte) error {
|
|||
if i >= len(b.keys) {
|
||||
b.keys = append(b.keys, binary.LittleEndian.Uint64(buf[0:8]))
|
||||
b.containers = append(b.containers, &container{
|
||||
container_type: byte(binary.LittleEndian.Uint16(buf[8:10])),
|
||||
n: int(binary.LittleEndian.Uint16(buf[10:12])) + 1,
|
||||
mapped: true,
|
||||
containerType: byte(binary.LittleEndian.Uint16(buf[8:10])),
|
||||
n: int(binary.LittleEndian.Uint16(buf[10:12])) + 1,
|
||||
mapped: true,
|
||||
})
|
||||
} else {
|
||||
b.keys[i] = binary.LittleEndian.Uint64(buf[0:8])
|
||||
c := b.containers[i]
|
||||
c.container_type = byte(binary.LittleEndian.Uint16(buf[8:10]))
|
||||
c.containerType = byte(binary.LittleEndian.Uint16(buf[8:10]))
|
||||
c.n = int(binary.LittleEndian.Uint16(buf[10:12])) + 1
|
||||
c.mapped = true
|
||||
|
||||
|
|
@ -663,7 +667,7 @@ func (b *Bitmap) UnmarshalBinary(data []byte) error {
|
|||
|
||||
// Map byte slice directly to the container data.
|
||||
c := b.containers[i]
|
||||
switch c.container_type {
|
||||
switch c.containerType {
|
||||
case ContainerRun:
|
||||
c.array = nil
|
||||
c.bitmap = nil
|
||||
|
|
@ -982,12 +986,12 @@ const RunMaxSize = 2048
|
|||
// an array or RLE container is used, depending on the contents. For containers
|
||||
// with more than 4,096 values, the values are encoded into bitmaps.
|
||||
type container struct {
|
||||
container_type byte // array, bitmap, or run
|
||||
n int // number of integers in container
|
||||
array []uint16 // used for array containers
|
||||
bitmap []uint64 // used for bitmap containers
|
||||
runs []interval16 // used for RLE containers
|
||||
mapped bool // mapped directly to a byte slice when true
|
||||
containerType byte // array, bitmap, or run
|
||||
n int // number of integers in container
|
||||
array []uint16 // used for array containers
|
||||
bitmap []uint64 // used for bitmap containers
|
||||
runs []interval16 // used for RLE containers
|
||||
mapped bool // mapped directly to a byte slice when true
|
||||
}
|
||||
|
||||
type interval16 struct {
|
||||
|
|
@ -1002,22 +1006,22 @@ func (iv interval16) runlen() int {
|
|||
|
||||
// newContainer returns a new instance of container.
|
||||
func newContainer() *container {
|
||||
return &container{container_type: ContainerArray}
|
||||
return &container{containerType: ContainerArray}
|
||||
}
|
||||
|
||||
// isArray returns true if the container is an array container.
|
||||
func (c *container) isArray() bool {
|
||||
return c.container_type == ContainerArray
|
||||
return c.containerType == ContainerArray
|
||||
}
|
||||
|
||||
// isBitmap returns true if the container is a bitmap container.
|
||||
func (c *container) isBitmap() bool {
|
||||
return c.container_type == ContainerBitmap
|
||||
return c.containerType == ContainerBitmap
|
||||
}
|
||||
|
||||
// isRun returns true if the container is a run-length-encoded container.
|
||||
func (c *container) isRun() bool {
|
||||
return c.container_type == ContainerRun
|
||||
return c.containerType == ContainerRun
|
||||
}
|
||||
|
||||
// unmap creates copies of the containers data in the heap.
|
||||
|
|
@ -1029,7 +1033,7 @@ func (c *container) unmap() {
|
|||
return
|
||||
}
|
||||
|
||||
switch c.container_type {
|
||||
switch c.containerType {
|
||||
case ContainerArray:
|
||||
tmp := make([]uint16, len(c.array))
|
||||
copy(tmp, c.array)
|
||||
|
|
@ -1207,7 +1211,7 @@ func (c *container) runAdd(v uint16) bool {
|
|||
c.unmap()
|
||||
if iv.last < v {
|
||||
if iv.last == v-1 {
|
||||
c.runs[i].last += 1
|
||||
c.runs[i].last++
|
||||
} else {
|
||||
c.runs = append(c.runs, interval16{start: v, last: v})
|
||||
}
|
||||
|
|
@ -1219,10 +1223,10 @@ func (c *container) runAdd(v uint16) bool {
|
|||
return true
|
||||
}
|
||||
// just before an interval
|
||||
c.runs[i].start -= 1
|
||||
c.runs[i].start--
|
||||
} else if i > 0 && v-1 == c.runs[i-1].last {
|
||||
// just after an interval
|
||||
c.runs[i-1].last += 1
|
||||
c.runs[i-1].last++
|
||||
} else {
|
||||
// alone
|
||||
newIv := interval16{start: v, last: v}
|
||||
|
|
@ -1256,7 +1260,7 @@ func (c *container) arrayCountRuns() (r int) {
|
|||
prev := -2
|
||||
for _, v := range c.array {
|
||||
if prev+1 != int(v) {
|
||||
r += 1
|
||||
r++
|
||||
}
|
||||
prev = int(v)
|
||||
}
|
||||
|
|
@ -1395,9 +1399,9 @@ func (c *container) runRemove(v uint16) bool {
|
|||
if v == c.runs[i].last && v == c.runs[i].start {
|
||||
c.runs = append(c.runs[:i], c.runs[i+1:]...)
|
||||
} else if v == c.runs[i].last {
|
||||
c.runs[i].last -= 1
|
||||
c.runs[i].last--
|
||||
} else if v == c.runs[i].start {
|
||||
c.runs[i].start += 1
|
||||
c.runs[i].start++
|
||||
} else if v > c.runs[i].start {
|
||||
last := c.runs[i].last
|
||||
c.runs[i].last = v - 1
|
||||
|
|
@ -1453,7 +1457,7 @@ func (c *container) runMax() uint16 {
|
|||
// bitmapToArray converts from bitmap format to array format.
|
||||
func (c *container) bitmapToArray() {
|
||||
c.array = make([]uint16, 0, c.n)
|
||||
c.container_type = ContainerArray
|
||||
c.containerType = ContainerArray
|
||||
|
||||
// return early if empty
|
||||
if c.n == 0 {
|
||||
|
|
@ -1476,7 +1480,7 @@ func (c *container) bitmapToArray() {
|
|||
// arrayToBitmap converts from array format to bitmap format.
|
||||
func (c *container) arrayToBitmap() {
|
||||
c.bitmap = make([]uint64, bitmapN)
|
||||
c.container_type = ContainerBitmap
|
||||
c.containerType = ContainerBitmap
|
||||
|
||||
// return early if empty
|
||||
if c.n == 0 {
|
||||
|
|
@ -1495,7 +1499,7 @@ func (c *container) arrayToBitmap() {
|
|||
// runToBitmap converts from RLE format to bitmap format.
|
||||
func (c *container) runToBitmap() {
|
||||
c.bitmap = make([]uint64, bitmapN)
|
||||
c.container_type = ContainerBitmap
|
||||
c.containerType = ContainerBitmap
|
||||
|
||||
// return early if empty
|
||||
if c.n == 0 {
|
||||
|
|
@ -1517,7 +1521,7 @@ func (c *container) runToBitmap() {
|
|||
|
||||
// bitmapToRun converts from bitmap format to RLE format.
|
||||
func (c *container) bitmapToRun() {
|
||||
c.container_type = ContainerRun
|
||||
c.containerType = ContainerRun
|
||||
// return early if empty
|
||||
if c.n == 0 {
|
||||
c.runs = make([]interval16, 0)
|
||||
|
|
@ -1573,7 +1577,7 @@ func (c *container) bitmapToRun() {
|
|||
|
||||
// arrayToRun converts from array format to RLE format.
|
||||
func (c *container) arrayToRun() {
|
||||
c.container_type = ContainerRun
|
||||
c.containerType = ContainerRun
|
||||
// return early if empty
|
||||
if c.n == 0 {
|
||||
c.runs = make([]interval16, 0)
|
||||
|
|
@ -1600,7 +1604,7 @@ func (c *container) arrayToRun() {
|
|||
|
||||
// runToArray converts from RLE format to array format.
|
||||
func (c *container) runToArray() {
|
||||
c.container_type = ContainerArray
|
||||
c.containerType = ContainerArray
|
||||
c.array = make([]uint16, 0, c.n)
|
||||
|
||||
// return early if empty
|
||||
|
|
@ -1621,9 +1625,9 @@ func (c *container) runToArray() {
|
|||
|
||||
// clone returns a copy of c.
|
||||
func (c *container) clone() *container {
|
||||
other := &container{n: c.n, container_type: c.container_type}
|
||||
other := &container{n: c.n, containerType: c.containerType}
|
||||
|
||||
switch c.container_type {
|
||||
switch c.containerType {
|
||||
case ContainerArray:
|
||||
other.array = make([]uint16, len(c.array))
|
||||
copy(other.array, c.array)
|
||||
|
|
@ -1640,7 +1644,7 @@ func (c *container) clone() *container {
|
|||
// flipBitmap returns a new bitmap containter containing the inverse of all
|
||||
// bits in c.
|
||||
func (c *container) flipBitmap() *container {
|
||||
other := &container{bitmap: make([]uint64, bitmapN), container_type: ContainerBitmap}
|
||||
other := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
|
||||
for i, bitmap := range c.bitmap {
|
||||
other.bitmap[i] = ^bitmap
|
||||
|
|
@ -1918,7 +1922,7 @@ func intersect(a, b *container) *container {
|
|||
}
|
||||
|
||||
func intersectArrayArray(a, b *container) *container {
|
||||
output := &container{container_type: ContainerArray}
|
||||
output := &container{containerType: ContainerArray}
|
||||
na, nb := len(a.array), len(b.array)
|
||||
for i, j := 0, 0; i < na && j < nb; {
|
||||
va, vb := a.array[i], b.array[j]
|
||||
|
|
@ -1939,7 +1943,7 @@ func intersectArrayArray(a, b *container) *container {
|
|||
// container. The return is always an array container (since it's guaranteed to
|
||||
// be low-cardinality)
|
||||
func intersectArrayRun(a, b *container) *container {
|
||||
output := &container{container_type: ContainerArray}
|
||||
output := &container{containerType: ContainerArray}
|
||||
na, nb := len(a.array), len(b.runs)
|
||||
for i, j := 0, 0; i < na && j < nb; {
|
||||
va, vb := a.array[i], b.runs[j]
|
||||
|
|
@ -1958,7 +1962,7 @@ func intersectArrayRun(a, b *container) *container {
|
|||
|
||||
// intersectRunRun computes the intersect of two run containers.
|
||||
func intersectRunRun(a, b *container) *container {
|
||||
output := &container{container_type: ContainerRun}
|
||||
output := &container{containerType: ContainerRun}
|
||||
na, nb := len(a.runs), len(b.runs)
|
||||
for i, j := 0, 0; i < na && j < nb; {
|
||||
va, vb := a.runs[i], b.runs[j]
|
||||
|
|
@ -2000,7 +2004,7 @@ func intersectBitmapRun(a, b *container) *container {
|
|||
var output *container
|
||||
if b.n < ArrayMaxSize {
|
||||
// output is array container
|
||||
output = &container{container_type: ContainerArray}
|
||||
output = &container{containerType: ContainerArray}
|
||||
for _, iv := range b.runs {
|
||||
for i := iv.start; i <= iv.last; i++ {
|
||||
if a.bitmapContains(i) {
|
||||
|
|
@ -2018,8 +2022,8 @@ func intersectBitmapRun(a, b *container) *container {
|
|||
// bitmap that are in the runs. alternately, we could zero out ranges in
|
||||
// the bitmap which are between runs.
|
||||
output = &container{
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
container_type: ContainerBitmap,
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
containerType: ContainerBitmap,
|
||||
}
|
||||
for j := 0; j < len(b.runs); j++ {
|
||||
vb := b.runs[j]
|
||||
|
|
@ -2060,7 +2064,7 @@ func intersectBitmapRun(a, b *container) *container {
|
|||
}
|
||||
|
||||
func intersectArrayBitmap(a, b *container) *container {
|
||||
output := &container{container_type: ContainerArray}
|
||||
output := &container{containerType: ContainerArray}
|
||||
for _, va := range a.array {
|
||||
bmidx := va / 64
|
||||
bidx := va % 64
|
||||
|
|
@ -2075,7 +2079,7 @@ func intersectArrayBitmap(a, b *container) *container {
|
|||
}
|
||||
|
||||
func intersectBitmapBitmap(a, b *container) *container {
|
||||
output := &container{bitmap: make([]uint64, bitmapN), container_type: ContainerBitmap}
|
||||
output := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
|
||||
for i := range a.bitmap {
|
||||
v := a.bitmap[i] & b.bitmap[i]
|
||||
|
|
@ -2116,7 +2120,7 @@ func union(a, b *container) *container {
|
|||
}
|
||||
|
||||
func unionArrayArray(a, b *container) *container {
|
||||
output := &container{container_type: ContainerArray}
|
||||
output := &container{containerType: ContainerArray}
|
||||
na, nb := len(a.array), len(b.array)
|
||||
for i, j := 0, 0; ; {
|
||||
if i >= na && j >= nb {
|
||||
|
|
@ -2152,7 +2156,7 @@ func unionArrayRun(a, b *container) *container {
|
|||
if b.n == maxContainerVal {
|
||||
return b.clone()
|
||||
}
|
||||
output := &container{container_type: ContainerRun}
|
||||
output := &container{containerType: ContainerRun}
|
||||
na, nb := len(a.array), len(b.runs)
|
||||
var vb interval16
|
||||
var va uint16
|
||||
|
|
@ -2189,18 +2193,18 @@ func (c *container) runAppendInterval(v interval16) int {
|
|||
if len(c.runs) == 0 {
|
||||
c.runs = append(c.runs, v)
|
||||
return int(v.last-v.start) + 1
|
||||
} else {
|
||||
last := c.runs[len(c.runs)-1]
|
||||
if last.last == maxContainerVal { //protect against overflow
|
||||
return 0
|
||||
}
|
||||
if last.last+1 >= v.start && v.last > last.last {
|
||||
c.runs[len(c.runs)-1].last = v.last
|
||||
return int(v.last - last.last)
|
||||
} else if last.last+1 < v.start {
|
||||
c.runs = append(c.runs, v)
|
||||
return int(v.last-v.start) + 1
|
||||
}
|
||||
}
|
||||
|
||||
last := c.runs[len(c.runs)-1]
|
||||
if last.last == maxContainerVal { //protect against overflow
|
||||
return 0
|
||||
}
|
||||
if last.last+1 >= v.start && v.last > last.last {
|
||||
c.runs[len(c.runs)-1].last = v.last
|
||||
return int(v.last - last.last)
|
||||
} else if last.last+1 < v.start {
|
||||
c.runs = append(c.runs, v)
|
||||
return int(v.last-v.start) + 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
@ -2214,8 +2218,8 @@ func unionRunRun(a, b *container) *container {
|
|||
}
|
||||
na, nb := len(a.runs), len(b.runs)
|
||||
output := &container{
|
||||
runs: make([]interval16, 0, na+nb),
|
||||
container_type: ContainerRun,
|
||||
runs: make([]interval16, 0, na+nb),
|
||||
containerType: ContainerRun,
|
||||
}
|
||||
var va, vb interval16
|
||||
for i, j := 0, 0; i < na || j < nb; {
|
||||
|
|
@ -2334,8 +2338,8 @@ func unionArrayBitmap(a, b *container) *container {
|
|||
|
||||
func unionBitmapBitmap(a, b *container) *container {
|
||||
output := &container{
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
container_type: ContainerBitmap,
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
containerType: ContainerBitmap,
|
||||
}
|
||||
|
||||
for i := 0; i < bitmapN; i++ {
|
||||
|
|
@ -2377,7 +2381,7 @@ func difference(a, b *container) *container {
|
|||
|
||||
// differenceArrayArray computes the difference bween two arrays.
|
||||
func differenceArrayArray(a, b *container) *container {
|
||||
output := &container{container_type: ContainerArray}
|
||||
output := &container{containerType: ContainerArray}
|
||||
na, nb := len(a.array), len(b.array)
|
||||
for i, j := 0, 0; i < na; {
|
||||
va := a.array[i]
|
||||
|
|
@ -2408,7 +2412,7 @@ func differenceArrayRun(a, b *container) *container {
|
|||
return a.clone()
|
||||
}
|
||||
|
||||
output := &container{array: make([]uint16, 0, a.n), container_type: ContainerArray}
|
||||
output := &container{array: make([]uint16, 0, a.n), containerType: ContainerArray}
|
||||
// cardinality upper bound: card(A)
|
||||
|
||||
i := 0 // array index
|
||||
|
|
@ -2468,7 +2472,7 @@ func differenceRunArray(a, b *container) *container {
|
|||
if a.n == 0 || b.n == 0 {
|
||||
return a.clone()
|
||||
}
|
||||
output := &container{runs: make([]interval16, 0, len(a.runs)), container_type: ContainerRun}
|
||||
output := &container{runs: make([]interval16, 0, len(a.runs)), containerType: ContainerRun}
|
||||
|
||||
bidx := 0
|
||||
vb := b.array[bidx]
|
||||
|
|
@ -2524,7 +2528,7 @@ func differenceRunBitmap(a, b *container) *container {
|
|||
if len(a.runs) > 0 && a.runs[0].start == 0 && a.runs[0].last == 65535 {
|
||||
return b.flipBitmap()
|
||||
}
|
||||
output := &container{container_type: ContainerRun}
|
||||
output := &container{containerType: ContainerRun}
|
||||
output.n = a.n
|
||||
if len(a.runs) == 0 {
|
||||
return output
|
||||
|
|
@ -2577,7 +2581,7 @@ func differenceRunBitmap(a, b *container) *container {
|
|||
|
||||
func differenceRunIterator(a *container, itr containerIterator) *container {
|
||||
|
||||
output := &container{runs: make([]interval16, 0, a.n), container_type: ContainerRun}
|
||||
output := &container{runs: make([]interval16, 0, a.n), containerType: ContainerRun}
|
||||
|
||||
vb, eof := itr.next()
|
||||
j := 0
|
||||
|
|
@ -2645,7 +2649,7 @@ func differenceRunRun(a, b *container) *container {
|
|||
alen := len(a.runs)
|
||||
blen := len(b.runs)
|
||||
|
||||
output := &container{runs: make([]interval16, 0, alen+blen), container_type: ContainerRun} // TODO allocate max then truncate? or something else
|
||||
output := &container{runs: make([]interval16, 0, alen+blen), containerType: ContainerRun} // TODO allocate max then truncate? or something else
|
||||
// cardinality upper bound: sum of number of runs
|
||||
// each B-run could split an A-run in two, up to len(b.runs) times
|
||||
|
||||
|
|
@ -2695,7 +2699,7 @@ func differenceRunRun(a, b *container) *container {
|
|||
}
|
||||
|
||||
func differenceArrayBitmap(a, b *container) *container {
|
||||
output := &container{container_type: ContainerArray}
|
||||
output := &container{containerType: ContainerArray}
|
||||
for _, va := range a.array {
|
||||
bmidx := va / 64
|
||||
bidx := va % 64
|
||||
|
|
@ -2726,7 +2730,7 @@ func differenceBitmapArray(a, b *container) *container {
|
|||
}
|
||||
|
||||
func differenceBitmapBitmap(a, b *container) *container {
|
||||
output := &container{bitmap: make([]uint64, bitmapN), container_type: ContainerBitmap}
|
||||
output := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
|
||||
for i := range a.bitmap {
|
||||
v := a.bitmap[i] & (^b.bitmap[i])
|
||||
|
|
@ -2769,7 +2773,7 @@ func xor(a, b *container) *container {
|
|||
}
|
||||
|
||||
func xorArrayArray(a, b *container) *container {
|
||||
output := &container{container_type: ContainerArray}
|
||||
output := &container{containerType: ContainerArray}
|
||||
na, nb := len(a.array), len(b.array)
|
||||
for i, j := 0, 0; i < na || j < nb; {
|
||||
if i < na && j >= nb {
|
||||
|
|
@ -2816,8 +2820,8 @@ func xorArrayBitmap(a, b *container) *container {
|
|||
|
||||
func xorBitmapBitmap(a, b *container) *container {
|
||||
output := &container{
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
container_type: ContainerBitmap,
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
containerType: ContainerBitmap,
|
||||
}
|
||||
for i := 0; i < bitmapN; i++ {
|
||||
v := a.bitmap[i] ^ b.bitmap[i]
|
||||
|
|
@ -3165,20 +3169,20 @@ func assert(condition bool, format string, a ...interface{}) {
|
|||
|
||||
// xorArrayRun computes the exclusive or of an array and a run container.
|
||||
func xorArrayRun(a, b *container) *container {
|
||||
output := &container{container_type: ContainerRun}
|
||||
output := &container{containerType: ContainerRun}
|
||||
na, nb := len(a.array), len(b.runs)
|
||||
var vb interval16
|
||||
var va uint16
|
||||
last_i, last_j := -1, -1
|
||||
lastI, lastJ := -1, -1
|
||||
for i, j := 0, 0; i < na || j < nb; {
|
||||
if i < na && i != last_i {
|
||||
if i < na && i != lastI {
|
||||
va = a.array[i]
|
||||
}
|
||||
if j < nb && j != last_j {
|
||||
if j < nb && j != lastJ {
|
||||
vb = b.runs[j]
|
||||
}
|
||||
last_i = i
|
||||
last_j = j
|
||||
lastI = i
|
||||
lastJ = j
|
||||
|
||||
if i < na && (j >= nb || va < vb.start) { //before
|
||||
output.n += output.runAppendInterval(interval16{start: va, last: va})
|
||||
|
|
@ -3228,91 +3232,91 @@ func xorArrayRun(a, b *container) *container {
|
|||
}
|
||||
|
||||
// xorCompare computes first exclusive run between two runs.
|
||||
func xorCompare(x *xorstm) (r1 interval16, has_data bool) {
|
||||
has_data = false
|
||||
if !x.va_valid || !x.vb_valid {
|
||||
if x.vb_valid {
|
||||
x.vb_valid = false
|
||||
func xorCompare(x *xorstm) (r1 interval16, hasData bool) {
|
||||
hasData = false
|
||||
if !x.vaValid || !x.vbValid {
|
||||
if x.vbValid {
|
||||
x.vbValid = false
|
||||
r1 = x.vb
|
||||
has_data = true
|
||||
hasData = true
|
||||
return
|
||||
}
|
||||
if x.va_valid {
|
||||
x.va_valid = false
|
||||
if x.vaValid {
|
||||
x.vaValid = false
|
||||
r1 = x.va
|
||||
has_data = true
|
||||
hasData = true
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if x.va.last < x.vb.start { //va before
|
||||
x.va_valid = false
|
||||
x.vaValid = false
|
||||
r1 = x.va
|
||||
has_data = true
|
||||
hasData = true
|
||||
} else if x.vb.last < x.va.start { //vb before
|
||||
x.vb_valid = false
|
||||
x.vbValid = false
|
||||
r1 = x.vb
|
||||
has_data = true
|
||||
hasData = true
|
||||
} else if x.va.start == x.vb.start && x.va.last == x.vb.last { // Equal
|
||||
x.va_valid = false
|
||||
x.vb_valid = false
|
||||
x.vaValid = false
|
||||
x.vbValid = false
|
||||
} else if x.va.start <= x.vb.start && x.va.last >= x.vb.last { //vb inside
|
||||
x.vb_valid = false
|
||||
x.vbValid = false
|
||||
if x.va.start != x.vb.start {
|
||||
r1 = interval16{start: x.va.start, last: x.vb.start - 1}
|
||||
has_data = true
|
||||
hasData = true
|
||||
}
|
||||
|
||||
if x.vb.last == maxContainerVal { // Check for overflow
|
||||
x.va_valid = false
|
||||
x.vaValid = false
|
||||
|
||||
} else {
|
||||
x.va.start = x.vb.last + 1
|
||||
if x.va.start > x.va.last {
|
||||
x.va_valid = false
|
||||
x.vaValid = false
|
||||
}
|
||||
}
|
||||
|
||||
} else if x.vb.start <= x.va.start && x.vb.last >= x.va.last { //va inside
|
||||
x.va_valid = false
|
||||
x.vaValid = false
|
||||
if x.vb.start != x.va.start {
|
||||
r1 = interval16{start: x.vb.start, last: x.va.start - 1}
|
||||
has_data = true
|
||||
hasData = true
|
||||
}
|
||||
|
||||
if x.va.last == maxContainerVal { //check for overflow
|
||||
x.vb_valid = false
|
||||
x.vbValid = false
|
||||
} else {
|
||||
x.vb.start = x.va.last + 1
|
||||
if x.vb.start > x.vb.last {
|
||||
x.vb_valid = false
|
||||
x.vbValid = false
|
||||
}
|
||||
}
|
||||
|
||||
} else if x.va.start < x.vb.start && x.va.last <= x.vb.last { //va first overlap
|
||||
x.va_valid = false
|
||||
x.vaValid = false
|
||||
r1 = interval16{start: x.va.start, last: x.vb.start - 1}
|
||||
has_data = true
|
||||
hasData = true
|
||||
if x.va.last == maxContainerVal { // check for overflow
|
||||
x.vb_valid = false
|
||||
x.vbValid = false
|
||||
} else {
|
||||
x.vb.start = x.va.last + 1
|
||||
if x.vb.start > x.vb.last {
|
||||
x.vb_valid = false
|
||||
x.vbValid = false
|
||||
}
|
||||
}
|
||||
} else if x.vb.start < x.va.start && x.vb.last <= x.va.last { //vb first overlap
|
||||
x.vb_valid = false
|
||||
x.vbValid = false
|
||||
r1 = interval16{start: x.vb.start, last: x.va.start - 1}
|
||||
has_data = true
|
||||
hasData = true
|
||||
|
||||
if x.vb.last == maxContainerVal { // check for overflow
|
||||
x.va_valid = false
|
||||
x.vaValid = false
|
||||
} else {
|
||||
x.va.start = x.vb.last + 1
|
||||
if x.va.start > x.va.last {
|
||||
x.va_valid = false
|
||||
x.vaValid = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3321,8 +3325,8 @@ func xorCompare(x *xorstm) (r1 interval16, has_data bool) {
|
|||
|
||||
//stm is state machine used to "xor" iterate over runs.
|
||||
type xorstm struct {
|
||||
va_valid, vb_valid bool
|
||||
va, vb interval16
|
||||
vaValid, vbValid bool
|
||||
va, vb interval16
|
||||
}
|
||||
|
||||
// xorRunRun computes the exclusive or of two run containers.
|
||||
|
|
@ -3336,30 +3340,30 @@ func xorRunRun(a, b *container) *container {
|
|||
}
|
||||
output := &container{}
|
||||
|
||||
last_i, last_j := -1, -1
|
||||
lastI, lastJ := -1, -1
|
||||
|
||||
state := &xorstm{}
|
||||
|
||||
for i, j := 0, 0; i < na || j < nb; {
|
||||
if i < na && last_i != i {
|
||||
if i < na && lastI != i {
|
||||
state.va = a.runs[i]
|
||||
state.va_valid = true
|
||||
state.vaValid = true
|
||||
}
|
||||
|
||||
if j < nb && last_j != j {
|
||||
if j < nb && lastJ != j {
|
||||
state.vb = b.runs[j]
|
||||
state.vb_valid = true
|
||||
state.vbValid = true
|
||||
}
|
||||
last_i, last_j = i, j
|
||||
lastI, lastJ = i, j
|
||||
|
||||
r1, ok := xorCompare(state)
|
||||
if ok {
|
||||
output.n += output.runAppendInterval(r1)
|
||||
}
|
||||
if !state.va_valid {
|
||||
if !state.vaValid {
|
||||
i++
|
||||
}
|
||||
if !state.vb_valid {
|
||||
if !state.vbValid {
|
||||
j++
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@ func (iv interval16) String() string {
|
|||
}
|
||||
|
||||
func (c *container) String() string {
|
||||
return fmt.Sprintf("<%s container n=%d, array[%d], runs[%d], bitmap[%d]> type:%d", c.info().Type, c.n, len(c.array), len(c.runs), len(c.bitmap), c.container_type)
|
||||
return fmt.Sprintf("<%s container n=%d, array[%d], runs[%d], bitmap[%d]> type:%d", c.info().Type, c.n, len(c.array), len(c.runs), len(c.bitmap), c.containerType)
|
||||
}
|
||||
|
||||
func TestRunAppendInterval(t *testing.T) {
|
||||
a := container{container_type: ContainerRun}
|
||||
a := container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
base []interval16
|
||||
app interval16
|
||||
|
|
@ -80,7 +80,7 @@ func TestInterval16RunLen(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContainerRunAdd(t *testing.T) {
|
||||
c := container{runs: make([]interval16, 0), container_type: ContainerRun}
|
||||
c := container{runs: make([]interval16, 0), containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
op uint16
|
||||
exp []interval16
|
||||
|
|
@ -111,7 +111,7 @@ func TestContainerRunAdd(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContainerRunAdd2(t *testing.T) {
|
||||
c := container{runs: make([]interval16, 0), container_type: ContainerRun}
|
||||
c := container{runs: make([]interval16, 0), containerType: ContainerRun}
|
||||
ret := c.add(0)
|
||||
if !ret {
|
||||
t.Fatalf("result of adding new bit should be true: %v", c.runs)
|
||||
|
|
@ -126,7 +126,7 @@ func TestContainerRunAdd2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunCountRange(t *testing.T) {
|
||||
c := container{runs: make([]interval16, 0), container_type: ContainerRun}
|
||||
c := container{runs: make([]interval16, 0), containerType: ContainerRun}
|
||||
cnt := c.runCountRange(2, 9)
|
||||
if cnt != 0 {
|
||||
t.Fatalf("should get 0 from empty container, but got: %v", cnt)
|
||||
|
|
@ -179,7 +179,7 @@ func TestRunCountRange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunContains(t *testing.T) {
|
||||
c := container{runs: make([]interval16, 0), container_type: ContainerRun}
|
||||
c := container{runs: make([]interval16, 0), containerType: ContainerRun}
|
||||
if c.runContains(5) {
|
||||
t.Fatalf("empty run container should not contain 5")
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ func TestRunContains(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapCountRange(t *testing.T) {
|
||||
c := container{container_type: ContainerBitmap}
|
||||
c := container{containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
start int
|
||||
end int
|
||||
|
|
@ -227,11 +227,11 @@ func TestBitmapCountRange(t *testing.T) {
|
|||
|
||||
func TestIntersectionCountArrayBitmap3(t *testing.T) {
|
||||
a, b := &container{}, &container{}
|
||||
a.container_type = ContainerBitmap
|
||||
a.containerType = ContainerBitmap
|
||||
a.bitmap = getFullBitmap()
|
||||
a.n = maxContainerVal + 1
|
||||
|
||||
b.container_type = ContainerBitmap
|
||||
b.containerType = ContainerBitmap
|
||||
b.bitmap = getFullBitmap()
|
||||
b.n = maxContainerVal + 1
|
||||
res := intersectBitmapBitmap(a, b)
|
||||
|
|
@ -288,9 +288,9 @@ func TestIntersectionCountArrayBitmap2(t *testing.T) {
|
|||
|
||||
for i, test := range tests {
|
||||
a.array = test.array
|
||||
a.container_type = ContainerArray
|
||||
a.containerType = ContainerArray
|
||||
b.bitmap = test.bitmap
|
||||
b.container_type = ContainerBitmap
|
||||
b.containerType = ContainerBitmap
|
||||
ret := intersectionCountArrayBitmap(a, b)
|
||||
if ret != test.exp {
|
||||
t.Fatalf("test #%v intersectCountArrayBitmap fail received: %v exp: %v", i, ret, test.exp)
|
||||
|
|
@ -299,7 +299,7 @@ func TestIntersectionCountArrayBitmap2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunRemove(t *testing.T) {
|
||||
c := container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, container_type: ContainerRun}
|
||||
c := container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
op uint16
|
||||
exp []interval16
|
||||
|
|
@ -333,7 +333,7 @@ func TestRunRemove(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunMax(t *testing.T) {
|
||||
c := container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, container_type: ContainerRun}
|
||||
c := container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: ContainerRun}
|
||||
max := c.max()
|
||||
if max != 16 {
|
||||
t.Fatalf("max for %v should be 16", c.runs)
|
||||
|
|
@ -347,8 +347,8 @@ func TestRunMax(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectionCountArrayRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerArray, array: []uint16{1, 5, 10, 11, 12}}
|
||||
b := &container{container_type: ContainerRun, runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}}
|
||||
a := &container{containerType: ContainerArray, array: []uint16{1, 5, 10, 11, 12}}
|
||||
b := &container{containerType: ContainerRun, runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}}
|
||||
|
||||
ret := intersectionCountArrayRun(a, b)
|
||||
if ret != 3 {
|
||||
|
|
@ -357,16 +357,16 @@ func TestIntersectionCountArrayRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectionCountBitmapRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerBitmap, bitmap: []uint64{0x8000000000000000}}
|
||||
b := &container{container_type: ContainerRun, runs: []interval16{{start: 63, last: 64}}}
|
||||
a := &container{containerType: ContainerBitmap, bitmap: []uint64{0x8000000000000000}}
|
||||
b := &container{containerType: ContainerRun, runs: []interval16{{start: 63, last: 64}}}
|
||||
|
||||
ret := intersectionCountBitmapRun(a, b)
|
||||
if ret != 1 {
|
||||
t.Fatalf("count of %v with %v should be 1, but got %v", a.bitmap, b.runs, ret)
|
||||
}
|
||||
|
||||
a = &container{container_type: ContainerBitmap, bitmap: []uint64{0xF0000001, 0xFF00000000000000, 0xFF000000000000F0, 0x0F0000}}
|
||||
b = &container{container_type: ContainerRun, runs: []interval16{{start: 29, last: 31}, {start: 125, last: 134}, {start: 191, last: 197}, {start: 200, last: 300}}}
|
||||
a = &container{containerType: ContainerBitmap, bitmap: []uint64{0xF0000001, 0xFF00000000000000, 0xFF000000000000F0, 0x0F0000}}
|
||||
b = &container{containerType: ContainerRun, runs: []interval16{{start: 29, last: 31}, {start: 125, last: 134}, {start: 191, last: 197}, {start: 200, last: 300}}}
|
||||
|
||||
ret = intersectionCountBitmapRun(a, b)
|
||||
if ret != 14 {
|
||||
|
|
@ -414,8 +414,8 @@ func TestIntersectionCountRunRun(t *testing.T) {
|
|||
bruns: []interval16{{start: 9, last: 9}, {start: 11, last: 17}}, exp: 6},
|
||||
}
|
||||
for i, test := range tests {
|
||||
a.container_type = ContainerRun
|
||||
b.container_type = ContainerRun
|
||||
a.containerType = ContainerRun
|
||||
b.containerType = ContainerRun
|
||||
a.runs = test.aruns
|
||||
b.runs = test.bruns
|
||||
ret := intersectionCountRunRun(a, b)
|
||||
|
|
@ -456,8 +456,8 @@ func TestIntersectArrayRun(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, test := range tests {
|
||||
a.container_type = ContainerArray
|
||||
b.container_type = ContainerRun
|
||||
a.containerType = ContainerArray
|
||||
b.containerType = ContainerRun
|
||||
a.array = test.array
|
||||
b.runs = test.runs
|
||||
ret := intersectArrayRun(a, b)
|
||||
|
|
@ -514,8 +514,8 @@ func TestIntersectRunRun(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for i, test := range tests {
|
||||
a.container_type = ContainerRun
|
||||
b.container_type = ContainerRun
|
||||
a.containerType = ContainerRun
|
||||
b.containerType = ContainerRun
|
||||
a.runs = test.aruns
|
||||
b.runs = test.bruns
|
||||
ret := intersectRunRun(a, b)
|
||||
|
|
@ -579,8 +579,8 @@ func TestIntersectBitmapRunBitmap(t *testing.T) {
|
|||
for i, v := range test.exp {
|
||||
exp[i] = v
|
||||
}
|
||||
a.container_type = ContainerBitmap
|
||||
b.container_type = ContainerRun
|
||||
a.containerType = ContainerBitmap
|
||||
b.containerType = ContainerRun
|
||||
ret := intersectBitmapRun(a, b)
|
||||
if ret.isArray() {
|
||||
ret.arrayToBitmap()
|
||||
|
|
@ -640,8 +640,8 @@ func TestIntersectBitmapRunArray(t *testing.T) {
|
|||
a.bitmap[i] = v
|
||||
}
|
||||
b.runs = test.runs
|
||||
a.container_type = ContainerBitmap
|
||||
b.container_type = ContainerRun
|
||||
a.containerType = ContainerBitmap
|
||||
b.containerType = ContainerRun
|
||||
ret := intersectBitmapRun(a, b)
|
||||
if !reflect.DeepEqual(ret.array, test.exp) {
|
||||
t.Fatalf("test #%v expected %v, but got %v", i, test.exp, ret.array)
|
||||
|
|
@ -658,19 +658,19 @@ func TestUnionMixed(t *testing.T) {
|
|||
// array container
|
||||
a := &container{}
|
||||
a.array = []uint16{1, 4, 5, 7, 10, 11, 12}
|
||||
a.container_type = ContainerArray
|
||||
a.containerType = ContainerArray
|
||||
a.n = 7
|
||||
|
||||
// bitmap container
|
||||
b := &container{bitmap: make([]uint64, bitmapN)}
|
||||
b.bitmap[0] = uint64(0x3)
|
||||
b.n = 2
|
||||
b.container_type = ContainerBitmap
|
||||
b.containerType = ContainerBitmap
|
||||
|
||||
// run container
|
||||
r := &container{}
|
||||
r.runs = []interval16{{start: 5, last: 10}}
|
||||
r.container_type = ContainerRun
|
||||
r.containerType = ContainerRun
|
||||
r.n = 6
|
||||
|
||||
t.Run("various container Unions", func(t *testing.T) {
|
||||
|
|
@ -711,10 +711,10 @@ func TestIntersectMixed(t *testing.T) {
|
|||
|
||||
a.runs = []interval16{{start: 5, last: 10}}
|
||||
a.n = 6
|
||||
a.container_type = ContainerRun
|
||||
a.containerType = ContainerRun
|
||||
b.array = []uint16{1, 4, 5, 7, 10, 11, 12}
|
||||
b.n = 7
|
||||
b.container_type = ContainerArray
|
||||
b.containerType = ContainerArray
|
||||
res := intersect(a, b)
|
||||
if !reflect.DeepEqual(res.array, []uint16{5, 7, 10}) {
|
||||
t.Fatalf("test #1 expected %v, but got %v", []uint16{5, 7, 10}, res.array)
|
||||
|
|
@ -730,7 +730,7 @@ func TestIntersectMixed(t *testing.T) {
|
|||
}
|
||||
c.bitmap = []uint64{0x60}
|
||||
c.n = 2
|
||||
c.container_type = ContainerBitmap
|
||||
c.containerType = ContainerBitmap
|
||||
|
||||
res = intersect(c, a)
|
||||
if !reflect.DeepEqual(res.array, []uint16{5, 6}) {
|
||||
|
|
@ -760,15 +760,15 @@ func TestDifferenceMixed(t *testing.T) {
|
|||
|
||||
a.runs = []interval16{{start: 5, last: 10}}
|
||||
a.n = a.runCountRange(0, 100)
|
||||
a.container_type = ContainerRun
|
||||
a.containerType = ContainerRun
|
||||
|
||||
b.array = []uint16{0, 2, 4, 6, 8, 10, 12}
|
||||
b.n = len(b.array)
|
||||
b.container_type = ContainerArray
|
||||
b.containerType = ContainerArray
|
||||
|
||||
d.array = []uint16{1, 3, 5, 7, 9, 11, 12}
|
||||
d.n = len(d.array)
|
||||
d.container_type = ContainerArray
|
||||
d.containerType = ContainerArray
|
||||
|
||||
res := difference(a, b)
|
||||
|
||||
|
|
@ -788,7 +788,7 @@ func TestDifferenceMixed(t *testing.T) {
|
|||
|
||||
c.bitmap = []uint64{0x64}
|
||||
c.n = c.countRange(0, 100)
|
||||
c.container_type = ContainerBitmap
|
||||
c.containerType = ContainerBitmap
|
||||
res = difference(c, a)
|
||||
if !reflect.DeepEqual(res.bitmap, []uint64{0x4}) {
|
||||
t.Fatalf("test #4 expected %v, but got %v", []uint16{4}, res.bitmap)
|
||||
|
|
@ -883,8 +883,8 @@ func TestUnionRunRun(t *testing.T) {
|
|||
for i, test := range tests {
|
||||
a.runs = test.aruns
|
||||
b.runs = test.bruns
|
||||
a.container_type = ContainerRun
|
||||
b.container_type = ContainerRun
|
||||
a.containerType = ContainerRun
|
||||
b.containerType = ContainerRun
|
||||
ret := unionRunRun(a, b)
|
||||
if !reflect.DeepEqual(ret.runs, test.exp) {
|
||||
t.Fatalf("test #%v expected %v, but got %v", i, test.exp, ret.runs)
|
||||
|
|
@ -925,8 +925,8 @@ func TestUnionArrayRun(t *testing.T) {
|
|||
for i, test := range tests {
|
||||
a.array = test.array
|
||||
b.runs = test.runs
|
||||
a.container_type = ContainerArray
|
||||
b.container_type = ContainerRun
|
||||
a.containerType = ContainerArray
|
||||
b.containerType = ContainerRun
|
||||
ret := unionArrayRun(a, b)
|
||||
if !reflect.DeepEqual(ret.array, test.exp) {
|
||||
t.Fatalf("test #%v expected %v, but got %v", i, test.exp, ret.array)
|
||||
|
|
@ -935,7 +935,7 @@ func TestUnionArrayRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapSetRange(t *testing.T) {
|
||||
c := &container{container_type: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
c := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
start uint64
|
||||
|
|
@ -975,7 +975,7 @@ func TestBitmapSetRange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestArrayToBitmap(t *testing.T) {
|
||||
a := &container{container_type: ContainerArray}
|
||||
a := &container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
exp []uint64
|
||||
|
|
@ -1006,7 +1006,7 @@ func TestArrayToBitmap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapToArray(t *testing.T) {
|
||||
a := &container{container_type: ContainerBitmap}
|
||||
a := &container{containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
exp []uint16
|
||||
|
|
@ -1037,7 +1037,7 @@ func TestBitmapToArray(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunToBitmap(t *testing.T) {
|
||||
a := &container{container_type: ContainerRun}
|
||||
a := &container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
runs []interval16
|
||||
exp []uint64
|
||||
|
|
@ -1091,7 +1091,7 @@ func getFullBitmap() []uint64 {
|
|||
}
|
||||
|
||||
func TestBitmapToRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerBitmap}
|
||||
a := &container{containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
exp []interval16
|
||||
|
|
@ -1169,7 +1169,7 @@ func TestBitmapToRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestArrayToRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerArray}
|
||||
a := &container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
exp []interval16
|
||||
|
|
@ -1203,7 +1203,7 @@ func TestArrayToRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunToArray(t *testing.T) {
|
||||
a := &container{container_type: ContainerRun}
|
||||
a := &container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
runs []interval16
|
||||
exp []uint16
|
||||
|
|
@ -1237,7 +1237,7 @@ func TestRunToArray(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapZeroRange(t *testing.T) {
|
||||
c := &container{container_type: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
c := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
start uint64
|
||||
|
|
@ -1273,7 +1273,7 @@ func TestBitmapZeroRange(t *testing.T) {
|
|||
if test.expN != c.n {
|
||||
t.Fatalf("test #%v expected n to be %v, but got %v", i, test.expN, c.n)
|
||||
}
|
||||
for i, _ := range test.bitmap {
|
||||
for i := range test.bitmap {
|
||||
c.bitmap[i] = 0
|
||||
}
|
||||
}
|
||||
|
|
@ -1281,8 +1281,8 @@ func TestBitmapZeroRange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUnionBitmapRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
b := &container{container_type: ContainerRun}
|
||||
a := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
b := &container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
runs []interval16
|
||||
|
|
@ -1313,14 +1313,14 @@ func TestUnionBitmapRun(t *testing.T) {
|
|||
if ret.n != test.expN {
|
||||
t.Fatalf("test #%v expected n to be %v, but got %v", i, test.expN, ret.n)
|
||||
}
|
||||
for i, _ := range test.bitmap {
|
||||
for i := range test.bitmap {
|
||||
a.bitmap[i] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBitmapCountRuns(t *testing.T) {
|
||||
c := &container{container_type: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
c := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
exp int
|
||||
|
|
@ -1353,7 +1353,7 @@ func TestBitmapCountRuns(t *testing.T) {
|
|||
t.Fatalf("test #%v expected %v but got %v", i, test.exp, ret)
|
||||
}
|
||||
|
||||
for j, _ := range test.bitmap {
|
||||
for j := range test.bitmap {
|
||||
c.bitmap[j] = 0
|
||||
}
|
||||
}
|
||||
|
|
@ -1370,7 +1370,7 @@ func TestBitmapCountRuns(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestArrayCountRuns(t *testing.T) {
|
||||
c := &container{container_type: ContainerArray}
|
||||
c := &container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
exp int
|
||||
|
|
@ -1411,8 +1411,8 @@ func TestArrayCountRuns(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceArrayRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerArray}
|
||||
b := &container{container_type: ContainerRun}
|
||||
a := &container{containerType: ContainerArray}
|
||||
b := &container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
runs []interval16
|
||||
|
|
@ -1437,8 +1437,8 @@ func TestDifferenceArrayRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceRunArray(t *testing.T) {
|
||||
a := &container{container_type: ContainerRun}
|
||||
b := &container{container_type: ContainerArray}
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
runs []interval16
|
||||
array []uint16
|
||||
|
|
@ -1518,8 +1518,8 @@ func MakeLastBitSet() []uint64 {
|
|||
}
|
||||
|
||||
func TestDifferenceRunBitmap(t *testing.T) {
|
||||
a := &container{container_type: ContainerRun}
|
||||
b := &container{container_type: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
tests := []struct {
|
||||
runs []interval16
|
||||
bitmap []uint64
|
||||
|
|
@ -1581,8 +1581,8 @@ func TestDifferenceRunBitmap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceBitmapRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
b := &container{container_type: ContainerRun}
|
||||
a := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
b := &container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
runs []interval16
|
||||
|
|
@ -1664,8 +1664,8 @@ func TestDifferenceBitmapRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceBitmapArray(t *testing.T) {
|
||||
b := &container{container_type: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
a := &container{container_type: ContainerArray}
|
||||
b := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
a := &container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
array []uint16
|
||||
|
|
@ -1714,8 +1714,8 @@ func TestDifferenceBitmapArray(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceBitmapBitmap(t *testing.T) {
|
||||
a := &container{bitmap: make([]uint64, bitmapN), container_type: ContainerBitmap}
|
||||
b := &container{bitmap: make([]uint64, bitmapN), container_type: ContainerBitmap}
|
||||
a := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
b := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
abitmap []uint64
|
||||
bbitmap []uint64
|
||||
|
|
@ -1744,8 +1744,8 @@ func TestDifferenceBitmapBitmap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceRunRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerRun}
|
||||
b := &container{container_type: ContainerRun}
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
aruns []interval16
|
||||
bruns []interval16
|
||||
|
|
@ -1778,7 +1778,7 @@ func TestDifferenceRunRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWriteReadArray(t *testing.T) {
|
||||
ca := &container{array: []uint16{1, 10, 100, 1000}, n: 4, container_type: ContainerArray}
|
||||
ca := &container{array: []uint16{1, 10, 100, 1000}, n: 4, containerType: ContainerArray}
|
||||
ba := &Bitmap{keys: []uint64{0}, containers: []*container{ca}}
|
||||
ba2 := &Bitmap{}
|
||||
var buf bytes.Buffer
|
||||
|
|
@ -1797,7 +1797,7 @@ func TestWriteReadArray(t *testing.T) {
|
|||
|
||||
func TestWriteReadBitmap(t *testing.T) {
|
||||
// create bitmap containing > 4096 bits
|
||||
cb := &container{bitmap: make([]uint64, bitmapN), n: 129 * 32, container_type: ContainerBitmap}
|
||||
cb := &container{bitmap: make([]uint64, bitmapN), n: 129 * 32, containerType: ContainerBitmap}
|
||||
for i := 0; i < 129; i++ {
|
||||
cb.bitmap[i] = 0x5555555555555555
|
||||
}
|
||||
|
|
@ -1819,7 +1819,7 @@ func TestWriteReadBitmap(t *testing.T) {
|
|||
|
||||
func TestWriteReadFullBitmap(t *testing.T) {
|
||||
// create bitmap containing > 4096 bits
|
||||
cb := &container{bitmap: make([]uint64, bitmapN), n: 65536, container_type: ContainerBitmap}
|
||||
cb := &container{bitmap: make([]uint64, bitmapN), n: 65536, containerType: ContainerBitmap}
|
||||
for i := 0; i < bitmapN; i++ {
|
||||
cb.bitmap[i] = 0xffffffffffffffff
|
||||
}
|
||||
|
|
@ -1847,7 +1847,7 @@ func TestWriteReadFullBitmap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWriteReadRun(t *testing.T) {
|
||||
cr := &container{runs: []interval16{{start: 3, last: 13}, {start: 100, last: 109}}, n: 21, container_type: ContainerRun}
|
||||
cr := &container{runs: []interval16{{start: 3, last: 13}, {start: 100, last: 109}}, n: 21, containerType: ContainerRun}
|
||||
br := &Bitmap{keys: []uint64{0}, containers: []*container{cr}}
|
||||
br2 := &Bitmap{}
|
||||
var buf bytes.Buffer
|
||||
|
|
@ -1871,21 +1871,21 @@ func TestXorArrayRun(t *testing.T) {
|
|||
exp *container
|
||||
}{
|
||||
{
|
||||
a: &container{array: []uint16{1, 5, 10, 11, 12}, container_type: ContainerArray},
|
||||
b: &container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, container_type: ContainerRun},
|
||||
exp: &container{array: []uint16{1, 2, 3, 4, 6, 7, 8, 9, 11, 13, 15, 16}, container_type: ContainerArray, n: 12},
|
||||
a: &container{array: []uint16{1, 5, 10, 11, 12}, containerType: ContainerArray},
|
||||
b: &container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: ContainerRun},
|
||||
exp: &container{array: []uint16{1, 2, 3, 4, 6, 7, 8, 9, 11, 13, 15, 16}, containerType: ContainerArray, n: 12},
|
||||
}, {
|
||||
a: &container{array: []uint16{1, 5, 10, 11, 12, 13, 14}, container_type: ContainerArray},
|
||||
b: &container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, container_type: ContainerRun},
|
||||
exp: &container{array: []uint16{1, 2, 3, 4, 6, 7, 8, 9, 11, 14, 15, 16}, container_type: ContainerArray, n: 12},
|
||||
a: &container{array: []uint16{1, 5, 10, 11, 12, 13, 14}, containerType: ContainerArray},
|
||||
b: &container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: ContainerRun},
|
||||
exp: &container{array: []uint16{1, 2, 3, 4, 6, 7, 8, 9, 11, 14, 15, 16}, containerType: ContainerArray, n: 12},
|
||||
}, {
|
||||
a: &container{array: []uint16{65535}, container_type: ContainerArray},
|
||||
b: &container{runs: []interval16{{start: 65534, last: 65535}}, container_type: ContainerRun},
|
||||
exp: &container{array: []uint16{65534}, container_type: ContainerArray, n: 1},
|
||||
a: &container{array: []uint16{65535}, containerType: ContainerArray},
|
||||
b: &container{runs: []interval16{{start: 65534, last: 65535}}, containerType: ContainerRun},
|
||||
exp: &container{array: []uint16{65534}, containerType: ContainerArray, n: 1},
|
||||
}, {
|
||||
a: &container{array: []uint16{65535}, container_type: ContainerArray},
|
||||
b: &container{runs: []interval16{{start: 65535, last: 65535}}, container_type: ContainerRun},
|
||||
exp: &container{array: []uint16{}, container_type: ContainerArray, n: 0},
|
||||
a: &container{array: []uint16{65535}, containerType: ContainerArray},
|
||||
b: &container{runs: []interval16{{start: 65535, last: 65535}}, containerType: ContainerRun},
|
||||
exp: &container{array: []uint16{}, containerType: ContainerArray, n: 0},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -1906,8 +1906,8 @@ func TestXorArrayRun(t *testing.T) {
|
|||
|
||||
//special case that didn't fit the xorrunrun table testing below.
|
||||
func TestXorRunRun1(t *testing.T) {
|
||||
a := &container{container_type: ContainerRun}
|
||||
b := &container{container_type: ContainerRun}
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: ContainerRun}
|
||||
a.runs = []interval16{{start: 4, last: 10}}
|
||||
b.runs = []interval16{{start: 5, last: 10}}
|
||||
ret := xorRunRun(a, b)
|
||||
|
|
@ -1921,8 +1921,8 @@ func TestXorRunRun1(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestXorRunRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerRun}
|
||||
b := &container{container_type: ContainerRun}
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
aruns []interval16
|
||||
bruns []interval16
|
||||
|
|
@ -2019,7 +2019,7 @@ func TestXorRunRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapFlip(t *testing.T) {
|
||||
c := &container{bitmap: make([]uint64, bitmapN), container_type: ContainerBitmap}
|
||||
c := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
|
||||
ttable := []struct {
|
||||
original uint64
|
||||
|
|
@ -2051,7 +2051,7 @@ func TestBitmapFlip(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapXorRange(t *testing.T) {
|
||||
c := &container{bitmap: make([]uint64, bitmapN), container_type: ContainerBitmap}
|
||||
c := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
start uint64
|
||||
|
|
@ -2119,8 +2119,8 @@ func TestBitmapXorRange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestXorBitmapRun(t *testing.T) {
|
||||
a := &container{container_type: ContainerBitmap}
|
||||
b := &container{container_type: ContainerRun}
|
||||
a := &container{containerType: ContainerBitmap}
|
||||
b := &container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
runs []interval16
|
||||
|
|
@ -2631,9 +2631,9 @@ func TestSearch64(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectArrayBitmap(t *testing.T) {
|
||||
a, b := &container{container_type: ContainerArray}, &container{
|
||||
container_type: ContainerBitmap,
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
a, b := &container{containerType: ContainerArray}, &container{
|
||||
containerType: ContainerBitmap,
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
|
|
@ -2679,11 +2679,11 @@ func TestIntersectArrayBitmap(t *testing.T) {
|
|||
|
||||
for i, test := range tests {
|
||||
a.array = test.array
|
||||
a.container_type = ContainerArray
|
||||
a.containerType = ContainerArray
|
||||
for i, bmval := range test.bitmap {
|
||||
b.bitmap[i] = bmval
|
||||
}
|
||||
b.container_type = ContainerBitmap
|
||||
b.containerType = ContainerBitmap
|
||||
ret := intersectArrayBitmap(a, b).array
|
||||
if len(ret) == 0 && len(test.exp) == 0 {
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue