fixed missing refactor test;refactor GetBitmap

This commit is contained in:
Todd Gruben 2020-07-14 07:57:02 -05:00
parent b8fe08c765
commit 374a4ec9ce
5 changed files with 13 additions and 14 deletions

View file

@ -156,7 +156,7 @@ func (c *Cursor) Add(v uint64) (changed bool, err error) {
return false, nil
case ContainerTypeBitmap:
// Exit if bit set in bitmap container.
pgno, bm, err := c.tx.GetBitmap(&cell)
pgno, bm, err := c.tx.leafCellBitmap(toPgno(cell.Data))
if err != nil {
return false, errors.Wrap(err, "cursor.Add")
@ -236,7 +236,7 @@ func (c *Cursor) Remove(v uint64) (changed bool, err error) {
}
return true, c.putLeafCell(leafArgs{Key: cell.Key, Type: ContainerTypeRLE, N: len(runs), Data: fromInterval16(runs)})
case ContainerTypeBitmap:
pgno, bm, err := c.tx.GetBitmap(&cell)
pgno, bm, err := c.tx.leafCellBitmap(toPgno(cell.Data))
if err != nil {
return false, errors.Wrap(err, "cursor.add")
}
@ -286,7 +286,7 @@ func (c *Cursor) Contains(v uint64) (exists bool, err error) {
}
return false, nil
case ContainerTypeBitmap:
_, a, err := c.tx.GetBitmap(&cell)
_, a, err := c.tx.leafCellBitmap(toPgno(cell.Data))
if err != nil {
return false, errors.Wrap(err, "cursor.Contains")
}
@ -943,7 +943,7 @@ func (c *Cursor) Union(rowID uint64, row []uint64) error {
case ContainerTypeRLE:
panic("TODO(BBJ): rbf.Bitmap.Union() RLE support")
case ContainerTypeBitmap:
_, bm, err := c.tx.GetBitmap(&cell)
_, bm, err := c.tx.leafCellBitmap(toPgno(cell.Data))
if err != nil {
return errors.Wrap(err, "union")
}
@ -991,7 +991,7 @@ func (c *Cursor) Intersect(rowID uint64, row []uint64) error {
case ContainerTypeRLE:
panic("TODO(BBJ): rbf.Bitmap.Intersect() RLE support")
case ContainerTypeBitmap:
_, bm, err := c.tx.GetBitmap(&cell)
_, bm, err := c.tx.leafCellBitmap(toPgno(cell.Data))
if err != nil {
return errors.Wrap(err, "cursor.Intersect")
}
@ -1117,7 +1117,7 @@ func (c *Cursor) merge(key uint64, data *roaring.Container) (bool, error) {
d := toArray16(cell.Data)
container = roaring.NewContainerArray(d)
case ContainerTypeBitmap:
_, d, err := c.tx.GetBitmap(&cell)
_, d, err := c.tx.leafCellBitmap(toPgno(cell.Data))
if err != nil {
return false, errors.Wrap(err, "cursor.merge")
}
@ -1204,7 +1204,7 @@ func (c *Cursor) difference(key uint64, data *roaring.Container) (bool, error) {
d := toArray16(cell.Data)
container = roaring.NewContainerArray(d)
case ContainerTypeBitmap:
_, d, err := c.tx.GetBitmap(&cell)
_, d, err := c.tx.leafCellBitmap(toPgno(cell.Data))
if err != nil {
return false, errors.Wrap(err, "cursor.difference")
}

View file

@ -281,7 +281,7 @@ func (c *leafCell) Bitmap(tx *Tx) []uint64 {
}
return buf
case ContainerTypeBitmap:
_, bm, _ := tx.GetBitmap(c)
_, bm, _ := tx.leafCellBitmap(toPgno(c.Data))
return bm
default:
panic(fmt.Sprintf("invalid container type: %d", c.Type))
@ -307,7 +307,7 @@ func (c *leafCell) Values(tx *Tx) []uint16 {
return a
case ContainerTypeBitmap:
a := make([]uint16, 0, BitmapN*64)
_, bm, _ := tx.GetBitmap(c)
_, bm, _ := tx.leafCellBitmap(toPgno(c.Data))
for i, v := range bm {
for j := uint(0); j < 64; j++ {
if v&(1<<j) != 0 {

View file

@ -676,8 +676,7 @@ func (tx *Tx) AddRoaring(name string, bm *roaring.Bitmap) (changed bool, err err
}
return c.AddRoaring(bm)
}
func (tx *Tx) GetBitmap(c *leafCell) (pgno uint32, bm []uint64, err error) {
pgno = toPgno(c.Data)
func (tx *Tx) leafCellBitmap(pgno uint32) (uint32, []uint64, error) {
page, err := tx.readPage(pgno)
if err != nil {
return 0, nil, err

View file

@ -3161,7 +3161,7 @@ func (c *Container) bitmapContains(v uint16) bool {
return (c.bitmap()[v/64] & (1 << uint64(v%64))) != 0
}
// binSearchRuns returns the index of the run containing v, and true, when v is contained;
// BinSearchRuns returns the index of the run containing v, and true, when v is contained;
// or the index of the next run starting after v, and false, when v is not contained.
func BinSearchRuns(v uint16, a []Interval16) (int32, bool) {
i := int32(sort.Search(len(a),

View file

@ -2565,7 +2565,7 @@ func TestRunBinSearchContains(t *testing.T) {
for i, test := range tests {
index := test.index
runs := test.runs
idx, found := binSearchRuns(index, runs)
idx, found := BinSearchRuns(index, runs)
if test.exp.index != idx && test.exp.found != found {
t.Fatalf("test #%v expected %v , but got %v %v", i, test.exp, idx, found)
@ -2630,7 +2630,7 @@ func TestRunBinSearch(t *testing.T) {
},
}
for i, test := range tests {
idx, contains := binSearchRuns(test.search, test.runs)
idx, contains := BinSearchRuns(test.search, test.runs)
if !(test.exp == contains && test.expi == idx) {
t.Fatalf("test #%v expected (%v, %v) but got (%v, %v)", i, test.exp, test.expi, contains, idx)
}