Remove IntersectInverse()

This commit is contained in:
Ben Johnson 2017-08-04 09:48:25 -06:00
parent 0bb94fc83d
commit 3b1428a84e
No known key found for this signature in database
GPG key ID: 81741CD251883081
4 changed files with 4 additions and 172 deletions

View file

@ -97,23 +97,6 @@ func (b *Bitmap) Intersect(other *Bitmap) *Bitmap {
return &Bitmap{segments: segments}
}
// IntersectInverse returns the itersection of b and the inverse other.
func (b *Bitmap) IntersectInverse(other *Bitmap) *Bitmap {
var segments []BitmapSegment
itr := newMergeSegmentIterator(b.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
if s0 == nil {
continue
} else if s1 == nil {
segments = append(segments, *s0)
}
segments = append(segments, *s0.IntersectInverse(s1))
}
return &Bitmap{segments: segments}
}
// Union returns the bitwise union of b and other.
func (b *Bitmap) Union(other *Bitmap) *Bitmap {
var segments []BitmapSegment
@ -337,17 +320,6 @@ func (s *BitmapSegment) Intersect(other *BitmapSegment) *BitmapSegment {
}
}
// IntersectInverse returns the itersection of s and the inverse of other.
func (s *BitmapSegment) IntersectInverse(other *BitmapSegment) *BitmapSegment {
data := s.data.IntersectInverse(&other.data)
return &BitmapSegment{
data: *data,
slice: s.slice,
n: data.Count(),
}
}
// Union returns the bitwise union of s and other.
func (s *BitmapSegment) Union(other *BitmapSegment) *BitmapSegment {
data := s.data.Union(&other.data)

View file

@ -562,7 +562,7 @@ func (f *Fragment) fieldRangeEQ(bitDepth uint, predicate uint64) (*Bitmap, error
if bit == 1 {
b = b.Intersect(row)
} else {
b = b.IntersectInverse(row)
b = b.Difference(row)
}
}
@ -608,7 +608,7 @@ func (f *Fragment) fieldRangeLT(bitDepth uint, predicate uint64, allowEquality b
}
// If bit is set then add columns for set bits to exclude.
keep = keep.Union(b.IntersectInverse(row))
keep = keep.Union(b.Difference(row))
}
return b, nil
@ -630,12 +630,12 @@ func (f *Fragment) fieldRangeGT(bitDepth uint, predicate uint64, allowEquality b
if bit == 1 {
return keep, nil
}
return b.Difference(b.IntersectInverse(row).Difference(keep)), nil
return b.Difference(b.Difference(row).Difference(keep)), nil
}
// If bit is set then remove all unset columns not already kept.
if bit == 1 {
b = b.Difference(b.IntersectInverse(row).Difference(keep))
b = b.Difference(b.Difference(row).Difference(keep))
continue
}

View file

@ -374,33 +374,6 @@ func (b *Bitmap) Intersect(other *Bitmap) *Bitmap {
return output
}
// IntersectInverse returns the intersection of b and the inverse of other.
func (b *Bitmap) IntersectInverse(other *Bitmap) *Bitmap {
output := &Bitmap{}
ki, ci := b.keys, b.containers
kj, cj := other.keys, other.containers
for {
ni, nj := len(ki), len(kj)
if ni == 0 && nj == 0 { // eof(i,j)
break
} else if ni == 0 || (nj != 0 && ki[0] > kj[0]) { // eof(i) or i > j
kj, cj = kj[1:], cj[1:]
} else if nj == 0 || (ki[0] < kj[0]) { // eof(j) or i < j
output.keys = append(output.keys, ki[0])
output.containers = append(output.containers, ci[0].clone())
ki, ci = ki[1:], ci[1:]
} else { // i == j
output.keys = append(output.keys, ki[0])
output.containers = append(output.containers, intersectInverse(ci[0], cj[0]))
ki, ci = ki[1:], ci[1:]
kj, cj = kj[1:], cj[1:]
}
}
return output
}
// Union returns the bitwise union of b and other.
func (b *Bitmap) Union(other *Bitmap) *Bitmap {
output := &Bitmap{}
@ -1457,106 +1430,6 @@ func intersectBitmapBitmap(a, b *container) *container {
return output
}
func intersectInverse(a, b *container) *container {
if a.isArray() {
if b.isArray() {
return intersectInverseArrayArray(a, b)
} else {
return intersectInverseArrayBitmap(a, b)
}
} else {
if b.isArray() {
return intersectInverseBitmapArray(a, b)
} else {
return intersectInverseBitmapBitmap(a, b)
}
}
}
func intersectInverseArrayArray(a, b *container) *container {
output := &container{}
aa, ab := a.array, b.array
for len(aa) > 0 && len(ab) > 0 {
if aa[0] < ab[0] {
output.array = append(output.array, aa[0])
aa = aa[1:]
} else if aa[0] > ab[0] {
ab = ab[1:]
} else {
aa, ab = aa[1:], ab[1:]
}
}
output.array = append(output.array, aa...)
output.n = len(output.array)
return output
}
func intersectInverseArrayBitmap(a, b *container) *container {
output := &container{}
aa := a.array
itr := newBufIterator(newBitmapIterator(b.bitmap))
for len(aa) > 0 {
vb, eof := itr.next()
if aa[0] < vb || eof {
output.add(aa[0])
aa = aa[1:]
itr.unread()
} else if aa[0] > vb {
// nop
} else {
aa = aa[1:]
}
}
return output
}
func intersectInverseBitmapArray(a, b *container) *container {
output := &container{}
itr := newBufIterator(newBitmapIterator(a.bitmap))
ab := b.array
for {
va, eof := itr.next()
if eof {
break
}
if len(ab) == 0 {
output.add(ab[0])
ab = ab[1:]
} else if va < ab[0] {
output.add(va)
} else if va > ab[0] {
// nop
} else {
ab = ab[1:]
}
}
return output
}
func intersectInverseBitmapBitmap(a, b *container) *container {
output := &container{}
itr0 := newBufIterator(newBitmapIterator(a.bitmap))
itr1 := newBufIterator(newBitmapIterator(b.bitmap))
for {
va, eof := itr0.next()
if eof {
break
}
vb, eof := itr1.next()
if va < vb || eof {
output.add(va)
itr1.unread()
} else if va > vb {
itr0.unread()
}
}
return output
}
func union(a, b *container) *container {
if a.isArray() {
if b.isArray() {

View file

@ -109,19 +109,6 @@ func TestBitmap_Intersection(t *testing.T) {
}
func TestBitmap_IntersectInverse(t *testing.T) {
bm0 := roaring.NewBitmap(200, 2683177, 3000000)
bm1 := roaring.NewBitmap()
for i := uint64(628); i < 2683301; i++ {
bm1.Add(i)
}
result := bm0.IntersectInverse(bm1)
if n := result.Count(); n != 2 {
t.Fatalf("unexpected n: %d (%#v)", n, result.Slice())
}
}
func TestBitmap_Difference(t *testing.T) {
bm0 := roaring.NewBitmap(0, 2683177)
bm1 := roaring.NewBitmap()