mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
cleanup local variable naming and comments for Rows
This commit is contained in:
parent
575e199ad8
commit
6f204e11f1
9 changed files with 171 additions and 171 deletions
18
executor.go
18
executor.go
|
|
@ -320,7 +320,7 @@ func (e *Executor) executeBitmapCall(ctx context.Context, index string, c *pql.C
|
|||
reduceFn := func(prev, v interface{}) interface{} {
|
||||
other, _ := prev.(*Row)
|
||||
if other == nil {
|
||||
other = NewBitmap()
|
||||
other = NewRow()
|
||||
}
|
||||
other.Merge(v.(*Row))
|
||||
return other
|
||||
|
|
@ -708,7 +708,7 @@ func (e *Executor) executeBitmapSlice(ctx context.Context, index string, c *pql.
|
|||
|
||||
frag := e.Holder.Fragment(index, frame, view, slice)
|
||||
if frag == nil {
|
||||
return NewBitmap(), nil
|
||||
return NewRow(), nil
|
||||
}
|
||||
return frag.Row(id), nil
|
||||
}
|
||||
|
|
@ -874,7 +874,7 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c *
|
|||
// Retrieve fragment.
|
||||
frag := e.Holder.Fragment(index, frame, ViewFieldPrefix+fieldName, slice)
|
||||
if frag == nil {
|
||||
return NewBitmap(), nil
|
||||
return NewRow(), nil
|
||||
}
|
||||
|
||||
return frag.FieldNotNull(field.BitDepth())
|
||||
|
|
@ -903,13 +903,13 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c *
|
|||
|
||||
baseValueMin, baseValueMax, outOfRange := field.BaseValueBetween(predicates[0], predicates[1])
|
||||
if outOfRange {
|
||||
return NewBitmap(), nil
|
||||
return NewRow(), nil
|
||||
}
|
||||
|
||||
// Retrieve fragment.
|
||||
frag := e.Holder.Fragment(index, frame, ViewFieldPrefix+fieldName, slice)
|
||||
if frag == nil {
|
||||
return NewBitmap(), nil
|
||||
return NewRow(), nil
|
||||
}
|
||||
|
||||
// If the query is asking for the entire valid range, just return
|
||||
|
|
@ -936,13 +936,13 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c *
|
|||
|
||||
baseValue, outOfRange := field.BaseValue(cond.Op, value)
|
||||
if outOfRange && cond.Op != pql.NEQ {
|
||||
return NewBitmap(), nil
|
||||
return NewRow(), nil
|
||||
}
|
||||
|
||||
// Retrieve fragment.
|
||||
frag := e.Holder.Fragment(index, frame, ViewFieldPrefix+fieldName, slice)
|
||||
if frag == nil {
|
||||
return NewBitmap(), nil
|
||||
return NewRow(), nil
|
||||
}
|
||||
|
||||
// LT[E] and GT[E] should return all not-null if selected range fully encompasses valid field range.
|
||||
|
|
@ -963,7 +963,7 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c *
|
|||
|
||||
// executeUnionSlice executes a union() call for a local slice.
|
||||
func (e *Executor) executeUnionSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) {
|
||||
other := NewBitmap()
|
||||
other := NewRow()
|
||||
for i, input := range c.Children {
|
||||
bm, err := e.executeBitmapCallSlice(ctx, index, input, slice)
|
||||
if err != nil {
|
||||
|
|
@ -982,7 +982,7 @@ func (e *Executor) executeUnionSlice(ctx context.Context, index string, c *pql.C
|
|||
|
||||
// executeXorSlice executes a xor() call for a local slice.
|
||||
func (e *Executor) executeXorSlice(ctx context.Context, index string, c *pql.Call, slice uint64) (*Row, error) {
|
||||
other := NewBitmap()
|
||||
other := NewRow()
|
||||
for i, input := range c.Children {
|
||||
bm, err := e.executeBitmapCallSlice(ctx, index, input, slice)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -975,8 +975,8 @@ func TestExecutor_Execute_FieldRange(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
// Ensure a remote query can return a bitmap.
|
||||
func TestExecutor_Execute_Remote_Bitmap(t *testing.T) {
|
||||
// Ensure a remote query can return a row.
|
||||
func TestExecutor_Execute_Remote_Row(t *testing.T) {
|
||||
c := test.NewCluster(2)
|
||||
|
||||
// Create secondary server and update second cluster node.
|
||||
|
|
@ -1000,12 +1000,12 @@ func TestExecutor_Execute_Remote_Bitmap(t *testing.T) {
|
|||
}
|
||||
|
||||
// Set bits in slice 0 & 2.
|
||||
bm := pilosa.NewBitmap(
|
||||
r := pilosa.NewRow(
|
||||
(0*SliceWidth)+1,
|
||||
(0*SliceWidth)+2,
|
||||
(2*SliceWidth)+4,
|
||||
)
|
||||
return []interface{}{bm}, nil
|
||||
return []interface{}{r}, nil
|
||||
}
|
||||
|
||||
// Create local executor data.
|
||||
|
|
|
|||
|
|
@ -730,7 +730,7 @@ func (f *Fragment) fieldRangeNEQ(bitDepth uint, predicate uint64) (*Row, error)
|
|||
}
|
||||
|
||||
func (f *Fragment) fieldRangeLT(bitDepth uint, predicate uint64, allowEquality bool) (*Row, error) {
|
||||
keep := NewBitmap()
|
||||
keep := NewRow()
|
||||
|
||||
// Start with set of columns with values set.
|
||||
b := f.Row(uint64(bitDepth))
|
||||
|
|
@ -779,7 +779,7 @@ func (f *Fragment) fieldRangeLT(bitDepth uint, predicate uint64, allowEquality b
|
|||
|
||||
func (f *Fragment) fieldRangeGT(bitDepth uint, predicate uint64, allowEquality bool) (*Row, error) {
|
||||
b := f.Row(uint64(bitDepth))
|
||||
keep := NewBitmap()
|
||||
keep := NewRow()
|
||||
|
||||
// Filter any bits that don't match the current bit value.
|
||||
for i := int(bitDepth - 1); i >= 0; i-- {
|
||||
|
|
@ -820,8 +820,8 @@ func (f *Fragment) FieldNotNull(bitDepth uint) (*Row, error) {
|
|||
// FieldRangeBetween returns bitmaps with a field value encoding matching any value between predicateMin and predicateMax.
|
||||
func (f *Fragment) FieldRangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) {
|
||||
b := f.Row(uint64(bitDepth))
|
||||
keep1 := NewBitmap() // GTE
|
||||
keep2 := NewBitmap() // LTE
|
||||
keep1 := NewRow() // GTE
|
||||
keep2 := NewRow() // LTE
|
||||
|
||||
// Filter any bits that don't match the current bit value.
|
||||
for i := int(bitDepth - 1); i >= 0; i-- {
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ func TestFragment_FieldSum(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("WithFilter", func(t *testing.T) {
|
||||
if sum, n, err := f.FieldSum(pilosa.NewBitmap(2000, 4000, 5000), bitDepth); err != nil {
|
||||
if sum, n, err := f.FieldSum(pilosa.NewRow(2000, 4000, 5000), bitDepth); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n != 2 {
|
||||
t.Fatalf("unexpected count: %d", n)
|
||||
|
|
@ -289,11 +289,11 @@ func TestFragment_FieldMinMax(t *testing.T) {
|
|||
cnt uint64
|
||||
}{
|
||||
{filter: nil, exp: 0, cnt: 1},
|
||||
{filter: pilosa.NewBitmap(2000, 4000, 5000), exp: 300, cnt: 2},
|
||||
{filter: pilosa.NewBitmap(2000, 4000), exp: 300, cnt: 2},
|
||||
{filter: pilosa.NewBitmap(1), exp: 0, cnt: 0},
|
||||
{filter: pilosa.NewBitmap(1000), exp: 382, cnt: 1},
|
||||
{filter: pilosa.NewBitmap(7000), exp: 0, cnt: 1},
|
||||
{filter: pilosa.NewRow(2000, 4000, 5000), exp: 300, cnt: 2},
|
||||
{filter: pilosa.NewRow(2000, 4000), exp: 300, cnt: 2},
|
||||
{filter: pilosa.NewRow(1), exp: 0, cnt: 0},
|
||||
{filter: pilosa.NewRow(1000), exp: 382, cnt: 1},
|
||||
{filter: pilosa.NewRow(7000), exp: 0, cnt: 1},
|
||||
}
|
||||
for i, test := range tests {
|
||||
if min, cnt, err := f.FieldMin(test.filter, bitDepth); err != nil {
|
||||
|
|
@ -313,11 +313,11 @@ func TestFragment_FieldMinMax(t *testing.T) {
|
|||
cnt uint64
|
||||
}{
|
||||
{filter: nil, exp: 2818, cnt: 2},
|
||||
{filter: pilosa.NewBitmap(2000, 4000, 5000), exp: 2818, cnt: 1},
|
||||
{filter: pilosa.NewBitmap(2000, 4000), exp: 300, cnt: 2},
|
||||
{filter: pilosa.NewBitmap(1), exp: 0, cnt: 0},
|
||||
{filter: pilosa.NewBitmap(1000), exp: 382, cnt: 1},
|
||||
{filter: pilosa.NewBitmap(7000), exp: 0, cnt: 1},
|
||||
{filter: pilosa.NewRow(2000, 4000, 5000), exp: 2818, cnt: 1},
|
||||
{filter: pilosa.NewRow(2000, 4000), exp: 300, cnt: 2},
|
||||
{filter: pilosa.NewRow(1), exp: 0, cnt: 0},
|
||||
{filter: pilosa.NewRow(1000), exp: 382, cnt: 1},
|
||||
{filter: pilosa.NewRow(7000), exp: 0, cnt: 1},
|
||||
}
|
||||
for i, test := range tests {
|
||||
if max, cnt, err := f.FieldMax(test.filter, bitDepth); err != nil {
|
||||
|
|
@ -642,7 +642,7 @@ func TestFragment_TopN_Intersect(t *testing.T) {
|
|||
defer f.Close()
|
||||
|
||||
// Create an intersecting input row.
|
||||
src := pilosa.NewBitmap(1, 2, 3)
|
||||
src := pilosa.NewRow(1, 2, 3)
|
||||
|
||||
// Set bits on various rows.
|
||||
f.MustSetBits(100, 1, 10, 11, 12) // one intersection
|
||||
|
|
@ -673,7 +673,7 @@ func TestFragment_TopN_Intersect_Large(t *testing.T) {
|
|||
defer f.Close()
|
||||
|
||||
// Create an intersecting input row.
|
||||
src := pilosa.NewBitmap(
|
||||
src := pilosa.NewRow(
|
||||
980, 981, 982, 983, 984, 985, 986, 987, 988, 989,
|
||||
990, 991, 992, 993, 994, 995, 996, 997, 998, 999,
|
||||
)
|
||||
|
|
@ -1081,7 +1081,7 @@ func TestFragment_Tanimoto(t *testing.T) {
|
|||
f := test.MustOpenFragment("i", "f", pilosa.ViewStandard, 0, pilosa.CacheTypeRanked)
|
||||
defer f.Close()
|
||||
|
||||
src := pilosa.NewBitmap(1, 2, 3)
|
||||
src := pilosa.NewRow(1, 2, 3)
|
||||
|
||||
// Set bits on the rows 100, 101, & 102.
|
||||
f.MustSetBits(100, 1, 3, 2, 200)
|
||||
|
|
@ -1104,7 +1104,7 @@ func TestFragment_Zero_Tanimoto(t *testing.T) {
|
|||
f := test.MustOpenFragment("i", "f", pilosa.ViewStandard, 0, pilosa.CacheTypeRanked)
|
||||
defer f.Close()
|
||||
|
||||
src := pilosa.NewBitmap(1, 2, 3)
|
||||
src := pilosa.NewRow(1, 2, 3)
|
||||
|
||||
// Set bits on the rows 100, 101, & 102.
|
||||
f.MustSetBits(100, 1, 3, 2, 200)
|
||||
|
|
|
|||
10
frame.go
10
frame.go
|
|
@ -718,7 +718,7 @@ func (f *Frame) SetFieldValue(columnID uint64, name string, value int64) (change
|
|||
}
|
||||
|
||||
// FieldSum returns the sum and count for a field.
|
||||
// An optional filtering bitmap can be provided.
|
||||
// An optional filtering row can be provided.
|
||||
func (f *Frame) FieldSum(filter *Row, name string) (sum, count int64, err error) {
|
||||
field := f.Field(name)
|
||||
if field == nil {
|
||||
|
|
@ -738,7 +738,7 @@ func (f *Frame) FieldSum(filter *Row, name string) (sum, count int64, err error)
|
|||
}
|
||||
|
||||
// FieldMin returns the min for a field.
|
||||
// An optional filtering bitmap can be provided.
|
||||
// An optional filtering row can be provided.
|
||||
func (f *Frame) FieldMin(filter *Row, name string) (min, count int64, err error) {
|
||||
field := f.Field(name)
|
||||
if field == nil {
|
||||
|
|
@ -758,7 +758,7 @@ func (f *Frame) FieldMin(filter *Row, name string) (min, count int64, err error)
|
|||
}
|
||||
|
||||
// FieldMax returns the max for a field.
|
||||
// An optional filtering bitmap can be provided.
|
||||
// An optional filtering row can be provided.
|
||||
func (f *Frame) FieldMax(filter *Row, name string) (max, count int64, err error) {
|
||||
field := f.Field(name)
|
||||
if field == nil {
|
||||
|
|
@ -794,7 +794,7 @@ func (f *Frame) FieldRange(name string, op pql.Token, predicate int64) (*Row, er
|
|||
|
||||
baseValue, outOfRange := field.BaseValue(op, predicate)
|
||||
if outOfRange {
|
||||
return NewBitmap(), nil
|
||||
return NewRow(), nil
|
||||
}
|
||||
|
||||
return view.FieldRange(op, field.BitDepth(), baseValue)
|
||||
|
|
@ -817,7 +817,7 @@ func (f *Frame) FieldRangeBetween(name string, predicateMin, predicateMax int64)
|
|||
|
||||
baseValueMin, baseValueMax, outOfRange := field.BaseValueBetween(predicateMin, predicateMax)
|
||||
if outOfRange {
|
||||
return NewBitmap(), nil
|
||||
return NewRow(), nil
|
||||
}
|
||||
|
||||
return view.FieldRangeBetween(field.BitDepth(), baseValueMin, baseValueMax)
|
||||
|
|
|
|||
|
|
@ -410,9 +410,9 @@ func TestHandler_Query_Bitmap_JSON(t *testing.T) {
|
|||
h.API.Cluster = test.NewCluster(1)
|
||||
h.API.Holder = hldr.Holder
|
||||
h.Executor.ExecuteFn = func(ctx context.Context, index string, query *pql.Query, slices []uint64, opt *pilosa.ExecOptions) ([]interface{}, error) {
|
||||
bm := pilosa.NewBitmap(1, 3, 66, pilosa.SliceWidth+1)
|
||||
bm.Attrs = map[string]interface{}{"a": "b", "c": 1, "d": true}
|
||||
return []interface{}{bm}, nil
|
||||
r := pilosa.NewRow(1, 3, 66, pilosa.SliceWidth+1)
|
||||
r.Attrs = map[string]interface{}{"a": "b", "c": 1, "d": true}
|
||||
return []interface{}{r}, nil
|
||||
}
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
|
@ -424,8 +424,8 @@ func TestHandler_Query_Bitmap_JSON(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure the handler can execute a query that returns a bitmap with column attributes as JSON.
|
||||
func TestHandler_Query_Bitmap_ColumnAttrs_JSON(t *testing.T) {
|
||||
// Ensure the handler can execute a query that returns a row with column attributes as JSON.
|
||||
func TestHandler_Query_Row_ColumnAttrs_JSON(t *testing.T) {
|
||||
hldr := test.NewHolder()
|
||||
defer hldr.Close()
|
||||
|
||||
|
|
@ -443,9 +443,9 @@ func TestHandler_Query_Bitmap_ColumnAttrs_JSON(t *testing.T) {
|
|||
h.API.Holder = hldr.Holder
|
||||
h.API.Cluster = test.NewCluster(1)
|
||||
h.Executor.ExecuteFn = func(ctx context.Context, index string, query *pql.Query, slices []uint64, opt *pilosa.ExecOptions) ([]interface{}, error) {
|
||||
bm := pilosa.NewBitmap(1, 3, 66, pilosa.SliceWidth+1)
|
||||
bm.Attrs = map[string]interface{}{"a": "b", "c": 1, "d": true}
|
||||
return []interface{}{bm}, nil
|
||||
r := pilosa.NewRow(1, 3, 66, pilosa.SliceWidth+1)
|
||||
r.Attrs = map[string]interface{}{"a": "b", "c": 1, "d": true}
|
||||
return []interface{}{r}, nil
|
||||
}
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
|
@ -457,8 +457,8 @@ func TestHandler_Query_Bitmap_ColumnAttrs_JSON(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure the handler can execute a query that returns a bitmap as protobuf.
|
||||
func TestHandler_Query_Bitmap_Protobuf(t *testing.T) {
|
||||
// Ensure the handler can execute a query that returns a row as protobuf.
|
||||
func TestHandler_Query_Row_Protobuf(t *testing.T) {
|
||||
hldr := test.MustOpenHolder()
|
||||
defer hldr.Close()
|
||||
|
||||
|
|
@ -466,9 +466,9 @@ func TestHandler_Query_Bitmap_Protobuf(t *testing.T) {
|
|||
h.API.Cluster = test.NewCluster(1)
|
||||
h.API.Holder = hldr.Holder
|
||||
h.Executor.ExecuteFn = func(ctx context.Context, index string, query *pql.Query, slices []uint64, opt *pilosa.ExecOptions) ([]interface{}, error) {
|
||||
bm := pilosa.NewBitmap(1, pilosa.SliceWidth+1)
|
||||
bm.Attrs = map[string]interface{}{"a": "b", "c": int64(1), "d": true}
|
||||
return []interface{}{bm}, nil
|
||||
r := pilosa.NewRow(1, pilosa.SliceWidth+1)
|
||||
r.Attrs = map[string]interface{}{"a": "b", "c": int64(1), "d": true}
|
||||
return []interface{}{r}, nil
|
||||
}
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
|
@ -497,8 +497,8 @@ func TestHandler_Query_Bitmap_Protobuf(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure the handler can execute a query that returns a bitmap with column attributes as protobuf.
|
||||
func TestHandler_Query_Bitmap_ColumnAttrs_Protobuf(t *testing.T) {
|
||||
// Ensure the handler can execute a query that returns a row with column attributes as protobuf.
|
||||
func TestHandler_Query_Row_ColumnAttrs_Protobuf(t *testing.T) {
|
||||
hldr := test.NewHolder()
|
||||
defer hldr.Close()
|
||||
|
||||
|
|
@ -514,9 +514,9 @@ func TestHandler_Query_Bitmap_ColumnAttrs_Protobuf(t *testing.T) {
|
|||
h.API.Holder = hldr.Holder
|
||||
h.API.Cluster = test.NewCluster(1)
|
||||
h.Executor.ExecuteFn = func(ctx context.Context, index string, query *pql.Query, slices []uint64, opt *pilosa.ExecOptions) ([]interface{}, error) {
|
||||
bm := pilosa.NewBitmap(1, pilosa.SliceWidth+1)
|
||||
bm.Attrs = map[string]interface{}{"a": "b", "c": int64(1), "d": true}
|
||||
return []interface{}{bm}, nil
|
||||
r := pilosa.NewRow(1, pilosa.SliceWidth+1)
|
||||
r.Attrs = map[string]interface{}{"a": "b", "c": int64(1), "d": true}
|
||||
return []interface{}{r}, nil
|
||||
}
|
||||
|
||||
// Encode request body.
|
||||
|
|
|
|||
|
|
@ -30,20 +30,20 @@ type Row struct {
|
|||
Attrs map[string]interface{}
|
||||
}
|
||||
|
||||
// NewBitmap returns a new instance of Bitmap.
|
||||
func NewBitmap(bits ...uint64) *Row {
|
||||
bm := &Row{}
|
||||
// NewRow returns a new instance of Row.
|
||||
func NewRow(bits ...uint64) *Row {
|
||||
r := &Row{}
|
||||
for _, i := range bits {
|
||||
bm.SetBit(i)
|
||||
r.SetBit(i)
|
||||
}
|
||||
return bm
|
||||
return r
|
||||
}
|
||||
|
||||
// Merge merges data from other into b.
|
||||
func (b *Row) Merge(other *Row) {
|
||||
// Merge merges data from other into r.
|
||||
func (r *Row) Merge(other *Row) {
|
||||
var segments []BitmapSegment
|
||||
|
||||
itr := newMergeSegmentIterator(b.segments, other.segments)
|
||||
itr := newMergeSegmentIterator(r.segments, other.segments)
|
||||
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
|
||||
// Use the other bitmap's data if segment is missing.
|
||||
if s0 == nil {
|
||||
|
|
@ -59,15 +59,15 @@ func (b *Row) Merge(other *Row) {
|
|||
segments = append(segments, *s0)
|
||||
}
|
||||
|
||||
b.segments = segments
|
||||
b.InvalidateCount()
|
||||
r.segments = segments
|
||||
r.InvalidateCount()
|
||||
}
|
||||
|
||||
// IntersectionCount returns the number of intersections between b and other.
|
||||
func (b *Row) IntersectionCount(other *Row) uint64 {
|
||||
// IntersectionCount returns the number of intersections between r and other.
|
||||
func (r *Row) IntersectionCount(other *Row) uint64 {
|
||||
var n uint64
|
||||
|
||||
itr := newMergeSegmentIterator(b.segments, other.segments)
|
||||
itr := newMergeSegmentIterator(r.segments, other.segments)
|
||||
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
|
||||
// Ignore non-overlapping segments.
|
||||
if s0 == nil || s1 == nil {
|
||||
|
|
@ -79,11 +79,11 @@ func (b *Row) IntersectionCount(other *Row) uint64 {
|
|||
return n
|
||||
}
|
||||
|
||||
// Intersect returns the itersection of b and other.
|
||||
func (b *Row) Intersect(other *Row) *Row {
|
||||
// Intersect returns the itersection of r and other.
|
||||
func (r *Row) Intersect(other *Row) *Row {
|
||||
var segments []BitmapSegment
|
||||
|
||||
itr := newMergeSegmentIterator(b.segments, other.segments)
|
||||
itr := newMergeSegmentIterator(r.segments, other.segments)
|
||||
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
|
||||
// Ignore non-overlapping segments.
|
||||
if s0 == nil || s1 == nil {
|
||||
|
|
@ -95,11 +95,11 @@ func (b *Row) Intersect(other *Row) *Row {
|
|||
return &Row{segments: segments}
|
||||
}
|
||||
|
||||
// Xor returns the xor of b and other.
|
||||
func (b *Row) Xor(other *Row) *Row {
|
||||
// Xor returns the xor of r and other.
|
||||
func (r *Row) Xor(other *Row) *Row {
|
||||
var segments []BitmapSegment
|
||||
|
||||
itr := newMergeSegmentIterator(b.segments, other.segments)
|
||||
itr := newMergeSegmentIterator(r.segments, other.segments)
|
||||
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
|
||||
if s1 == nil {
|
||||
segments = append(segments, *s0)
|
||||
|
|
@ -115,10 +115,10 @@ func (b *Row) Xor(other *Row) *Row {
|
|||
return &Row{segments: segments}
|
||||
}
|
||||
|
||||
// Union returns the bitwise union of b and other.
|
||||
func (b *Row) Union(other *Row) *Row {
|
||||
// Union returns the bitwise union of r and other.
|
||||
func (r *Row) Union(other *Row) *Row {
|
||||
var segments []BitmapSegment
|
||||
itr := newMergeSegmentIterator(b.segments, other.segments)
|
||||
itr := newMergeSegmentIterator(r.segments, other.segments)
|
||||
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
|
||||
if s1 == nil {
|
||||
segments = append(segments, *s0)
|
||||
|
|
@ -133,11 +133,11 @@ func (b *Row) Union(other *Row) *Row {
|
|||
return &Row{segments: segments}
|
||||
}
|
||||
|
||||
// Difference returns the diff of b and other.
|
||||
func (b *Row) Difference(other *Row) *Row {
|
||||
// Difference returns the diff of r and other.
|
||||
func (r *Row) Difference(other *Row) *Row {
|
||||
var segments []BitmapSegment
|
||||
|
||||
itr := newMergeSegmentIterator(b.segments, other.segments)
|
||||
itr := newMergeSegmentIterator(r.segments, other.segments)
|
||||
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
|
||||
if s0 == nil {
|
||||
continue
|
||||
|
|
@ -151,14 +151,14 @@ func (b *Row) Difference(other *Row) *Row {
|
|||
return &Row{segments: segments}
|
||||
}
|
||||
|
||||
// SetBit sets the i-th bit of the bitmap.
|
||||
func (b *Row) SetBit(i uint64) (changed bool) {
|
||||
return b.createSegmentIfNotExists(i / SliceWidth).SetBit(i)
|
||||
// SetBit sets the i-th bit of the row.
|
||||
func (r *Row) SetBit(i uint64) (changed bool) {
|
||||
return r.createSegmentIfNotExists(i / SliceWidth).SetBit(i)
|
||||
}
|
||||
|
||||
// ClearBit clears the i-th bit of the bitmap.
|
||||
func (b *Row) ClearBit(i uint64) (changed bool) {
|
||||
s := b.segment(i / SliceWidth)
|
||||
func (r *Row) ClearBit(i uint64) (changed bool) {
|
||||
s := r.segment(i / SliceWidth)
|
||||
if s == nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -167,49 +167,49 @@ func (b *Row) ClearBit(i uint64) (changed bool) {
|
|||
|
||||
// segment returns a segment for a given slice.
|
||||
// Returns nil if segment does not exist.
|
||||
func (b *Row) segment(slice uint64) *BitmapSegment {
|
||||
if i := sort.Search(len(b.segments), func(i int) bool {
|
||||
return b.segments[i].slice >= slice
|
||||
}); i < len(b.segments) && b.segments[i].slice == slice {
|
||||
return &b.segments[i]
|
||||
func (r *Row) segment(slice uint64) *BitmapSegment {
|
||||
if i := sort.Search(len(r.segments), func(i int) bool {
|
||||
return r.segments[i].slice >= slice
|
||||
}); i < len(r.segments) && r.segments[i].slice == slice {
|
||||
return &r.segments[i]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Row) createSegmentIfNotExists(slice uint64) *BitmapSegment {
|
||||
i := sort.Search(len(b.segments), func(i int) bool {
|
||||
return b.segments[i].slice >= slice
|
||||
func (r *Row) createSegmentIfNotExists(slice uint64) *BitmapSegment {
|
||||
i := sort.Search(len(r.segments), func(i int) bool {
|
||||
return r.segments[i].slice >= slice
|
||||
})
|
||||
|
||||
// Return exact match.
|
||||
if i < len(b.segments) && b.segments[i].slice == slice {
|
||||
return &b.segments[i]
|
||||
if i < len(r.segments) && r.segments[i].slice == slice {
|
||||
return &r.segments[i]
|
||||
}
|
||||
|
||||
// Insert new segment.
|
||||
b.segments = append(b.segments, BitmapSegment{data: *roaring.NewBitmap()})
|
||||
if i < len(b.segments) {
|
||||
copy(b.segments[i+1:], b.segments[i:])
|
||||
r.segments = append(r.segments, BitmapSegment{data: *roaring.NewBitmap()})
|
||||
if i < len(r.segments) {
|
||||
copy(r.segments[i+1:], r.segments[i:])
|
||||
}
|
||||
b.segments[i] = BitmapSegment{
|
||||
r.segments[i] = BitmapSegment{
|
||||
data: *roaring.NewBitmap(),
|
||||
slice: slice,
|
||||
writable: true,
|
||||
}
|
||||
|
||||
return &b.segments[i]
|
||||
return &r.segments[i]
|
||||
}
|
||||
|
||||
// InvalidateCount updates the cached count in the bitmap.
|
||||
func (b *Row) InvalidateCount() {
|
||||
for i := range b.segments {
|
||||
b.segments[i].InvalidateCount()
|
||||
func (r *Row) InvalidateCount() {
|
||||
for i := range r.segments {
|
||||
r.segments[i].InvalidateCount()
|
||||
}
|
||||
}
|
||||
|
||||
// IncrementCount increments the bitmap cached counter, note this is an optimization that assumes that the caller is aware the size increased.
|
||||
func (b *Row) IncrementCount(i uint64) {
|
||||
seg := b.segment(i / SliceWidth)
|
||||
func (r *Row) IncrementCount(i uint64) {
|
||||
seg := r.segment(i / SliceWidth)
|
||||
if seg != nil {
|
||||
seg.n++
|
||||
}
|
||||
|
|
@ -217,8 +217,8 @@ func (b *Row) IncrementCount(i uint64) {
|
|||
}
|
||||
|
||||
// DecrementCount decrements the bitmap cached counter.
|
||||
func (b *Row) DecrementCount(i uint64) {
|
||||
seg := b.segment(i / SliceWidth)
|
||||
func (r *Row) DecrementCount(i uint64) {
|
||||
seg := r.segment(i / SliceWidth)
|
||||
if seg != nil {
|
||||
if seg.n > 0 {
|
||||
seg.n--
|
||||
|
|
@ -226,24 +226,24 @@ func (b *Row) DecrementCount(i uint64) {
|
|||
}
|
||||
}
|
||||
|
||||
// Count returns the number of set bits in the bitmap.
|
||||
func (b *Row) Count() uint64 {
|
||||
// Count returns the number of set bits in the row.
|
||||
func (r *Row) Count() uint64 {
|
||||
var n uint64
|
||||
for i := range b.segments {
|
||||
n += b.segments[i].Count()
|
||||
for i := range r.segments {
|
||||
n += r.segments[i].Count()
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// MarshalJSON returns a JSON-encoded byte slice of b.
|
||||
func (b *Row) MarshalJSON() ([]byte, error) {
|
||||
// MarshalJSON returns a JSON-encoded byte slice of r.
|
||||
func (r *Row) MarshalJSON() ([]byte, error) {
|
||||
var o struct {
|
||||
Attrs map[string]interface{} `json:"attrs"`
|
||||
Bits []uint64 `json:"bits"`
|
||||
}
|
||||
o.Bits = b.Bits()
|
||||
o.Bits = r.Bits()
|
||||
|
||||
o.Attrs = b.Attrs
|
||||
o.Attrs = r.Attrs
|
||||
if o.Attrs == nil {
|
||||
o.Attrs = make(map[string]interface{})
|
||||
}
|
||||
|
|
@ -251,46 +251,46 @@ func (b *Row) MarshalJSON() ([]byte, error) {
|
|||
return json.Marshal(&o)
|
||||
}
|
||||
|
||||
// Bits returns the bits in b as a slice of ints.
|
||||
func (b *Row) Bits() []uint64 {
|
||||
a := make([]uint64, 0, b.Count())
|
||||
for i := range b.segments {
|
||||
a = append(a, b.segments[i].Bits()...)
|
||||
// Bits returns the bits in r as a slice of ints.
|
||||
func (r *Row) Bits() []uint64 {
|
||||
a := make([]uint64, 0, r.Count())
|
||||
for i := range r.segments {
|
||||
a = append(a, r.segments[i].Bits()...)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// encodeBitmap converts b into its internal representation.
|
||||
func encodeBitmap(b *Row) *internal.Bitmap {
|
||||
if b == nil {
|
||||
// encodeBitmap converts r into its internal representation.
|
||||
func encodeBitmap(r *Row) *internal.Bitmap {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &internal.Bitmap{
|
||||
Bits: b.Bits(),
|
||||
Attrs: encodeAttrs(b.Attrs),
|
||||
Bits: r.Bits(),
|
||||
Attrs: encodeAttrs(r.Attrs),
|
||||
}
|
||||
}
|
||||
|
||||
// decodeBitmap converts b from its internal representation.
|
||||
func decodeBitmap(pb *internal.Bitmap) *Row {
|
||||
if pb == nil {
|
||||
// decodeBitmap converts r from its internal representation.
|
||||
func decodeBitmap(pr *internal.Bitmap) *Row {
|
||||
if pr == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
b := NewBitmap()
|
||||
b.Attrs = decodeAttrs(pb.Attrs)
|
||||
for _, v := range pb.Bits {
|
||||
b.SetBit(v)
|
||||
r := NewRow()
|
||||
r.Attrs = decodeAttrs(pr.Attrs)
|
||||
for _, v := range pr.Bits {
|
||||
r.SetBit(v)
|
||||
}
|
||||
return b
|
||||
return r
|
||||
}
|
||||
|
||||
// Union performs a union on a slice of bitmaps.
|
||||
func Union(bitmaps []*Row) *Row {
|
||||
other := bitmaps[0]
|
||||
for _, bm := range bitmaps[1:] {
|
||||
other = other.Union(bm)
|
||||
// Union performs a union on a slice of rows.
|
||||
func Union(rows []*Row) *Row {
|
||||
other := rows[0]
|
||||
for _, r := range rows[1:] {
|
||||
other = other.Union(r)
|
||||
}
|
||||
return other
|
||||
}
|
||||
|
|
@ -22,45 +22,45 @@ import (
|
|||
"github.com/pilosa/pilosa"
|
||||
)
|
||||
|
||||
// Ensure a bitmap can be merged
|
||||
func TestBitmap_Merge(t *testing.T) {
|
||||
// Ensure a row can be merged
|
||||
func TestRow_Merge(t *testing.T) {
|
||||
tests := []struct {
|
||||
bm1 *pilosa.Row
|
||||
bm2 *pilosa.Row
|
||||
r1 *pilosa.Row
|
||||
r2 *pilosa.Row
|
||||
exp uint64
|
||||
}{
|
||||
{
|
||||
bm1: pilosa.NewBitmap(1, 2, 3, SliceWidth+1, 2*SliceWidth),
|
||||
bm2: pilosa.NewBitmap(3, 4, 5),
|
||||
r1: pilosa.NewRow(1, 2, 3, SliceWidth+1, 2*SliceWidth),
|
||||
r2: pilosa.NewRow(3, 4, 5),
|
||||
exp: 7,
|
||||
},
|
||||
{
|
||||
bm1: pilosa.NewBitmap(),
|
||||
bm2: pilosa.NewBitmap(2, 66000, 70000, 70001, 70002, 70003, 70004),
|
||||
r1: pilosa.NewRow(),
|
||||
r2: pilosa.NewRow(2, 66000, 70000, 70001, 70002, 70003, 70004),
|
||||
exp: 7,
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
t.Run(fmt.Sprintf("#%d:", i), func(t *testing.T) {
|
||||
test.bm1.Merge(test.bm2)
|
||||
if cnt := test.bm1.Count(); cnt != test.exp {
|
||||
test.r1.Merge(test.r2)
|
||||
if cnt := test.r1.Count(); cnt != test.exp {
|
||||
t.Fatalf("merged count %d is not %d", cnt, test.exp)
|
||||
}
|
||||
if length := len(test.bm1.Bits()); uint64(length) != test.exp {
|
||||
if length := len(test.r1.Bits()); uint64(length) != test.exp {
|
||||
t.Fatalf("merged length %d is not %d", length, test.exp)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure a bitmap can Xor'ed
|
||||
func TestBitmap_Xor(t *testing.T) {
|
||||
bm1 := pilosa.NewBitmap(0, 1, SliceWidth)
|
||||
bm2 := pilosa.NewBitmap(0, 2*SliceWidth)
|
||||
// Ensure a row can Xor'ed
|
||||
func TestRow_Xor(t *testing.T) {
|
||||
r1 := pilosa.NewRow(0, 1, SliceWidth)
|
||||
r2 := pilosa.NewRow(0, 2*SliceWidth)
|
||||
exp := []uint64{1, SliceWidth, 2 * SliceWidth}
|
||||
|
||||
res := bm1.Xor(bm2)
|
||||
res := r1.Xor(r2)
|
||||
if res.Count() != 3 {
|
||||
t.Fatalf("Test 1 Count after xor %d != 3\n", res.Count())
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ func TestBitmap_Xor(t *testing.T) {
|
|||
if !reflect.DeepEqual(res.Bits(), exp) {
|
||||
t.Fatalf("Test 2 Results %v != expected %v\n", res.Bits(), exp)
|
||||
}
|
||||
res = bm2.Xor(bm1)
|
||||
res = r2.Xor(r1)
|
||||
if res.Count() != 3 {
|
||||
t.Fatalf("Test 3 Count after xor %d != 3\n", res.Count())
|
||||
}
|
||||
|
|
@ -77,11 +77,11 @@ func TestBitmap_Xor(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
func TestBitmap_Union_Segment(t *testing.T) {
|
||||
bm1 := pilosa.NewBitmap(0, 1, SliceWidth)
|
||||
bm2 := pilosa.NewBitmap(0, 2*SliceWidth)
|
||||
func TestRow_Union_Segment(t *testing.T) {
|
||||
r1 := pilosa.NewRow(0, 1, SliceWidth)
|
||||
r2 := pilosa.NewRow(0, 2*SliceWidth)
|
||||
exp := []uint64{0, 1, SliceWidth, 2 * SliceWidth}
|
||||
res := bm1.Union(bm2)
|
||||
res := r1.Union(r2)
|
||||
|
||||
if res.Count() != 4 {
|
||||
t.Fatalf("Test 1 Count after Union %d != 5\n", res.Count())
|
||||
|
|
@ -89,7 +89,7 @@ func TestBitmap_Union_Segment(t *testing.T) {
|
|||
if !reflect.DeepEqual(res.Bits(), exp) {
|
||||
t.Fatalf("Test 2 Union Results %v != expected %v\n", res.Bits(), exp)
|
||||
}
|
||||
res = bm2.Union(bm1)
|
||||
res = r2.Union(r1)
|
||||
if res.Count() != 4 {
|
||||
t.Fatalf("Test 3 Count after xor %d != 5\n", res.Count())
|
||||
}
|
||||
|
|
@ -98,11 +98,11 @@ func TestBitmap_Union_Segment(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBitmap_Difference_Segment(t *testing.T) {
|
||||
bm1 := pilosa.NewBitmap(0, 1, SliceWidth)
|
||||
bm2 := pilosa.NewBitmap(0, 2*SliceWidth)
|
||||
func TestRow_Difference_Segment(t *testing.T) {
|
||||
r1 := pilosa.NewRow(0, 1, SliceWidth)
|
||||
r2 := pilosa.NewRow(0, 2*SliceWidth)
|
||||
exp := []uint64{1, SliceWidth}
|
||||
res := bm1.Difference(bm2)
|
||||
res := r1.Difference(r2)
|
||||
|
||||
if res.Count() != 2 {
|
||||
t.Fatalf("Test 1 Count after Difference %d != 5\n", res.Count())
|
||||
14
view.go
14
view.go
|
|
@ -401,31 +401,31 @@ func (v *View) FieldMax(filter *Row, bitDepth uint) (max, count uint64, err erro
|
|||
return max, count, nil
|
||||
}
|
||||
|
||||
// FieldRange returns bitmaps with a field value encoding matching the predicate.
|
||||
// FieldRange returns rows with a field value encoding matching the predicate.
|
||||
func (v *View) FieldRange(op pql.Token, bitDepth uint, predicate uint64) (*Row, error) {
|
||||
bm := NewBitmap()
|
||||
r := NewRow()
|
||||
for _, frag := range v.Fragments() {
|
||||
other, err := frag.FieldRange(op, bitDepth, predicate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bm = bm.Union(other)
|
||||
r = r.Union(other)
|
||||
}
|
||||
return bm, nil
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// FieldRangeBetween returns bitmaps with a field value encoding matching any
|
||||
// value between predicateMin and predicateMax.
|
||||
func (v *View) FieldRangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) {
|
||||
bm := NewBitmap()
|
||||
r := NewRow()
|
||||
for _, frag := range v.Fragments() {
|
||||
other, err := frag.FieldRangeBetween(bitDepth, predicateMin, predicateMax)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bm = bm.Union(other)
|
||||
r = r.Union(other)
|
||||
}
|
||||
return bm, nil
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// IsInverseView returns true if the view is used for storing an inverted representation.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue