mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-10 23:11:01 +00:00
Rename (export) container -> Container
This commit is contained in:
parent
2590b25628
commit
4014f22802
7 changed files with 275 additions and 276 deletions
|
|
@ -93,7 +93,7 @@ type (
|
|||
|
||||
de struct { // d element
|
||||
k uint64
|
||||
v *container
|
||||
v *Container
|
||||
}
|
||||
|
||||
// Enumerator captures the state of enumerating a tree. It is returned
|
||||
|
|
@ -417,7 +417,7 @@ func (t *Tree) find(q interface{}, k uint64) (i int, ok bool) {
|
|||
|
||||
// First returns the first item of the tree in the key collating order, or
|
||||
// (zero-value, zero-value) if the tree is empty.
|
||||
func (t *Tree) First() (k uint64, v *container) {
|
||||
func (t *Tree) First() (k uint64, v *Container) {
|
||||
if q := t.first; q != nil {
|
||||
q := &q.d[0]
|
||||
k, v = q.k, q.v
|
||||
|
|
@ -427,7 +427,7 @@ func (t *Tree) First() (k uint64, v *container) {
|
|||
|
||||
// Get returns the value associated with k and true if it exists. Otherwise Get
|
||||
// returns (zero-value, false).
|
||||
func (t *Tree) Get(k uint64) (v *container, ok bool) {
|
||||
func (t *Tree) Get(k uint64) (v *Container, ok bool) {
|
||||
q := t.r
|
||||
if q == nil {
|
||||
return
|
||||
|
|
@ -453,7 +453,7 @@ func (t *Tree) Get(k uint64) (v *container, ok bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func (t *Tree) insert(q *d, i int, k uint64, v *container) *d {
|
||||
func (t *Tree) insert(q *d, i int, k uint64, v *Container) *d {
|
||||
t.ver++
|
||||
c := q.c
|
||||
if i < c {
|
||||
|
|
@ -468,7 +468,7 @@ func (t *Tree) insert(q *d, i int, k uint64, v *container) *d {
|
|||
|
||||
// Last returns the last item of the tree in the key collating order, or
|
||||
// (zero-value, zero-value) if the tree is empty.
|
||||
func (t *Tree) Last() (k uint64, v *container) {
|
||||
func (t *Tree) Last() (k uint64, v *Container) {
|
||||
if q := t.last; q != nil {
|
||||
q := &q.d[q.c-1]
|
||||
k, v = q.k, q.v
|
||||
|
|
@ -481,7 +481,7 @@ func (t *Tree) Len() int {
|
|||
return t.c
|
||||
}
|
||||
|
||||
func (t *Tree) overflow(p *x, q *d, pi, i int, k uint64, v *container) {
|
||||
func (t *Tree) overflow(p *x, q *d, pi, i int, k uint64, v *Container) {
|
||||
t.ver++
|
||||
l, r := p.siblings(pi)
|
||||
|
||||
|
|
@ -577,7 +577,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
|
|||
}
|
||||
|
||||
// Set sets the value associated with k.
|
||||
func (t *Tree) Set(k uint64, v *container) {
|
||||
func (t *Tree) Set(k uint64, v *Container) {
|
||||
//dbg("--- PRE Set(%v, %v)\n%s", k, v, t.dump())
|
||||
//defer func() {
|
||||
// dbg("--- POST\n%s\n====\n", t.dump())
|
||||
|
|
@ -643,11 +643,11 @@ func (t *Tree) Set(k uint64, v *container) {
|
|||
// tree.Put(k, func(uint64, bool){ return v, true })
|
||||
//
|
||||
// modulo the differing return values.
|
||||
func (t *Tree) Put(k uint64, upd func(oldV *container, exists bool) (newV *container, write bool)) (oldV *container, written bool) {
|
||||
func (t *Tree) Put(k uint64, upd func(oldV *Container, exists bool) (newV *Container, write bool)) (oldV *Container, written bool) {
|
||||
pi := -1
|
||||
var p *x
|
||||
q := t.r
|
||||
var newV *container
|
||||
var newV *Container
|
||||
if q == nil {
|
||||
// new KV pair in empty tree
|
||||
newV, written = upd(newV, false)
|
||||
|
|
@ -710,7 +710,7 @@ func (t *Tree) Put(k uint64, upd func(oldV *container, exists bool) (newV *conta
|
|||
}
|
||||
}
|
||||
|
||||
func (t *Tree) split(p *x, q *d, pi, i int, k uint64, v *container) {
|
||||
func (t *Tree) split(p *x, q *d, pi, i int, k uint64, v *Container) {
|
||||
t.ver++
|
||||
r := btDPool.Get().(*d)
|
||||
if q.n != nil {
|
||||
|
|
@ -856,7 +856,7 @@ func (e *Enumerator) Close() {
|
|||
// Next returns the currently enumerated item, if it exists and moves to the
|
||||
// next item in the key collation order. If there is no item to return, err ==
|
||||
// io.EOF is returned.
|
||||
func (e *Enumerator) Next() (k uint64, v *container, err error) {
|
||||
func (e *Enumerator) Next() (k uint64, v *Container, err error) {
|
||||
if err = e.err; err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -904,7 +904,7 @@ func (e *Enumerator) next() error {
|
|||
// Prev returns the currently enumerated item, if it exists and moves to the
|
||||
// previous item in the key collation order. If there is no item to return, err
|
||||
// == io.EOF is returned.
|
||||
func (e *Enumerator) Prev() (k uint64, v *container, err error) {
|
||||
func (e *Enumerator) Prev() (k uint64, v *Container, err error) {
|
||||
if err = e.err; err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,16 +18,16 @@ type BTreeContainers struct {
|
|||
tree *Tree
|
||||
|
||||
lastKey uint64
|
||||
lastContainer *container
|
||||
lastContainer *Container
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) Get(key uint64) *container {
|
||||
func (btc *BTreeContainers) Get(key uint64) *Container {
|
||||
// Check the last* cache for same container.
|
||||
if key == btc.lastKey && btc.lastContainer != nil {
|
||||
return btc.lastContainer
|
||||
}
|
||||
|
||||
var c *container
|
||||
var c *Container
|
||||
el, ok := btc.tree.Get(key)
|
||||
if ok {
|
||||
c = el
|
||||
|
|
@ -37,7 +37,7 @@ func (btc *BTreeContainers) Get(key uint64) *container {
|
|||
return c
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) Put(key uint64, c *container) {
|
||||
func (btc *BTreeContainers) Put(key uint64, c *Container) {
|
||||
// If a mapped container is added to the tree, reset the
|
||||
// lastContainer cache so that the cache is not pointing
|
||||
// at a read-only mmap.
|
||||
|
|
@ -47,7 +47,7 @@ func (btc *BTreeContainers) Put(key uint64, c *container) {
|
|||
btc.tree.Set(key, c)
|
||||
}
|
||||
|
||||
func (u updater) update(oldV *container, exists bool) (*container, bool) {
|
||||
func (u updater) update(oldV *Container, exists bool) (*Container, bool) {
|
||||
// update the existing container
|
||||
if exists {
|
||||
oldV.containerType = u.containerType
|
||||
|
|
@ -55,7 +55,7 @@ func (u updater) update(oldV *container, exists bool) (*container, bool) {
|
|||
oldV.mapped = u.mapped
|
||||
return oldV, false
|
||||
}
|
||||
return &container{
|
||||
return &Container{
|
||||
containerType: u.containerType,
|
||||
n: u.n,
|
||||
mapped: u.mapped,
|
||||
|
|
@ -79,7 +79,7 @@ func (btc *BTreeContainers) Remove(key uint64) {
|
|||
btc.tree.Delete(key)
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) GetOrCreate(key uint64) *container {
|
||||
func (btc *BTreeContainers) GetOrCreate(key uint64) *Container {
|
||||
// Check the last* cache for same container.
|
||||
if key == btc.lastKey && btc.lastContainer != nil {
|
||||
return btc.lastContainer
|
||||
|
|
@ -115,7 +115,7 @@ func (btc *BTreeContainers) Clone() Containers {
|
|||
return nbtc
|
||||
}
|
||||
|
||||
func (btc *BTreeContainers) Last() (key uint64, c *container) {
|
||||
func (btc *BTreeContainers) Last() (key uint64, c *Container) {
|
||||
if btc.tree.Len() == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
|
@ -141,7 +141,7 @@ func (btc *BTreeContainers) Iterator(key uint64) (citer Contiterator, found bool
|
|||
type BTCIterator struct {
|
||||
e *Enumerator
|
||||
key uint64
|
||||
val *container
|
||||
val *Container
|
||||
}
|
||||
|
||||
func (i *BTCIterator) Next() bool {
|
||||
|
|
@ -155,7 +155,7 @@ func (i *BTCIterator) Next() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (i *BTCIterator) Value() (uint64, *container) {
|
||||
func (i *BTCIterator) Value() (uint64, *Container) {
|
||||
if i.val == nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ func NewSliceContainers() *SliceContainers {
|
|||
|
||||
type SliceContainers struct {
|
||||
keys []uint64
|
||||
containers []*container
|
||||
containers []*Container
|
||||
lastKey uint64
|
||||
lastContainer *container
|
||||
lastContainer *Container
|
||||
}
|
||||
|
||||
func (sc *SliceContainers) Get(key uint64) *container {
|
||||
func (sc *SliceContainers) Get(key uint64) *Container {
|
||||
i := search64(sc.keys, key)
|
||||
if i < 0 {
|
||||
return nil
|
||||
|
|
@ -19,7 +19,7 @@ func (sc *SliceContainers) Get(key uint64) *container {
|
|||
return sc.containers[i]
|
||||
}
|
||||
|
||||
func (sc *SliceContainers) Put(key uint64, c *container) {
|
||||
func (sc *SliceContainers) Put(key uint64, c *Container) {
|
||||
i := search64(sc.keys, key)
|
||||
|
||||
// If index is negative then there's not an exact match
|
||||
|
|
@ -58,7 +58,7 @@ func (sc *SliceContainers) Remove(key uint64) {
|
|||
sc.containers = append(sc.containers[:i], sc.containers[i+1:]...)
|
||||
|
||||
}
|
||||
func (sc *SliceContainers) insertAt(key uint64, c *container, i int) {
|
||||
func (sc *SliceContainers) insertAt(key uint64, c *Container, i int) {
|
||||
sc.keys = append(sc.keys, 0)
|
||||
copy(sc.keys[i+1:], sc.keys[i:])
|
||||
sc.keys[i] = key
|
||||
|
|
@ -68,7 +68,7 @@ func (sc *SliceContainers) insertAt(key uint64, c *container, i int) {
|
|||
sc.containers[i] = c
|
||||
}
|
||||
|
||||
func (sc *SliceContainers) GetOrCreate(key uint64) *container {
|
||||
func (sc *SliceContainers) GetOrCreate(key uint64) *Container {
|
||||
// Check the last* cache for same container.
|
||||
if key == sc.lastKey && sc.lastContainer != nil {
|
||||
return sc.lastContainer
|
||||
|
|
@ -90,7 +90,7 @@ func (sc *SliceContainers) GetOrCreate(key uint64) *container {
|
|||
func (sc *SliceContainers) Clone() Containers {
|
||||
other := NewSliceContainers()
|
||||
other.keys = make([]uint64, len(sc.keys))
|
||||
other.containers = make([]*container, len(sc.containers))
|
||||
other.containers = make([]*Container, len(sc.containers))
|
||||
copy(other.keys, sc.keys)
|
||||
for i, c := range sc.containers {
|
||||
other.containers[i] = c.clone()
|
||||
|
|
@ -98,7 +98,7 @@ func (sc *SliceContainers) Clone() Containers {
|
|||
return other
|
||||
}
|
||||
|
||||
func (sc *SliceContainers) Last() (key uint64, c *container) {
|
||||
func (sc *SliceContainers) Last() (key uint64, c *Container) {
|
||||
if len(sc.keys) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ type SliceIterator struct {
|
|||
e *SliceContainers
|
||||
i int
|
||||
key uint64
|
||||
value *container
|
||||
value *Container
|
||||
}
|
||||
|
||||
func (si *SliceIterator) Next() bool {
|
||||
|
|
@ -142,6 +142,6 @@ func (si *SliceIterator) Next() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (si *SliceIterator) Value() (uint64, *container) {
|
||||
func (si *SliceIterator) Value() (uint64, *Container) {
|
||||
return si.key, si.value
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ func testContainersIterator(cs Containers, t *testing.T) {
|
|||
t.Fatal("Next() should be false for empty btc")
|
||||
}
|
||||
|
||||
cs.Put(1, &container{n: 1})
|
||||
cs.Put(2, &container{n: 2})
|
||||
cs.Put(1, &Container{n: 1})
|
||||
cs.Put(2, &Container{n: 2})
|
||||
|
||||
itr, found = cs.Iterator(0)
|
||||
if found {
|
||||
|
|
@ -47,9 +47,9 @@ func testContainersIterator(cs Containers, t *testing.T) {
|
|||
t.Fatalf("itr should be done, but got true")
|
||||
}
|
||||
|
||||
cs.Put(3, &container{n: 3})
|
||||
cs.Put(5, &container{n: 5})
|
||||
cs.Put(6, &container{n: 6})
|
||||
cs.Put(3, &Container{n: 3})
|
||||
cs.Put(5, &Container{n: 5})
|
||||
cs.Put(6, &Container{n: 6})
|
||||
|
||||
itr, found = cs.Iterator(3)
|
||||
if !itr.Next() {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import (
|
|||
"fmt"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
"reflect"
|
||||
"math/bits"
|
||||
"reflect"
|
||||
"sort"
|
||||
"unsafe"
|
||||
)
|
||||
|
|
@ -66,10 +66,10 @@ const (
|
|||
|
||||
type Containers interface {
|
||||
// Get returns nil if the key does not exist.
|
||||
Get(key uint64) *container
|
||||
Get(key uint64) *Container
|
||||
|
||||
// Put adds the container at key.
|
||||
Put(key uint64, c *container)
|
||||
Put(key uint64, c *Container)
|
||||
|
||||
// PutContainerValues updates an existing container at key.
|
||||
// If a container does not exist for key, a new one is allocated.
|
||||
|
|
@ -79,13 +79,13 @@ type Containers interface {
|
|||
Remove(key uint64)
|
||||
|
||||
// GetOrCreate returns the container at key, creating a new empty container if necessary.
|
||||
GetOrCreate(key uint64) *container
|
||||
GetOrCreate(key uint64) *Container
|
||||
|
||||
// Clone does a deep copy of Containers, including cloning all containers contained.
|
||||
Clone() Containers
|
||||
|
||||
// Last returns the highest key and associated container.
|
||||
Last() (key uint64, c *container)
|
||||
Last() (key uint64, c *Container)
|
||||
|
||||
// Size returns the number of containers stored.
|
||||
Size() int
|
||||
|
|
@ -98,7 +98,7 @@ type Containers interface {
|
|||
|
||||
type Contiterator interface {
|
||||
Next() bool
|
||||
Value() (uint64, *container)
|
||||
Value() (uint64, *Container)
|
||||
}
|
||||
|
||||
// Bitmap represents a roaring bitmap.
|
||||
|
|
@ -341,7 +341,7 @@ func (b *Bitmap) OffsetRange(offset, start, end uint64) *Bitmap {
|
|||
}
|
||||
|
||||
// container returns the container with the given key.
|
||||
func (b *Bitmap) container(key uint64) *container {
|
||||
func (b *Bitmap) container(key uint64) *Container {
|
||||
return b.conts.Get(key)
|
||||
}
|
||||
|
||||
|
|
@ -805,7 +805,7 @@ type Iterator struct {
|
|||
bitmap *Bitmap
|
||||
citer Contiterator
|
||||
key uint64
|
||||
c *container
|
||||
c *Container
|
||||
j, k int // i: container; j: array index, bit index, or run index; k: offset within the run
|
||||
}
|
||||
|
||||
|
|
@ -996,17 +996,17 @@ const ArrayMaxSize = 4096
|
|||
// RunMaxSize represents the maximum size of run length encoded containers.
|
||||
const RunMaxSize = 2048
|
||||
|
||||
// container represents a container for uint16 integers.
|
||||
// Container represents a Container for uint16 integers.
|
||||
//
|
||||
// These are used for storing the low bits of numbers in larger sets of uint64.
|
||||
// The high bits are stored in a container's key which is tracked by a separate
|
||||
// data structure. Integers in a container can be encoded in one of three ways -
|
||||
// the encoding used is usually whichever is most compact, though any container
|
||||
// The high bits are stored in a Container's key which is tracked by a separate
|
||||
// data structure. Integers in a Container can be encoded in one of three ways -
|
||||
// the encoding used is usually whichever is most compact, though any Container
|
||||
// type should be able to encode any set of integers safely. For containers with
|
||||
// less than 4,096 values, an array is often used. Containers with long runs of
|
||||
// integers would use run length encoding, and more random data usually uses
|
||||
// bitmap encoding.
|
||||
type container struct {
|
||||
type Container struct {
|
||||
mapped bool // mapped directly to a byte slice when true
|
||||
containerType byte // array, bitmap, or run
|
||||
n int // number of integers in container
|
||||
|
|
@ -1026,22 +1026,22 @@ func (iv interval16) runlen() int {
|
|||
}
|
||||
|
||||
// newContainer returns a new instance of container.
|
||||
func newContainer() *container {
|
||||
return &container{containerType: ContainerArray}
|
||||
func newContainer() *Container {
|
||||
return &Container{containerType: ContainerArray}
|
||||
}
|
||||
|
||||
// isArray returns true if the container is an array container.
|
||||
func (c *container) isArray() bool {
|
||||
func (c *Container) isArray() bool {
|
||||
return c.containerType == ContainerArray
|
||||
}
|
||||
|
||||
// isBitmap returns true if the container is a bitmap container.
|
||||
func (c *container) isBitmap() bool {
|
||||
func (c *Container) isBitmap() bool {
|
||||
return c.containerType == ContainerBitmap
|
||||
}
|
||||
|
||||
// isRun returns true if the container is a run-length-encoded container.
|
||||
func (c *container) isRun() bool {
|
||||
func (c *Container) isRun() bool {
|
||||
return c.containerType == ContainerRun
|
||||
}
|
||||
|
||||
|
|
@ -1049,7 +1049,7 @@ func (c *container) isRun() bool {
|
|||
//
|
||||
// This is performed when altering the container since its contents could be
|
||||
// pointing at a read-only mmap.
|
||||
func (c *container) unmap() {
|
||||
func (c *Container) unmap() {
|
||||
if !c.mapped {
|
||||
return
|
||||
}
|
||||
|
|
@ -1072,12 +1072,12 @@ func (c *container) unmap() {
|
|||
}
|
||||
|
||||
// count counts all bits in the container.
|
||||
func (c *container) count() (n int) {
|
||||
func (c *Container) count() (n int) {
|
||||
return c.countRange(0, maxContainerVal+1)
|
||||
}
|
||||
|
||||
// countRange counts the number of bits set between [start, end).
|
||||
func (c *container) countRange(start, end int) (n int) {
|
||||
func (c *Container) countRange(start, end int) (n int) {
|
||||
if c.isArray() {
|
||||
return c.arrayCountRange(start, end)
|
||||
} else if c.isRun() {
|
||||
|
|
@ -1086,7 +1086,7 @@ func (c *container) countRange(start, end int) (n int) {
|
|||
return c.bitmapCountRange(start, end)
|
||||
}
|
||||
|
||||
func (c *container) arrayCountRange(start, end int) (n int) {
|
||||
func (c *Container) arrayCountRange(start, end int) (n int) {
|
||||
i := sort.Search(len(c.array), func(i int) bool { return int(c.array[i]) >= start })
|
||||
for ; i < len(c.array); i++ {
|
||||
v := int(c.array[i])
|
||||
|
|
@ -1098,7 +1098,7 @@ func (c *container) arrayCountRange(start, end int) (n int) {
|
|||
return n
|
||||
}
|
||||
|
||||
func (c *container) bitmapCountRange(start, end int) int {
|
||||
func (c *Container) bitmapCountRange(start, end int) int {
|
||||
var n uint64
|
||||
i, j := start/64, end/64
|
||||
// Special case when start and end fall in the same word.
|
||||
|
|
@ -1128,7 +1128,7 @@ func (c *container) bitmapCountRange(start, end int) int {
|
|||
return int(n)
|
||||
}
|
||||
|
||||
func (c *container) runCountRange(start, end int) (n int) {
|
||||
func (c *Container) runCountRange(start, end int) (n int) {
|
||||
for _, iv := range c.runs {
|
||||
// iv is before range
|
||||
if int(iv.last) < start {
|
||||
|
|
@ -1159,7 +1159,7 @@ func (c *container) runCountRange(start, end int) (n int) {
|
|||
}
|
||||
|
||||
// add adds a value to the container.
|
||||
func (c *container) add(v uint16) (added bool) {
|
||||
func (c *Container) add(v uint16) (added bool) {
|
||||
|
||||
if c.isArray() {
|
||||
added = c.arrayAdd(v)
|
||||
|
|
@ -1174,7 +1174,7 @@ func (c *container) add(v uint16) (added bool) {
|
|||
return added
|
||||
}
|
||||
|
||||
func (c *container) arrayAdd(v uint16) bool {
|
||||
func (c *Container) arrayAdd(v uint16) bool {
|
||||
// Optimize appending to the end of an array container.
|
||||
if c.n > 0 && c.n < ArrayMaxSize && c.isArray() && c.array[c.n-1] < v {
|
||||
c.unmap()
|
||||
|
|
@ -1204,7 +1204,7 @@ func (c *container) arrayAdd(v uint16) bool {
|
|||
|
||||
}
|
||||
|
||||
func (c *container) bitmapAdd(v uint16) bool {
|
||||
func (c *Container) bitmapAdd(v uint16) bool {
|
||||
if c.bitmapContains(v) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1213,7 +1213,7 @@ func (c *container) bitmapAdd(v uint16) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (c *container) runAdd(v uint16) bool {
|
||||
func (c *Container) runAdd(v uint16) bool {
|
||||
if len(c.runs) == 0 {
|
||||
c.unmap()
|
||||
c.runs = []interval16{{start: v, last: v}}
|
||||
|
|
@ -1260,7 +1260,7 @@ func (c *container) runAdd(v uint16) bool {
|
|||
}
|
||||
|
||||
// contains returns true if v is in the container.
|
||||
func (c *container) contains(v uint16) bool {
|
||||
func (c *Container) contains(v uint16) bool {
|
||||
if c.isArray() {
|
||||
return c.arrayContains(v)
|
||||
} else if c.isRun() {
|
||||
|
|
@ -1270,7 +1270,7 @@ func (c *container) contains(v uint16) bool {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *container) bitmapCountRuns() (r int) {
|
||||
func (c *Container) bitmapCountRuns() (r int) {
|
||||
for i := 0; i < 1023; i++ {
|
||||
v, v1 := c.bitmap[i], c.bitmap[i+1]
|
||||
r = r + int(popcount((v<<1)&^v)+((v>>63)&^v1))
|
||||
|
|
@ -1280,7 +1280,7 @@ func (c *container) bitmapCountRuns() (r int) {
|
|||
return r
|
||||
}
|
||||
|
||||
func (c *container) arrayCountRuns() (r int) {
|
||||
func (c *Container) arrayCountRuns() (r int) {
|
||||
prev := -2
|
||||
for _, v := range c.array {
|
||||
if prev+1 != int(v) {
|
||||
|
|
@ -1291,7 +1291,7 @@ func (c *container) arrayCountRuns() (r int) {
|
|||
return r
|
||||
}
|
||||
|
||||
func (c *container) countRuns() (r int) {
|
||||
func (c *Container) countRuns() (r int) {
|
||||
if c.isArray() {
|
||||
return c.arrayCountRuns()
|
||||
} else if c.isBitmap() {
|
||||
|
|
@ -1306,7 +1306,7 @@ func (c *container) countRuns() (r int) {
|
|||
|
||||
// Optimize converts the container to the type which will take up the least
|
||||
// amount of space.
|
||||
func (c *container) Optimize() {
|
||||
func (c *Container) Optimize() {
|
||||
if c.n == 0 {
|
||||
return
|
||||
}
|
||||
|
|
@ -1343,11 +1343,11 @@ func (c *container) Optimize() {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *container) arrayContains(v uint16) bool {
|
||||
func (c *Container) arrayContains(v uint16) bool {
|
||||
return search32(c.array, v) >= 0
|
||||
}
|
||||
|
||||
func (c *container) bitmapContains(v uint16) bool {
|
||||
func (c *Container) bitmapContains(v uint16) bool {
|
||||
return (c.bitmap[v/64] & (1 << uint64(v%64))) != 0
|
||||
}
|
||||
|
||||
|
|
@ -1365,13 +1365,13 @@ func binSearchRuns(v uint16, a []interval16) (int, bool) {
|
|||
|
||||
// runContains determines if v is in the container assuming c is a run
|
||||
// container.
|
||||
func (c *container) runContains(v uint16) bool {
|
||||
func (c *Container) runContains(v uint16) bool {
|
||||
_, found := binSearchRuns(v, c.runs)
|
||||
return found
|
||||
}
|
||||
|
||||
// remove removes a value from the container.
|
||||
func (c *container) remove(v uint16) (removed bool) {
|
||||
func (c *Container) remove(v uint16) (removed bool) {
|
||||
if c.isArray() {
|
||||
removed = c.arrayRemove(v)
|
||||
} else if c.isRun() {
|
||||
|
|
@ -1385,7 +1385,7 @@ func (c *container) remove(v uint16) (removed bool) {
|
|||
return removed
|
||||
}
|
||||
|
||||
func (c *container) arrayRemove(v uint16) bool {
|
||||
func (c *Container) arrayRemove(v uint16) bool {
|
||||
i := search32(c.array, v)
|
||||
if i < 0 {
|
||||
return false
|
||||
|
|
@ -1396,7 +1396,7 @@ func (c *container) arrayRemove(v uint16) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (c *container) bitmapRemove(v uint16) bool {
|
||||
func (c *Container) bitmapRemove(v uint16) bool {
|
||||
if !c.bitmapContains(v) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1414,7 +1414,7 @@ func (c *container) bitmapRemove(v uint16) bool {
|
|||
}
|
||||
|
||||
// runRemove removes v from a run container, and returns true if v was removed.
|
||||
func (c *container) runRemove(v uint16) bool {
|
||||
func (c *Container) runRemove(v uint16) bool {
|
||||
i, contains := binSearchRuns(v, c.runs)
|
||||
if !contains {
|
||||
return false
|
||||
|
|
@ -1435,7 +1435,7 @@ func (c *container) runRemove(v uint16) bool {
|
|||
}
|
||||
|
||||
// max returns the maximum value in the container.
|
||||
func (c *container) max() uint16 {
|
||||
func (c *Container) max() uint16 {
|
||||
if c.isArray() {
|
||||
return c.arrayMax()
|
||||
} else if c.isRun() {
|
||||
|
|
@ -1445,14 +1445,14 @@ func (c *container) max() uint16 {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *container) arrayMax() uint16 {
|
||||
func (c *Container) arrayMax() uint16 {
|
||||
if len(c.array) == 0 {
|
||||
return 0 // probably hiding some ugly bug but it prevents a crash
|
||||
}
|
||||
return c.array[len(c.array)-1]
|
||||
}
|
||||
|
||||
func (c *container) bitmapMax() uint16 {
|
||||
func (c *Container) bitmapMax() uint16 {
|
||||
// Search bitmap in reverse order.
|
||||
for i := len(c.bitmap) - 1; i >= 0; i-- {
|
||||
// If value is zero then skip.
|
||||
|
|
@ -1474,7 +1474,7 @@ func (c *container) bitmapMax() uint16 {
|
|||
return 0
|
||||
}
|
||||
|
||||
func (c *container) runMax() uint16 {
|
||||
func (c *Container) runMax() uint16 {
|
||||
if len(c.runs) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -1482,7 +1482,7 @@ func (c *container) runMax() uint16 {
|
|||
}
|
||||
|
||||
// bitmapToArray converts from bitmap format to array format.
|
||||
func (c *container) bitmapToArray() {
|
||||
func (c *Container) bitmapToArray() {
|
||||
c.array = make([]uint16, 0, c.n)
|
||||
c.containerType = ContainerArray
|
||||
|
||||
|
|
@ -1505,7 +1505,7 @@ func (c *container) bitmapToArray() {
|
|||
}
|
||||
|
||||
// arrayToBitmap converts from array format to bitmap format.
|
||||
func (c *container) arrayToBitmap() {
|
||||
func (c *Container) arrayToBitmap() {
|
||||
c.bitmap = make([]uint64, bitmapN)
|
||||
c.containerType = ContainerBitmap
|
||||
|
||||
|
|
@ -1524,7 +1524,7 @@ func (c *container) arrayToBitmap() {
|
|||
}
|
||||
|
||||
// runToBitmap converts from RLE format to bitmap format.
|
||||
func (c *container) runToBitmap() {
|
||||
func (c *Container) runToBitmap() {
|
||||
c.bitmap = make([]uint64, bitmapN)
|
||||
c.containerType = ContainerBitmap
|
||||
|
||||
|
|
@ -1547,7 +1547,7 @@ func (c *container) runToBitmap() {
|
|||
}
|
||||
|
||||
// bitmapToRun converts from bitmap format to RLE format.
|
||||
func (c *container) bitmapToRun() {
|
||||
func (c *Container) bitmapToRun() {
|
||||
c.containerType = ContainerRun
|
||||
// return early if empty
|
||||
if c.n == 0 {
|
||||
|
|
@ -1603,7 +1603,7 @@ func (c *container) bitmapToRun() {
|
|||
}
|
||||
|
||||
// arrayToRun converts from array format to RLE format.
|
||||
func (c *container) arrayToRun() {
|
||||
func (c *Container) arrayToRun() {
|
||||
c.containerType = ContainerRun
|
||||
// return early if empty
|
||||
if c.n == 0 {
|
||||
|
|
@ -1630,7 +1630,7 @@ func (c *container) arrayToRun() {
|
|||
}
|
||||
|
||||
// runToArray converts from RLE format to array format.
|
||||
func (c *container) runToArray() {
|
||||
func (c *Container) runToArray() {
|
||||
c.containerType = ContainerArray
|
||||
c.array = make([]uint16, 0, c.n)
|
||||
|
||||
|
|
@ -1651,8 +1651,8 @@ func (c *container) runToArray() {
|
|||
}
|
||||
|
||||
// clone returns a copy of c.
|
||||
func (c *container) clone() *container {
|
||||
other := &container{n: c.n, containerType: c.containerType}
|
||||
func (c *Container) clone() *Container {
|
||||
other := &Container{n: c.n, containerType: c.containerType}
|
||||
|
||||
switch c.containerType {
|
||||
case ContainerArray:
|
||||
|
|
@ -1669,7 +1669,7 @@ func (c *container) clone() *container {
|
|||
}
|
||||
|
||||
// WriteTo writes c to w.
|
||||
func (c *container) WriteTo(w io.Writer) (n int64, err error) {
|
||||
func (c *Container) WriteTo(w io.Writer) (n int64, err error) {
|
||||
if c.isArray() {
|
||||
return c.arrayWriteTo(w)
|
||||
} else if c.isRun() {
|
||||
|
|
@ -1679,7 +1679,7 @@ func (c *container) WriteTo(w io.Writer) (n int64, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *container) arrayWriteTo(w io.Writer) (n int64, err error) {
|
||||
func (c *Container) arrayWriteTo(w io.Writer) (n int64, err error) {
|
||||
if len(c.array) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
|
@ -1695,13 +1695,13 @@ func (c *container) arrayWriteTo(w io.Writer) (n int64, err error) {
|
|||
return int64(nn), err
|
||||
}
|
||||
|
||||
func (c *container) bitmapWriteTo(w io.Writer) (n int64, err error) {
|
||||
func (c *Container) bitmapWriteTo(w io.Writer) (n int64, err error) {
|
||||
// Write sizeof(uint64) * bitmapN bytes.
|
||||
nn, err := w.Write((*[0xFFFFFFF]byte)(unsafe.Pointer(&c.bitmap[0]))[:(8 * bitmapN)])
|
||||
return int64(nn), err
|
||||
}
|
||||
|
||||
func (c *container) runWriteTo(w io.Writer) (n int64, err error) {
|
||||
func (c *Container) runWriteTo(w io.Writer) (n int64, err error) {
|
||||
if len(c.runs) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
|
@ -1716,7 +1716,7 @@ func (c *container) runWriteTo(w io.Writer) (n int64, err error) {
|
|||
}
|
||||
|
||||
// size returns the encoded size of the container, in bytes.
|
||||
func (c *container) size() int {
|
||||
func (c *Container) size() int {
|
||||
if c.isArray() {
|
||||
return len(c.array) * 2 // sizeof(uint16)
|
||||
} else if c.isRun() {
|
||||
|
|
@ -1727,7 +1727,7 @@ func (c *container) size() int {
|
|||
}
|
||||
|
||||
// info returns the current stats about the container.
|
||||
func (c *container) info() ContainerInfo {
|
||||
func (c *Container) info() ContainerInfo {
|
||||
info := ContainerInfo{N: c.n}
|
||||
|
||||
if c.isArray() {
|
||||
|
|
@ -1755,7 +1755,7 @@ func (c *container) info() ContainerInfo {
|
|||
}
|
||||
|
||||
// check performs a consistency check on the container.
|
||||
func (c *container) check() error {
|
||||
func (c *Container) check() error {
|
||||
var a ErrorList
|
||||
|
||||
if c.isArray() {
|
||||
|
|
@ -1795,7 +1795,7 @@ type ContainerInfo struct {
|
|||
|
||||
// flip returns a new container containing the inverse of all
|
||||
// bits in a.
|
||||
func flip(a *container) *container {
|
||||
func flip(a *Container) *Container {
|
||||
if a.isArray() {
|
||||
return flipArray(a)
|
||||
} else if a.isRun() {
|
||||
|
|
@ -1805,15 +1805,15 @@ func flip(a *container) *container {
|
|||
}
|
||||
}
|
||||
|
||||
func flipArray(b *container) *container {
|
||||
func flipArray(b *Container) *Container {
|
||||
// TODO: actually implement this
|
||||
x := b.clone()
|
||||
x.arrayToBitmap()
|
||||
return flipBitmap(x)
|
||||
}
|
||||
|
||||
func flipBitmap(b *container) *container {
|
||||
other := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
func flipBitmap(b *Container) *Container {
|
||||
other := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
|
||||
for i, bitmap := range b.bitmap {
|
||||
other.bitmap[i] = ^bitmap
|
||||
|
|
@ -1823,14 +1823,14 @@ func flipBitmap(b *container) *container {
|
|||
return other
|
||||
}
|
||||
|
||||
func flipRun(b *container) *container {
|
||||
func flipRun(b *Container) *Container {
|
||||
// TODO: actually implement this
|
||||
x := b.clone()
|
||||
x.runToBitmap()
|
||||
return flipBitmap(x)
|
||||
}
|
||||
|
||||
func intersectionCount(a, b *container) int {
|
||||
func intersectionCount(a, b *Container) int {
|
||||
if a.isArray() {
|
||||
if b.isArray() {
|
||||
return intersectionCountArrayArray(a, b)
|
||||
|
|
@ -1858,7 +1858,7 @@ func intersectionCount(a, b *container) int {
|
|||
}
|
||||
}
|
||||
|
||||
func intersectionCountArrayArray(a, b *container) (n int) {
|
||||
func intersectionCountArrayArray(a, b *Container) (n int) {
|
||||
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]
|
||||
|
|
@ -1874,7 +1874,7 @@ func intersectionCountArrayArray(a, b *container) (n int) {
|
|||
return n
|
||||
}
|
||||
|
||||
func intersectionCountArrayRun(a, b *container) (n int) {
|
||||
func intersectionCountArrayRun(a, b *Container) (n int) {
|
||||
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]
|
||||
|
|
@ -1890,7 +1890,7 @@ func intersectionCountArrayRun(a, b *container) (n int) {
|
|||
return n
|
||||
}
|
||||
|
||||
func intersectionCountRunRun(a, b *container) (n int) {
|
||||
func intersectionCountRunRun(a, b *Container) (n int) {
|
||||
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]
|
||||
|
|
@ -1921,14 +1921,14 @@ func intersectionCountRunRun(a, b *container) (n int) {
|
|||
return
|
||||
}
|
||||
|
||||
func intersectionCountBitmapRun(a, b *container) (n int) {
|
||||
func intersectionCountBitmapRun(a, b *Container) (n int) {
|
||||
for _, iv := range b.runs {
|
||||
n += a.bitmapCountRange(int(iv.start), int(iv.last)+1)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func intersectionCountArrayBitmap(a, b *container) (n int) {
|
||||
func intersectionCountArrayBitmap(a, b *Container) (n int) {
|
||||
ln := len(b.bitmap)
|
||||
for _, val := range a.array {
|
||||
i := int(val >> 6)
|
||||
|
|
@ -1941,11 +1941,11 @@ func intersectionCountArrayBitmap(a, b *container) (n int) {
|
|||
return n
|
||||
}
|
||||
|
||||
func intersectionCountBitmapBitmap(a, b *container) (n int) {
|
||||
func intersectionCountBitmapBitmap(a, b *Container) (n int) {
|
||||
return int(popcountAndSlice(a.bitmap, b.bitmap))
|
||||
}
|
||||
|
||||
func intersect(a, b *container) *container {
|
||||
func intersect(a, b *Container) *Container {
|
||||
if a.isArray() {
|
||||
if b.isArray() {
|
||||
return intersectArrayArray(a, b)
|
||||
|
|
@ -1973,8 +1973,8 @@ func intersect(a, b *container) *container {
|
|||
}
|
||||
}
|
||||
|
||||
func intersectArrayArray(a, b *container) *container {
|
||||
output := &container{containerType: ContainerArray}
|
||||
func intersectArrayArray(a, b *Container) *Container {
|
||||
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]
|
||||
|
|
@ -1994,8 +1994,8 @@ func intersectArrayArray(a, b *container) *container {
|
|||
// intersectArrayRun computes the intersect of an array container and a run
|
||||
// container. The return is always an array container (since it's guaranteed to
|
||||
// be low-cardinality)
|
||||
func intersectArrayRun(a, b *container) *container {
|
||||
output := &container{containerType: ContainerArray}
|
||||
func intersectArrayRun(a, b *Container) *Container {
|
||||
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]
|
||||
|
|
@ -2013,8 +2013,8 @@ func intersectArrayRun(a, b *container) *container {
|
|||
}
|
||||
|
||||
// intersectRunRun computes the intersect of two run containers.
|
||||
func intersectRunRun(a, b *container) *container {
|
||||
output := &container{containerType: ContainerRun}
|
||||
func intersectRunRun(a, b *Container) *Container {
|
||||
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]
|
||||
|
|
@ -2052,11 +2052,11 @@ func intersectRunRun(a, b *container) *container {
|
|||
|
||||
// intersectBitmapRun returns an array container if the run container's
|
||||
// cardinality is < ArrayMaxSize. Otherwise it returns a bitmap container.
|
||||
func intersectBitmapRun(a, b *container) *container {
|
||||
var output *container
|
||||
func intersectBitmapRun(a, b *Container) *Container {
|
||||
var output *Container
|
||||
if b.n < ArrayMaxSize {
|
||||
// output is array container
|
||||
output = &container{containerType: ContainerArray}
|
||||
output = &Container{containerType: ContainerArray}
|
||||
for _, iv := range b.runs {
|
||||
for i := iv.start; i <= iv.last; i++ {
|
||||
if a.bitmapContains(i) {
|
||||
|
|
@ -2073,7 +2073,7 @@ func intersectBitmapRun(a, b *container) *container {
|
|||
// right now this iterates through the runs and sets integers in the
|
||||
// bitmap that are in the runs. alternately, we could zero out ranges in
|
||||
// the bitmap which are between runs.
|
||||
output = &container{
|
||||
output = &Container{
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
containerType: ContainerBitmap,
|
||||
}
|
||||
|
|
@ -2115,8 +2115,8 @@ func intersectBitmapRun(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func intersectArrayBitmap(a, b *container) *container {
|
||||
output := &container{containerType: ContainerArray}
|
||||
func intersectArrayBitmap(a, b *Container) *Container {
|
||||
output := &Container{containerType: ContainerArray}
|
||||
for _, va := range a.array {
|
||||
bmidx := va / 64
|
||||
bidx := va % 64
|
||||
|
|
@ -2130,8 +2130,8 @@ func intersectArrayBitmap(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func intersectBitmapBitmap(a, b *container) *container {
|
||||
output := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
func intersectBitmapBitmap(a, b *Container) *Container {
|
||||
output := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
|
||||
for i := range a.bitmap {
|
||||
v := a.bitmap[i] & b.bitmap[i]
|
||||
|
|
@ -2143,7 +2143,7 @@ func intersectBitmapBitmap(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func union(a, b *container) *container {
|
||||
func union(a, b *Container) *Container {
|
||||
if a.isArray() {
|
||||
if b.isArray() {
|
||||
return unionArrayArray(a, b)
|
||||
|
|
@ -2171,8 +2171,8 @@ func union(a, b *container) *container {
|
|||
}
|
||||
}
|
||||
|
||||
func unionArrayArray(a, b *container) *container {
|
||||
output := &container{containerType: ContainerArray}
|
||||
func unionArrayArray(a, b *Container) *Container {
|
||||
output := &Container{containerType: ContainerArray}
|
||||
na, nb := len(a.array), len(b.array)
|
||||
for i, j := 0, 0; ; {
|
||||
if i >= na && j >= nb {
|
||||
|
|
@ -2204,11 +2204,11 @@ func unionArrayArray(a, b *container) *container {
|
|||
|
||||
// unionArrayRun optimistically assumes that the result will be a run container,
|
||||
// and converts to a bitmap or array container afterwards if necessary.
|
||||
func unionArrayRun(a, b *container) *container {
|
||||
func unionArrayRun(a, b *Container) *Container {
|
||||
if b.n == maxContainerVal+1 {
|
||||
return b.clone()
|
||||
}
|
||||
output := &container{containerType: ContainerRun}
|
||||
output := &Container{containerType: ContainerRun}
|
||||
na, nb := len(a.array), len(b.runs)
|
||||
var vb interval16
|
||||
var va uint16
|
||||
|
|
@ -2241,7 +2241,7 @@ func unionArrayRun(a, b *container) *container {
|
|||
// interval is earlier than the start of the last interval in the list of runs.
|
||||
// Its return value is the amount by which the cardinality of the container was
|
||||
// increased.
|
||||
func (c *container) runAppendInterval(v interval16) int {
|
||||
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
|
||||
|
|
@ -2261,7 +2261,7 @@ func (c *container) runAppendInterval(v interval16) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func unionRunRun(a, b *container) *container {
|
||||
func unionRunRun(a, b *Container) *Container {
|
||||
if a.n == maxContainerVal+1 {
|
||||
return a.clone()
|
||||
}
|
||||
|
|
@ -2269,7 +2269,7 @@ func unionRunRun(a, b *container) *container {
|
|||
return b.clone()
|
||||
}
|
||||
na, nb := len(a.runs), len(b.runs)
|
||||
output := &container{
|
||||
output := &Container{
|
||||
runs: make([]interval16, 0, na+nb),
|
||||
containerType: ContainerRun,
|
||||
}
|
||||
|
|
@ -2295,7 +2295,7 @@ func unionRunRun(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func unionBitmapRun(a, b *container) *container {
|
||||
func unionBitmapRun(a, b *Container) *Container {
|
||||
if b.n == maxContainerVal+1 {
|
||||
return b.clone()
|
||||
}
|
||||
|
|
@ -2312,7 +2312,7 @@ func unionBitmapRun(a, b *container) *container {
|
|||
const maxBitmap = 0xFFFFFFFFFFFFFFFF
|
||||
|
||||
// sets all bits in [i, j) (c must be a bitmap container)
|
||||
func (c *container) bitmapSetRange(i, j uint64) {
|
||||
func (c *Container) bitmapSetRange(i, j uint64) {
|
||||
x := i >> 6
|
||||
y := (j - 1) >> 6
|
||||
var X uint64 = maxBitmap << (i % 64)
|
||||
|
|
@ -2335,7 +2335,7 @@ func (c *container) bitmapSetRange(i, j uint64) {
|
|||
}
|
||||
|
||||
// xor's all bits in [i, j) with all true (c must be a bitmap container).
|
||||
func (c *container) bitmapXorRange(i, j uint64) {
|
||||
func (c *Container) bitmapXorRange(i, j uint64) {
|
||||
x := i >> 6
|
||||
y := (j - 1) >> 6
|
||||
var X uint64 = maxBitmap << (i % 64)
|
||||
|
|
@ -2360,7 +2360,7 @@ func (c *container) bitmapXorRange(i, j uint64) {
|
|||
}
|
||||
|
||||
// zeroes all bits in [i, j) (c must be a bitmap container)
|
||||
func (c *container) bitmapZeroRange(i, j uint64) {
|
||||
func (c *Container) bitmapZeroRange(i, j uint64) {
|
||||
x := i >> 6
|
||||
y := (j - 1) >> 6
|
||||
var X uint64 = maxBitmap << (i % 64)
|
||||
|
|
@ -2380,7 +2380,7 @@ func (c *container) bitmapZeroRange(i, j uint64) {
|
|||
}
|
||||
}
|
||||
|
||||
func unionArrayBitmap(a, b *container) *container {
|
||||
func unionArrayBitmap(a, b *Container) *Container {
|
||||
output := b.clone()
|
||||
for _, v := range a.array {
|
||||
if !output.bitmapContains(v) {
|
||||
|
|
@ -2391,8 +2391,8 @@ func unionArrayBitmap(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func unionBitmapBitmap(a, b *container) *container {
|
||||
output := &container{
|
||||
func unionBitmapBitmap(a, b *Container) *Container {
|
||||
output := &Container{
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
containerType: ContainerBitmap,
|
||||
}
|
||||
|
|
@ -2406,7 +2406,7 @@ func unionBitmapBitmap(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func difference(a, b *container) *container {
|
||||
func difference(a, b *Container) *Container {
|
||||
if a.isArray() {
|
||||
if b.isArray() {
|
||||
return differenceArrayArray(a, b)
|
||||
|
|
@ -2435,8 +2435,8 @@ func difference(a, b *container) *container {
|
|||
}
|
||||
|
||||
// differenceArrayArray computes the difference bween two arrays.
|
||||
func differenceArrayArray(a, b *container) *container {
|
||||
output := &container{containerType: ContainerArray}
|
||||
func differenceArrayArray(a, b *Container) *Container {
|
||||
output := &Container{containerType: ContainerArray}
|
||||
na, nb := len(a.array), len(b.array)
|
||||
for i, j := 0, 0; i < na; {
|
||||
va := a.array[i]
|
||||
|
|
@ -2460,14 +2460,14 @@ func differenceArrayArray(a, b *container) *container {
|
|||
}
|
||||
|
||||
// differenceArrayRun computes the difference of an array from a run.
|
||||
func differenceArrayRun(a, b *container) *container {
|
||||
func differenceArrayRun(a, b *Container) *Container {
|
||||
// func (ac *arrayContainer) iandNotRun16(rc *runContainer16) container {
|
||||
|
||||
if a.n == 0 || b.n == 0 {
|
||||
return a.clone()
|
||||
}
|
||||
|
||||
output := &container{array: make([]uint16, 0, a.n), containerType: ContainerArray}
|
||||
output := &Container{array: make([]uint16, 0, a.n), containerType: ContainerArray}
|
||||
// cardinality upper bound: card(A)
|
||||
|
||||
i := 0 // array index
|
||||
|
|
@ -2517,7 +2517,7 @@ func differenceArrayRun(a, b *container) *container {
|
|||
}
|
||||
|
||||
// differenceBitmapRun computes the difference of an bitmap from a run.
|
||||
func differenceBitmapRun(a, b *container) *container {
|
||||
func differenceBitmapRun(a, b *Container) *Container {
|
||||
if a.n == 0 || b.n == 0 {
|
||||
return a.clone()
|
||||
}
|
||||
|
|
@ -2531,11 +2531,11 @@ func differenceBitmapRun(a, b *container) *container {
|
|||
|
||||
// differenceRunArray subtracts the bits in an array container from a run
|
||||
// container.
|
||||
func differenceRunArray(a, b *container) *container {
|
||||
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)), containerType: ContainerRun}
|
||||
output := &Container{runs: make([]interval16, 0, len(a.runs)), containerType: ContainerRun}
|
||||
|
||||
bidx := 0
|
||||
vb := b.array[bidx]
|
||||
|
|
@ -2586,12 +2586,12 @@ RUNLOOP:
|
|||
}
|
||||
|
||||
// differenceRunBitmap computes the difference of an run from a bitmap.
|
||||
func differenceRunBitmap(a, b *container) *container {
|
||||
func differenceRunBitmap(a, b *Container) *Container {
|
||||
// If a is full, difference is the flip of b.
|
||||
if len(a.runs) > 0 && a.runs[0].start == 0 && a.runs[0].last == 65535 {
|
||||
return flipBitmap(b)
|
||||
}
|
||||
output := &container{containerType: ContainerRun}
|
||||
output := &Container{containerType: ContainerRun}
|
||||
output.n = a.n
|
||||
if len(a.runs) == 0 {
|
||||
return output
|
||||
|
|
@ -2643,7 +2643,7 @@ func differenceRunBitmap(a, b *container) *container {
|
|||
}
|
||||
|
||||
// differenceRunRun computes the difference of two runs.
|
||||
func differenceRunRun(a, b *container) *container {
|
||||
func differenceRunRun(a, b *Container) *Container {
|
||||
if a.n == 0 || b.n == 0 {
|
||||
return a.clone()
|
||||
}
|
||||
|
|
@ -2657,7 +2657,7 @@ func differenceRunRun(a, b *container) *container {
|
|||
alen := len(a.runs)
|
||||
blen := len(b.runs)
|
||||
|
||||
output := &container{runs: make([]interval16, 0, alen+blen), containerType: 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
|
||||
|
||||
|
|
@ -2706,8 +2706,8 @@ func differenceRunRun(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func differenceArrayBitmap(a, b *container) *container {
|
||||
output := &container{containerType: ContainerArray}
|
||||
func differenceArrayBitmap(a, b *Container) *Container {
|
||||
output := &Container{containerType: ContainerArray}
|
||||
for _, va := range a.array {
|
||||
bmidx := va / 64
|
||||
bidx := va % 64
|
||||
|
|
@ -2722,7 +2722,7 @@ func differenceArrayBitmap(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func differenceBitmapArray(a, b *container) *container {
|
||||
func differenceBitmapArray(a, b *Container) *Container {
|
||||
output := a.clone()
|
||||
|
||||
for _, v := range b.array {
|
||||
|
|
@ -2737,8 +2737,8 @@ func differenceBitmapArray(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func differenceBitmapBitmap(a, b *container) *container {
|
||||
output := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
func differenceBitmapBitmap(a, b *Container) *Container {
|
||||
output := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
|
||||
for i := range a.bitmap {
|
||||
v := a.bitmap[i] & (^b.bitmap[i])
|
||||
|
|
@ -2752,7 +2752,7 @@ func differenceBitmapBitmap(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func xor(a, b *container) *container {
|
||||
func xor(a, b *Container) *Container {
|
||||
if a.isArray() {
|
||||
if b.isArray() {
|
||||
return xorArrayArray(a, b)
|
||||
|
|
@ -2780,8 +2780,8 @@ func xor(a, b *container) *container {
|
|||
}
|
||||
}
|
||||
|
||||
func xorArrayArray(a, b *container) *container {
|
||||
output := &container{containerType: ContainerArray}
|
||||
func xorArrayArray(a, b *Container) *Container {
|
||||
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 {
|
||||
|
|
@ -2809,7 +2809,7 @@ func xorArrayArray(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func xorArrayBitmap(a, b *container) *container {
|
||||
func xorArrayBitmap(a, b *Container) *Container {
|
||||
output := b.clone()
|
||||
for _, v := range a.array {
|
||||
if b.bitmapContains(v) {
|
||||
|
|
@ -2828,8 +2828,8 @@ func xorArrayBitmap(a, b *container) *container {
|
|||
return output
|
||||
}
|
||||
|
||||
func xorBitmapBitmap(a, b *container) *container {
|
||||
output := &container{
|
||||
func xorBitmapBitmap(a, b *Container) *Container {
|
||||
output := &Container{
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
containerType: ContainerBitmap,
|
||||
}
|
||||
|
|
@ -3038,8 +3038,8 @@ func (a *ErrorList) AppendWithPrefix(err error, prefix string) {
|
|||
}
|
||||
|
||||
// xorArrayRun computes the exclusive or of an array and a run container.
|
||||
func xorArrayRun(a, b *container) *container {
|
||||
output := &container{containerType: ContainerRun}
|
||||
func xorArrayRun(a, b *Container) *Container {
|
||||
output := &Container{containerType: ContainerRun}
|
||||
na, nb := len(a.array), len(b.runs)
|
||||
var vb interval16
|
||||
var va uint16
|
||||
|
|
@ -3200,7 +3200,7 @@ type xorstm struct {
|
|||
}
|
||||
|
||||
// xorRunRun computes the exclusive or of two run containers.
|
||||
func xorRunRun(a, b *container) *container {
|
||||
func xorRunRun(a, b *Container) *Container {
|
||||
na, nb := len(a.runs), len(b.runs)
|
||||
if na == 0 {
|
||||
return b.clone()
|
||||
|
|
@ -3208,7 +3208,7 @@ func xorRunRun(a, b *container) *container {
|
|||
if nb == 0 {
|
||||
return a.clone()
|
||||
}
|
||||
output := &container{containerType: ContainerRun}
|
||||
output := &Container{containerType: ContainerRun}
|
||||
|
||||
lastI, lastJ := -1, -1
|
||||
|
||||
|
|
@ -3248,7 +3248,7 @@ func xorRunRun(a, b *container) *container {
|
|||
}
|
||||
|
||||
// xorRunRun computes the exclusive or of a bitmap and a run container.
|
||||
func xorBitmapRun(a, b *container) *container {
|
||||
func xorBitmapRun(a, b *Container) *Container {
|
||||
output := a.clone()
|
||||
for j := 0; j < len(b.runs); j++ {
|
||||
output.bitmapXorRange(uint64(b.runs[j].start), uint64(b.runs[j].last)+1)
|
||||
|
|
@ -3333,4 +3333,3 @@ func popcountXorSlice(s, m []uint64) uint64 {
|
|||
}
|
||||
return cnt
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -230,8 +230,8 @@ type testOp struct {
|
|||
exp string
|
||||
}
|
||||
|
||||
func doContainer(containerType byte, data interface{}) *container {
|
||||
c := &container{
|
||||
func doContainer(containerType byte, data interface{}) *Container {
|
||||
c := &Container{
|
||||
containerType: containerType,
|
||||
}
|
||||
|
||||
|
|
@ -248,12 +248,12 @@ func doContainer(containerType byte, data interface{}) *container {
|
|||
return c
|
||||
}
|
||||
|
||||
func setupContainerTests() map[byte]map[string]*container {
|
||||
func setupContainerTests() map[byte]map[string]*Container {
|
||||
|
||||
cts := make(map[byte]map[string]*container)
|
||||
cts := make(map[byte]map[string]*Container)
|
||||
|
||||
// array containers
|
||||
cts[ContainerArray] = map[string]*container{
|
||||
cts[ContainerArray] = map[string]*Container{
|
||||
"empty": doContainer(ContainerArray, arrayEmpty()),
|
||||
"full": doContainer(ContainerArray, arrayFull()),
|
||||
"firstBitSet": doContainer(ContainerArray, arrayFirstBitSet()),
|
||||
|
|
@ -267,7 +267,7 @@ func setupContainerTests() map[byte]map[string]*container {
|
|||
}
|
||||
|
||||
// bitmap containers
|
||||
cts[ContainerBitmap] = map[string]*container{
|
||||
cts[ContainerBitmap] = map[string]*Container{
|
||||
"empty": doContainer(ContainerBitmap, bitmapEmpty()),
|
||||
"full": doContainer(ContainerBitmap, bitmapFull()),
|
||||
"firstBitSet": doContainer(ContainerBitmap, bitmapFirstBitSet()),
|
||||
|
|
@ -281,7 +281,7 @@ func setupContainerTests() map[byte]map[string]*container {
|
|||
}
|
||||
|
||||
// run containers
|
||||
cts[ContainerRun] = map[string]*container{
|
||||
cts[ContainerRun] = map[string]*Container{
|
||||
"empty": doContainer(ContainerRun, runEmpty()),
|
||||
"full": doContainer(ContainerRun, runFull()),
|
||||
"firstBitSet": doContainer(ContainerRun, runFirstBitSet()),
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ func (iv interval16) String() string {
|
|||
return fmt.Sprintf("[%d, %d]", iv.start, iv.last)
|
||||
}
|
||||
|
||||
func (c *container) 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.containerType)
|
||||
}
|
||||
|
||||
func TestRunAppendInterval(t *testing.T) {
|
||||
a := container{containerType: ContainerRun}
|
||||
a := Container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
base []interval16
|
||||
app interval16
|
||||
|
|
@ -82,7 +82,7 @@ func TestInterval16RunLen(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContainerRunAdd(t *testing.T) {
|
||||
c := container{runs: make([]interval16, 0), containerType: ContainerRun}
|
||||
c := Container{runs: make([]interval16, 0), containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
op uint16
|
||||
exp []interval16
|
||||
|
|
@ -113,7 +113,7 @@ func TestContainerRunAdd(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContainerRunAdd2(t *testing.T) {
|
||||
c := container{runs: make([]interval16, 0), containerType: 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)
|
||||
|
|
@ -128,7 +128,7 @@ func TestContainerRunAdd2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunCountRange(t *testing.T) {
|
||||
c := container{runs: make([]interval16, 0), containerType: 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)
|
||||
|
|
@ -181,7 +181,7 @@ func TestRunCountRange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunContains(t *testing.T) {
|
||||
c := container{runs: make([]interval16, 0), containerType: ContainerRun}
|
||||
c := Container{runs: make([]interval16, 0), containerType: ContainerRun}
|
||||
if c.runContains(5) {
|
||||
t.Fatalf("empty run container should not contain 5")
|
||||
}
|
||||
|
|
@ -203,7 +203,7 @@ func TestRunContains(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapCountRange(t *testing.T) {
|
||||
c := container{containerType: ContainerBitmap}
|
||||
c := Container{containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
start int
|
||||
end int
|
||||
|
|
@ -228,7 +228,7 @@ func TestBitmapCountRange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectionCountArrayBitmap3(t *testing.T) {
|
||||
a, b := &container{}, &container{}
|
||||
a, b := &Container{}, &Container{}
|
||||
a.containerType = ContainerBitmap
|
||||
a.bitmap = getFullBitmap()
|
||||
a.n = maxContainerVal + 1
|
||||
|
|
@ -255,7 +255,7 @@ func TestIntersectionCountArrayBitmap3(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectionCountArrayBitmap2(t *testing.T) {
|
||||
a, b := &container{}, &container{}
|
||||
a, b := &Container{}, &Container{}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
bitmap []uint64
|
||||
|
|
@ -301,7 +301,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}}, containerType: 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
|
||||
|
|
@ -335,13 +335,13 @@ 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}}, containerType: 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)
|
||||
}
|
||||
|
||||
c = container{runs: []interval16{}}
|
||||
c = Container{runs: []interval16{}}
|
||||
max = c.max()
|
||||
if max != 0 {
|
||||
t.Fatalf("max for %v should be 0", c.runs)
|
||||
|
|
@ -349,8 +349,8 @@ func TestRunMax(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectionCountArrayRun(t *testing.T) {
|
||||
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}}}
|
||||
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 {
|
||||
|
|
@ -359,16 +359,16 @@ func TestIntersectionCountArrayRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectionCountBitmapRun(t *testing.T) {
|
||||
a := &container{containerType: ContainerBitmap, bitmap: []uint64{0x8000000000000000}}
|
||||
b := &container{containerType: 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{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}}}
|
||||
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 {
|
||||
|
|
@ -377,8 +377,8 @@ func TestIntersectionCountBitmapRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectionCountRunRun(t *testing.T) {
|
||||
a := &container{}
|
||||
b := &container{}
|
||||
a := &Container{}
|
||||
b := &Container{}
|
||||
tests := []struct {
|
||||
aruns []interval16
|
||||
bruns []interval16
|
||||
|
|
@ -428,8 +428,8 @@ func TestIntersectionCountRunRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectArrayRun(t *testing.T) {
|
||||
a := &container{}
|
||||
b := &container{}
|
||||
a := &Container{}
|
||||
b := &Container{}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
runs []interval16
|
||||
|
|
@ -470,8 +470,8 @@ func TestIntersectArrayRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectRunRun(t *testing.T) {
|
||||
a := &container{}
|
||||
b := &container{}
|
||||
a := &Container{}
|
||||
b := &Container{}
|
||||
tests := []struct {
|
||||
aruns []interval16
|
||||
bruns []interval16
|
||||
|
|
@ -532,8 +532,8 @@ func TestIntersectRunRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectBitmapRunBitmap(t *testing.T) {
|
||||
a := &container{bitmap: make([]uint64, bitmapN)}
|
||||
b := &container{}
|
||||
a := &Container{bitmap: make([]uint64, bitmapN)}
|
||||
b := &Container{}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
runs []interval16
|
||||
|
|
@ -598,8 +598,8 @@ func TestIntersectBitmapRunBitmap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectBitmapRunArray(t *testing.T) {
|
||||
a := &container{bitmap: make([]uint64, bitmapN)}
|
||||
b := &container{}
|
||||
a := &Container{bitmap: make([]uint64, bitmapN)}
|
||||
b := &Container{}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
runs []interval16
|
||||
|
|
@ -658,19 +658,19 @@ func TestIntersectBitmapRunArray(t *testing.T) {
|
|||
func TestUnionMixed(t *testing.T) {
|
||||
|
||||
// array container
|
||||
a := &container{}
|
||||
a := &Container{}
|
||||
a.array = []uint16{1, 4, 5, 7, 10, 11, 12}
|
||||
a.containerType = ContainerArray
|
||||
a.n = 7
|
||||
|
||||
// bitmap container
|
||||
b := &container{bitmap: make([]uint64, bitmapN)}
|
||||
b := &Container{bitmap: make([]uint64, bitmapN)}
|
||||
b.bitmap[0] = uint64(0x3)
|
||||
b.n = 2
|
||||
b.containerType = ContainerBitmap
|
||||
|
||||
// run container
|
||||
r := &container{}
|
||||
r := &Container{}
|
||||
r.runs = []interval16{{start: 5, last: 10}}
|
||||
r.containerType = ContainerRun
|
||||
r.n = 6
|
||||
|
|
@ -678,8 +678,8 @@ func TestUnionMixed(t *testing.T) {
|
|||
t.Run("various container Unions", func(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
c1 *container
|
||||
c2 *container
|
||||
c1 *Container
|
||||
c2 *Container
|
||||
exp []uint16
|
||||
}{
|
||||
{name: "run-array", c1: r, c2: a, exp: []uint16{1, 4, 5, 6, 7, 8, 9, 10, 11, 12}},
|
||||
|
|
@ -707,9 +707,9 @@ func TestUnionMixed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectMixed(t *testing.T) {
|
||||
a := &container{}
|
||||
b := &container{}
|
||||
c := &container{}
|
||||
a := &Container{}
|
||||
b := &Container{}
|
||||
c := &Container{}
|
||||
|
||||
a.runs = []interval16{{start: 5, last: 10}}
|
||||
a.n = 6
|
||||
|
|
@ -755,10 +755,10 @@ func TestIntersectMixed(t *testing.T) {
|
|||
|
||||
}
|
||||
func TestDifferenceMixed(t *testing.T) {
|
||||
a := &container{}
|
||||
b := &container{}
|
||||
c := &container{}
|
||||
d := &container{}
|
||||
a := &Container{}
|
||||
b := &Container{}
|
||||
c := &Container{}
|
||||
d := &Container{}
|
||||
|
||||
a.runs = []interval16{{start: 5, last: 10}}
|
||||
a.n = a.runCountRange(0, 100)
|
||||
|
|
@ -834,8 +834,8 @@ func TestDifferenceMixed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUnionRunRun(t *testing.T) {
|
||||
a := &container{}
|
||||
b := &container{}
|
||||
a := &Container{}
|
||||
b := &Container{}
|
||||
tests := []struct {
|
||||
aruns []interval16
|
||||
bruns []interval16
|
||||
|
|
@ -895,8 +895,8 @@ func TestUnionRunRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUnionArrayRun(t *testing.T) {
|
||||
a := &container{}
|
||||
b := &container{}
|
||||
a := &Container{}
|
||||
b := &Container{}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
runs []interval16
|
||||
|
|
@ -937,7 +937,7 @@ func TestUnionArrayRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapSetRange(t *testing.T) {
|
||||
c := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
c := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
start uint64
|
||||
|
|
@ -977,7 +977,7 @@ func TestBitmapSetRange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestArrayToBitmap(t *testing.T) {
|
||||
a := &container{containerType: ContainerArray}
|
||||
a := &Container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
exp []uint64
|
||||
|
|
@ -1008,7 +1008,7 @@ func TestArrayToBitmap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapToArray(t *testing.T) {
|
||||
a := &container{containerType: ContainerBitmap}
|
||||
a := &Container{containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
exp []uint16
|
||||
|
|
@ -1039,7 +1039,7 @@ func TestBitmapToArray(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunToBitmap(t *testing.T) {
|
||||
a := &container{containerType: ContainerRun}
|
||||
a := &Container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
runs []interval16
|
||||
exp []uint64
|
||||
|
|
@ -1093,7 +1093,7 @@ func getFullBitmap() []uint64 {
|
|||
}
|
||||
|
||||
func TestBitmapToRun(t *testing.T) {
|
||||
a := &container{containerType: ContainerBitmap}
|
||||
a := &Container{containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
exp []interval16
|
||||
|
|
@ -1171,7 +1171,7 @@ func TestBitmapToRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestArrayToRun(t *testing.T) {
|
||||
a := &container{containerType: ContainerArray}
|
||||
a := &Container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
exp []interval16
|
||||
|
|
@ -1205,7 +1205,7 @@ func TestArrayToRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunToArray(t *testing.T) {
|
||||
a := &container{containerType: ContainerRun}
|
||||
a := &Container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
runs []interval16
|
||||
exp []uint16
|
||||
|
|
@ -1239,7 +1239,7 @@ func TestRunToArray(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapZeroRange(t *testing.T) {
|
||||
c := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
c := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
start uint64
|
||||
|
|
@ -1283,8 +1283,8 @@ func TestBitmapZeroRange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUnionBitmapRun(t *testing.T) {
|
||||
a := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
b := &container{containerType: ContainerRun}
|
||||
a := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
b := &Container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
runs []interval16
|
||||
|
|
@ -1322,7 +1322,7 @@ func TestUnionBitmapRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapCountRuns(t *testing.T) {
|
||||
c := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
c := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
exp int
|
||||
|
|
@ -1372,7 +1372,7 @@ func TestBitmapCountRuns(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestArrayCountRuns(t *testing.T) {
|
||||
c := &container{containerType: ContainerArray}
|
||||
c := &Container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
exp int
|
||||
|
|
@ -1413,8 +1413,8 @@ func TestArrayCountRuns(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceArrayRun(t *testing.T) {
|
||||
a := &container{containerType: ContainerArray}
|
||||
b := &container{containerType: ContainerRun}
|
||||
a := &Container{containerType: ContainerArray}
|
||||
b := &Container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
array []uint16
|
||||
runs []interval16
|
||||
|
|
@ -1439,8 +1439,8 @@ func TestDifferenceArrayRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceRunArray(t *testing.T) {
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: ContainerArray}
|
||||
a := &Container{containerType: ContainerRun}
|
||||
b := &Container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
runs []interval16
|
||||
array []uint16
|
||||
|
|
@ -1520,8 +1520,8 @@ func MakeLastBitSet() []uint64 {
|
|||
}
|
||||
|
||||
func TestDifferenceRunBitmap(t *testing.T) {
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
a := &Container{containerType: ContainerRun}
|
||||
b := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
tests := []struct {
|
||||
runs []interval16
|
||||
bitmap []uint64
|
||||
|
|
@ -1583,8 +1583,8 @@ func TestDifferenceRunBitmap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceBitmapRun(t *testing.T) {
|
||||
a := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
b := &container{containerType: ContainerRun}
|
||||
a := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
b := &Container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
runs []interval16
|
||||
|
|
@ -1666,8 +1666,8 @@ func TestDifferenceBitmapRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceBitmapArray(t *testing.T) {
|
||||
b := &container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
a := &container{containerType: ContainerArray}
|
||||
b := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
|
||||
a := &Container{containerType: ContainerArray}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
array []uint16
|
||||
|
|
@ -1716,8 +1716,8 @@ func TestDifferenceBitmapArray(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceBitmapBitmap(t *testing.T) {
|
||||
a := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
b := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
a := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
b := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
abitmap []uint64
|
||||
bbitmap []uint64
|
||||
|
|
@ -1746,8 +1746,8 @@ func TestDifferenceBitmapBitmap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDifferenceRunRun(t *testing.T) {
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: ContainerRun}
|
||||
a := &Container{containerType: ContainerRun}
|
||||
b := &Container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
aruns []interval16
|
||||
bruns []interval16
|
||||
|
|
@ -1780,7 +1780,7 @@ func TestDifferenceRunRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWriteReadArray(t *testing.T) {
|
||||
ca := &container{array: []uint16{1, 10, 100, 1000}, n: 4, containerType: ContainerArray}
|
||||
ca := &Container{array: []uint16{1, 10, 100, 1000}, n: 4, containerType: ContainerArray}
|
||||
ba := NewSliceBitmap()
|
||||
ba.conts.Put(0, ca)
|
||||
ba2 := NewSliceBitmap()
|
||||
|
|
@ -1800,7 +1800,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, containerType: ContainerBitmap}
|
||||
cb := &Container{bitmap: make([]uint64, bitmapN), n: 129 * 32, containerType: ContainerBitmap}
|
||||
for i := 0; i < 129; i++ {
|
||||
cb.bitmap[i] = 0x5555555555555555
|
||||
}
|
||||
|
|
@ -1823,7 +1823,7 @@ func TestWriteReadBitmap(t *testing.T) {
|
|||
|
||||
func TestWriteReadFullBitmap(t *testing.T) {
|
||||
// create bitmap containing > 4096 bits
|
||||
cb := &container{bitmap: make([]uint64, bitmapN), n: 65536, containerType: ContainerBitmap}
|
||||
cb := &Container{bitmap: make([]uint64, bitmapN), n: 65536, containerType: ContainerBitmap}
|
||||
for i := 0; i < bitmapN; i++ {
|
||||
cb.bitmap[i] = 0xffffffffffffffff
|
||||
}
|
||||
|
|
@ -1852,7 +1852,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, containerType: ContainerRun}
|
||||
cr := &Container{runs: []interval16{{start: 3, last: 13}, {start: 100, last: 109}}, n: 21, containerType: ContainerRun}
|
||||
br := NewSliceBitmap()
|
||||
br.conts.Put(0, cr)
|
||||
br2 := NewSliceBitmap()
|
||||
|
|
@ -1872,26 +1872,26 @@ func TestWriteReadRun(t *testing.T) {
|
|||
|
||||
func TestXorArrayRun(t *testing.T) {
|
||||
tests := []struct {
|
||||
a *container
|
||||
b *container
|
||||
exp *container
|
||||
a *Container
|
||||
b *Container
|
||||
exp *Container
|
||||
}{
|
||||
{
|
||||
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}, 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}, 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{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}, 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}, 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}, containerType: ContainerArray},
|
||||
b: &container{runs: []interval16{{start: 65535, last: 65535}}, containerType: ContainerRun},
|
||||
exp: &container{array: []uint16{}, containerType: 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},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -1912,8 +1912,8 @@ func TestXorArrayRun(t *testing.T) {
|
|||
|
||||
//special case that didn't fit the xorrunrun table testing below.
|
||||
func TestXorRunRun1(t *testing.T) {
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: 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)
|
||||
|
|
@ -1927,8 +1927,8 @@ func TestXorRunRun1(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestXorRunRun(t *testing.T) {
|
||||
a := &container{containerType: ContainerRun}
|
||||
b := &container{containerType: ContainerRun}
|
||||
a := &Container{containerType: ContainerRun}
|
||||
b := &Container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
aruns []interval16
|
||||
bruns []interval16
|
||||
|
|
@ -2025,7 +2025,7 @@ func TestXorRunRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBitmapXorRange(t *testing.T) {
|
||||
c := &container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
c := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
start uint64
|
||||
|
|
@ -2093,8 +2093,8 @@ func TestBitmapXorRange(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestXorBitmapRun(t *testing.T) {
|
||||
a := &container{containerType: ContainerBitmap}
|
||||
b := &container{containerType: ContainerRun}
|
||||
a := &Container{containerType: ContainerBitmap}
|
||||
b := &Container{containerType: ContainerRun}
|
||||
tests := []struct {
|
||||
bitmap []uint64
|
||||
runs []interval16
|
||||
|
|
@ -2546,7 +2546,7 @@ func TestSearch64(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIntersectArrayBitmap(t *testing.T) {
|
||||
a, b := &container{containerType: ContainerArray}, &container{
|
||||
a, b := &Container{containerType: ContainerArray}, &Container{
|
||||
containerType: ContainerBitmap,
|
||||
bitmap: make([]uint64, bitmapN),
|
||||
}
|
||||
|
|
@ -3226,12 +3226,12 @@ func TestContainerCombinations(t *testing.T) {
|
|||
}
|
||||
|
||||
//func getFunc(func(a, b *container) *container, m, n *container) *container {
|
||||
func runContainerFunc(f interface{}, c ...*container) *container {
|
||||
func runContainerFunc(f interface{}, c ...*Container) *Container {
|
||||
switch f.(type) {
|
||||
case func(*container) *container:
|
||||
return f.(func(*container) *container)(c[0])
|
||||
case func(*container, *container) *container:
|
||||
return f.(func(a, b *container) *container)(c[0], c[1])
|
||||
case func(*Container) *Container:
|
||||
return f.(func(*Container) *Container)(c[0])
|
||||
case func(*Container, *Container) *Container:
|
||||
return f.(func(a, b *Container) *Container)(c[0], c[1])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue