passed deadcode check

This commit is contained in:
Todd Gruben 2017-12-19 11:30:17 -06:00 committed by Travis Turner
parent ae048733a6
commit fe2ce92077
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9
3 changed files with 4 additions and 159 deletions

View file

@ -1,57 +0,0 @@
// Copyright 2017 Pilosa Corp.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package roaring
import (
"reflect"
"testing"
)
// Ensure iterator returns values from a bitmap.
func TestBitmapIterator(t *testing.T) {
for i, tt := range []struct {
bitmap []uint64
values []uint16
}{
// Empty
{
bitmap: []uint64{6}, // 0110
values: []uint16{1, 2},
},
// Single uint64 bitmap
{
bitmap: []uint64{6}, // 0110
values: []uint16{1, 2},
},
// Multi uint64 bitmap
{
bitmap: []uint64{1 << 63, 1, 0, 1, 3 << 62},
values: []uint16{63, 64, 192, 318, 319},
},
} {
itr := newBitmapIterator(tt.bitmap)
var a []uint16
for v, eof := itr.next(); !eof; v, eof = itr.next() {
a = append(a, v)
}
if !reflect.DeepEqual(a, tt.values) {
t.Errorf("%d. unexpected values: exp=%+v, got=%+v", i, a, tt.values)
}
}
}

View file

@ -718,18 +718,18 @@ func (b *Bitmap) UnmarshalBinary(data []byte) error {
}
// Unmarshal the op and apply it.
var op op
if err := op.UnmarshalBinary(buf); err != nil {
var opr op
if err := opr.UnmarshalBinary(buf); err != nil {
// FIXME(benbjohnson): return error with position so file can be trimmed.
return err
}
op.apply(b)
opr.apply(b)
// Increase the op count.
b.opN++
// Move the buffer forward.
buf = buf[op.size():]
buf = buf[opr.size():]
}
return nil
@ -2990,38 +2990,6 @@ func popcount(x uint64) (n uint64) {
return x >> 56
}
// bitmapIterator represents an iterator over container bitmap values.
type bitmapIterator struct {
bitmap []uint64
i int
}
// Returns eof as true if there are no values left in the iterator.
func (itr *bitmapIterator) next() (v uint16, eof bool) {
if itr.i+1 >= len(itr.bitmap)*64 {
return 0, true
}
itr.i++
// Find first non-zero bit in current bitmap, if possible.
hb := itr.i >> 6
lb := itr.bitmap[hb] >> (uint(itr.i) % 64)
if lb != 0 {
itr.i = itr.i + trailingZeroN(lb)
return uint16(itr.i), false
}
// Otherwise iterate through remaining bitmaps to find next bit.
for hb++; hb < len(itr.bitmap); hb++ {
if itr.bitmap[hb] != 0 {
itr.i = hb<<6 + trailingZeroN(itr.bitmap[hb])
return uint16(itr.i), false
}
}
return 0, true
}
// ErrorList represents a list of errors.
type ErrorList []error
@ -3057,13 +3025,6 @@ func (a *ErrorList) AppendWithPrefix(err error, prefix string) {
}
}
// assert panics with a formatted message if condition is false.
func assert(condition bool, format string, a ...interface{}) {
if !condition {
panic(fmt.Sprintf(format, a...))
}
}
// xorArrayRun computes the exclusive or of an array and a run container.
func xorArrayRun(a, b *container) *container {
output := &container{containerType: ContainerRun}

View file

@ -2493,65 +2493,6 @@ func TestBitmap_BitmapWriteToWithEmpty(t *testing.T) {
}
}
func Test_BufBitmapIterator_Next(t *testing.T) {
b := NewBitmap()
for i := uint64(0); i < 4097; i++ {
b.Add(i)
}
if !b.containers[0].isBitmap() {
t.Fatalf("wrong container type")
}
bin := []uint16{}
itr := newBufBitmapIterator(newBitmapIterator(b.containers[0].bitmap))
x := uint16(0)
for i := 0; i < 10; i++ {
x, _ = itr.next()
bin = append(bin, x)
}
exp := []uint16{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
if !reflect.DeepEqual(bin, exp) {
t.Fatalf("BufBitmapIterator expected (%v) but got (%v)", exp, bin)
}
// ensure that unread points next back one such that the last value is repeated
itr.unread()
x, _ = itr.next()
bin = append(bin, x)
exp = append(exp, uint16(9))
if !reflect.DeepEqual(bin, exp) {
t.Fatalf("BufBitmapIterator expected (%v) but got (%v)", exp, bin)
}
}
func Test_BufBitmapIterator_UnreadPanic(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("BufBitmapIterator unread did not panic")
}
}()
b := NewBitmap()
for i := uint64(0); i < 4097; i++ {
b.Add(i)
}
if !b.containers[0].isBitmap() {
t.Fatalf("wrong container type")
}
itr := newBufBitmapIterator(newBitmapIterator(b.containers[0].bitmap))
for i := 0; i < 10; i++ {
itr.next()
}
// ensure that unreading back-to-back panics
itr.unread()
itr.unread()
}
func TestSearch64(t *testing.T) {
tests := []struct {
a []uint64