mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-30 10:45:18 -06:00
Merge pull request #777 from cmasone-attic/depanic
Implement compoundSet.Filter()
This commit is contained in:
@@ -113,7 +113,16 @@ func (cs compoundSet) Subtract(others ...Set) Set {
|
||||
}
|
||||
|
||||
func (cs compoundSet) Filter(cb setFilterCallback) Set {
|
||||
panic("not implemented")
|
||||
seq := newEmptySequenceChunker(makeSetLeafChunkFn(cs.t, cs.cs), newSetMetaSequenceChunkFn(cs.t, cs.cs), newSetLeafBoundaryChecker(), newOrderedMetaSequenceBoundaryChecker)
|
||||
|
||||
cs.IterAll(func(v Value) {
|
||||
if cb(v) {
|
||||
seq.Append(v)
|
||||
}
|
||||
})
|
||||
|
||||
s := seq.Done()
|
||||
return internalValueFromType(s, s.Type()).(Set)
|
||||
}
|
||||
|
||||
func (cs compoundSet) findLeaf(key Value) (*sequenceCursor, setLeaf, int) {
|
||||
|
||||
@@ -255,3 +255,29 @@ func TestCompoundSetRemoveNonexistentValue(t *testing.T) {
|
||||
assert.Equal(original.Len(), actual.Len())
|
||||
assert.True(original.Equals(actual))
|
||||
}
|
||||
|
||||
func TestCompoundSetFilter(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
doTest := func(ts testSet) {
|
||||
set := ts.toCompoundSet(chunks.NewMemoryStore())
|
||||
sort.Sort(ts)
|
||||
pivotPoint := 10
|
||||
pivot := ts.values[pivotPoint]
|
||||
actual := set.Filter(func(v Value) bool {
|
||||
return ts.less(v, pivot)
|
||||
})
|
||||
assert.True(newTypedSet(set.cs, set.t, ts.values[:pivotPoint+1]...).Equals(actual))
|
||||
|
||||
idx := 0
|
||||
actual.IterAll(func(v Value) {
|
||||
assert.True(ts.values[idx].Equals(v), "%v != %v", v, ts.values[idx])
|
||||
idx++
|
||||
})
|
||||
}
|
||||
|
||||
doTest(getTestNativeOrderSet())
|
||||
doTest(getTestRefValueOrderSet())
|
||||
doTest(getTestRefToNativeOrderSet())
|
||||
doTest(getTestRefToValueOrderSet())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user