mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 11:27:50 +00:00
fix linter errors
This commit is contained in:
parent
374a4ec9ce
commit
b61bdbd7a0
6 changed files with 77 additions and 31 deletions
|
|
@ -30,11 +30,13 @@ func fromArray16(a []uint16) []byte {
|
|||
return (*[8192]byte)(unsafe.Pointer(&a[0]))[: len(a)*2 : len(a)*2]
|
||||
}
|
||||
|
||||
/* lint
|
||||
func cloneArray16(a []uint16) []uint16 {
|
||||
other := make([]uint16, len(a))
|
||||
copy(other, a)
|
||||
return other
|
||||
}
|
||||
*/
|
||||
|
||||
// arrayIndex returns the insertion index of v in a. Returns true if exact match.
|
||||
func arrayIndex(a []uint16, v uint16) (int, bool) {
|
||||
|
|
@ -74,8 +76,10 @@ func fromInterval16(a []roaring.Interval16) []byte {
|
|||
return (*[8192]byte)(unsafe.Pointer(&a[0]))[: len(a)*4 : len(a)*4]
|
||||
}
|
||||
|
||||
/* lint
|
||||
func cloneInterval16(a []roaring.Interval16) []roaring.Interval16 {
|
||||
other := make([]roaring.Interval16, len(a))
|
||||
copy(other, a)
|
||||
return other
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ func toPgno(val []byte) uint32 {
|
|||
func (c *Cursor) putLeafCell(in leafArgs) (err error) {
|
||||
cells := readLeafCells(c.leafPage, c.leafCells[:])
|
||||
elem := &c.stack.elems[c.stack.index]
|
||||
cell := leafCell{Key: in.Key, Type: in.Type, N: in.N, Data: in.Data}
|
||||
cell := leafCell(in)
|
||||
|
||||
if elem.index >= len(cells) || c.Key() != cell.Key {
|
||||
//new cell
|
||||
|
|
@ -376,7 +376,9 @@ func (c *Cursor) putLeafCell(in leafArgs) (err error) {
|
|||
if in.Type == ContainerTypeBitmap {
|
||||
var bm [PageSize]byte
|
||||
copy(bm[:], fromArray64(toArray64(in.Data)))
|
||||
c.tx.writeBitmapPage(toPgno(cell.Data), bm[:])
|
||||
if err = c.tx.writeBitmapPage(toPgno(cell.Data), bm[:]); err != nil {
|
||||
return errors.Wrap(err, "putLeafCell writing bitmap page")
|
||||
}
|
||||
}
|
||||
var buf [PageSize]byte
|
||||
// Write cells to page.
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
package rbf_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"math/bits"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
|
|
@ -866,7 +867,9 @@ func TestCursor_UpdateBranchCells(t *testing.T) {
|
|||
}
|
||||
changed, err = c.Remove(1)
|
||||
if changed {
|
||||
c.First()
|
||||
if err := c.First(); err != nil && err != io.EOF {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, want := c.Values(), []uint16{}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -885,7 +888,9 @@ func TestCursor_UpdateBranchCells(t *testing.T) {
|
|||
}
|
||||
changed, err = c.Remove(2)
|
||||
if changed {
|
||||
c.First()
|
||||
if err := c.First(); err != nil && err != io.EOF {
|
||||
panic(err)
|
||||
}
|
||||
if got, want := c.Values(), []uint16{1}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -895,7 +900,9 @@ func TestCursor_UpdateBranchCells(t *testing.T) {
|
|||
|
||||
changed, err = c.Remove(1)
|
||||
if changed {
|
||||
c.First()
|
||||
if err := c.First(); err != nil && err != io.EOF {
|
||||
panic(err)
|
||||
}
|
||||
if got, want := c.Values(), []uint16{}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -929,7 +936,9 @@ func TestCursor_SplitBranchCells(t *testing.T) {
|
|||
numContainers := 314
|
||||
for i := 0; i < numContainers; i++ { //need to calculate how many will force a split
|
||||
b := rb(uint64(i))
|
||||
tx.AddRoaring("x", b)
|
||||
if _, err := tx.AddRoaring("x", b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
before := &EasyWalker{tx: tx}
|
||||
rbf.Page(tx, 0, before)
|
||||
|
|
@ -939,10 +948,9 @@ func TestCursor_SplitBranchCells(t *testing.T) {
|
|||
|
||||
}
|
||||
// adding one more container should split it
|
||||
tx.AddRoaring("x", rb(uint64(numContainers)))
|
||||
c, _ := tx.Cursor("x")
|
||||
c.First()
|
||||
c.Dump("test.dot")
|
||||
if _, err := tx.AddRoaring("x", rb(uint64(numContainers))); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
after := &EasyWalker{tx: tx}
|
||||
rbf.Page(tx, 0, after)
|
||||
|
|
@ -977,14 +985,20 @@ func TestCursor_RemoveCells(t *testing.T) {
|
|||
numContainers := 455 //enough containers to cause a split
|
||||
for i := 0; i < numContainers; i++ {
|
||||
b := rb(uint64(i))
|
||||
tx.AddRoaring("x", b)
|
||||
if _, err := tx.AddRoaring("x", b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
for i := numContainers; i >= 1; i-- {
|
||||
cur.RemoveRoaring(rb(uint64(i)))
|
||||
if _, err := cur.RemoveRoaring(rb(uint64(i))); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
cur.RemoveRoaring(rb(uint64(0)))
|
||||
if _, err := cur.RemoveRoaring(rb(uint64(0))); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//f, err := os.OpenFile("before.dot", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 066)
|
||||
}
|
||||
|
|
@ -1000,7 +1014,9 @@ func TestCursor_PlayContainer(t *testing.T) {
|
|||
}
|
||||
many := func(c *rbf.Cursor, start, count uint64) {
|
||||
for i := start; i < start+count; i++ {
|
||||
c.Add(i)
|
||||
if _, err := c.Add(i); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
cur, _ := tx.Cursor("x")
|
||||
|
|
@ -1018,7 +1034,9 @@ func TestCursor_PlayContainer(t *testing.T) {
|
|||
many(cur, 9*65536, rbf.ArrayMaxSize+10) //+offset)
|
||||
*/
|
||||
|
||||
cur.First()
|
||||
if err := cur.First(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cur.Dump("fun.dot")
|
||||
}
|
||||
|
||||
|
|
@ -1044,13 +1062,17 @@ func TestCursor_OneBitmap(t *testing.T) {
|
|||
numContainers := 4
|
||||
for i := 0; i < numContainers; i++ { //need to calculate how many will force a split
|
||||
b := rb(uint64(i)) // measured at i=454 seems reasonable should occur at Len(branchcells)+header >8192
|
||||
tx.AddRoaring("x", b)
|
||||
if _, err := tx.AddRoaring("x", b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
cur, err := tx.Cursor("x")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cur.First()
|
||||
if err := cur.First(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cur.Dump("fun.dot")
|
||||
}
|
||||
func TestCursor_GenerateAll(t *testing.T) {
|
||||
|
|
@ -1066,23 +1088,31 @@ func TestCursor_GenerateAll(t *testing.T) {
|
|||
bm.Put(11, roaring.NewContainerArray([]uint16{1, 2, 3}))
|
||||
return bm
|
||||
}()
|
||||
tx.AddRoaring("x", ar)
|
||||
if _, err := tx.AddRoaring("x", ar); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
rb := func() *roaring.Bitmap {
|
||||
bm := roaring.NewBitmap()
|
||||
bm.Put(1, roaring.NewContainerRun([]roaring.Interval16{{Start: 1, Last: 12}}))
|
||||
return bm
|
||||
}()
|
||||
tx.AddRoaring("x", rb)
|
||||
if _, err := tx.AddRoaring("x", rb); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bb := func() *roaring.Bitmap {
|
||||
bm := roaring.NewBitmap()
|
||||
bm.Put(0, roaring.NewContainerBitmap(makeBitmap([]uint16{75})))
|
||||
return bm
|
||||
}()
|
||||
tx.AddRoaring("x", bb)
|
||||
if _, err := tx.AddRoaring("x", bb); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := tx.CreateBitmap("field/view/"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tx.AddRoaring("field/view/", bb)
|
||||
if _, err := tx.AddRoaring("field/view/", bb); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cur, err := tx.Cursor("field/view/")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
|
|
@ -21,14 +21,20 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/pilosa/pilosa/v2/roaring"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//probably should just implement the container interface
|
||||
// but for now i'll do it
|
||||
func (c *Cursor) Rows() ([]uint64, error) {
|
||||
shardVsContainerExponent := uint(4) //needs constant exported from roaring package
|
||||
c.First()
|
||||
rows := make([]uint64, 0)
|
||||
if err := c.First(); err != nil {
|
||||
if err == io.EOF { //root leaf with no elements
|
||||
return rows, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "rows")
|
||||
}
|
||||
var err error
|
||||
var lastRow uint64 = math.MaxUint64
|
||||
for {
|
||||
|
|
@ -55,7 +61,10 @@ func (tx *Tx) FieldViews() []string {
|
|||
return res
|
||||
}
|
||||
func (c *Cursor) DumpKeys() {
|
||||
c.First()
|
||||
if err := c.First(); err != nil {
|
||||
//ignoring errors for this debug function
|
||||
return
|
||||
}
|
||||
for {
|
||||
err := c.Next()
|
||||
if err == io.EOF {
|
||||
|
|
@ -99,7 +108,9 @@ func (c *Cursor) Row(rowID uint64) (*roaring.Bitmap, error) {
|
|||
elem := &c.stack.elems[c.stack.index]
|
||||
n := readCellN(c.leafPage)
|
||||
if elem.index >= n {
|
||||
c.goNextPage()
|
||||
if err := c.goNextPage(); err != nil {
|
||||
return nil, errors.Wrap(err, "row")
|
||||
}
|
||||
}
|
||||
}
|
||||
other := roaring.NewSliceBitmap()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ package rbf
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
|
@ -99,12 +98,14 @@ func writeMetaRootRecordPageNo(page []byte, pgno uint32) { binary.BigEndian.PutU
|
|||
func readMetaFreelistPageNo(page []byte) uint32 { return binary.BigEndian.Uint32(page[24:]) }
|
||||
func writeMetaFreelistPageNo(page []byte, pgno uint32) { binary.BigEndian.PutUint32(page[24:], pgno) }
|
||||
|
||||
/* lint
|
||||
func readMetaChecksum(page []byte) uint32 {
|
||||
return binary.BigEndian.Uint32(page[PageSize-4 : PageSize])
|
||||
}
|
||||
func writeMetaChecksum(page []byte, chksum uint32) {
|
||||
binary.BigEndian.PutUint32(page[PageSize-4:PageSize], chksum)
|
||||
}
|
||||
*/
|
||||
|
||||
// Root record page helpers
|
||||
|
||||
|
|
@ -471,9 +472,11 @@ func search(n int, f func(int) int) (index int, exact bool) {
|
|||
return i, false
|
||||
}
|
||||
|
||||
/* lint
|
||||
func itohex(v int) string { return fmt.Sprintf("0x%x", v) }
|
||||
|
||||
func hexdump(b []byte) { println(hex.Dump(b)) }
|
||||
*/
|
||||
|
||||
func pagedumpi(b []byte, indent string, writer io.Writer) {
|
||||
pgno := readPageNo(b)
|
||||
|
|
|
|||
|
|
@ -41,9 +41,7 @@ func (tx *Tx) Commit() error {
|
|||
}
|
||||
|
||||
// Disconnect transaction from DB.
|
||||
tx.db.removeTx(tx)
|
||||
|
||||
return nil
|
||||
return tx.db.removeTx(tx)
|
||||
}
|
||||
|
||||
func (tx *Tx) Rollback() error {
|
||||
|
|
@ -67,9 +65,7 @@ func (tx *Tx) Rollback() error {
|
|||
}
|
||||
|
||||
// Disconnect transaction from DB.
|
||||
tx.db.removeTx(tx)
|
||||
|
||||
return nil
|
||||
return tx.db.removeTx(tx)
|
||||
}
|
||||
|
||||
// Root returns the root page number for a bitmap. Returns 0 if the bitmap does not exist.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue