Keep sequence projection storage proportional to assigned items
This commit is contained in:
49
internal/engine/sequence_projection_test.go
Normal file
49
internal/engine/sequence_projection_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package engine
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSparseSequenceProjectionIndexesOnlyAssignedPositions(t *testing.T) {
|
||||
index := newSequenceItemProjectionIndex([]sequenceItemProjection{
|
||||
{inputIndex: 0, outputIndex: 9000}, {inputIndex: 3000, outputIndex: 2},
|
||||
})
|
||||
if len(index.outputByInput) != 2 || len(index.inputByOutput) != 2 {
|
||||
t.Fatal("sparse projection retained unassigned positions")
|
||||
}
|
||||
for input, output := range map[int]int{0: 9000, 3000: 2} {
|
||||
if got, found := index.outputForInput(input); !found || got != output {
|
||||
t.Fatalf("input %d = %d, %t", input, got, found)
|
||||
}
|
||||
if got, found := index.inputForOutput(output); !found || got != input {
|
||||
t.Fatalf("output %d = %d, %t", output, got, found)
|
||||
}
|
||||
}
|
||||
for _, position := range []int{-1, 1, 10000} {
|
||||
if _, found := index.outputForInput(position); found {
|
||||
t.Fatalf("unassigned input %d exists", position)
|
||||
}
|
||||
if _, found := index.inputForOutput(position); found {
|
||||
t.Fatalf("unassigned output %d exists", position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestContiguousSequenceRangesKeepArithmeticLookup(t *testing.T) {
|
||||
ranges := make([]sequenceRange, 128)
|
||||
for position := range ranges {
|
||||
ranges[position] = sequenceRange{sourceIndex: position, path: Keys("items"), start: position, end: position + 1}
|
||||
}
|
||||
for _, assigned := range indexSequenceRanges(ranges) {
|
||||
if len(assigned.projection.outputByInput) != 0 || len(assigned.projection.inputByOutput) != 0 {
|
||||
t.Fatal("contiguous range materialized a projection index")
|
||||
}
|
||||
if output, found := assigned.outputForInput(0); !found || output != assigned.start {
|
||||
t.Fatal("arithmetic forward lookup lost its offset")
|
||||
}
|
||||
if input, found := assigned.inputForOutput(assigned.start); !found || input != 0 {
|
||||
t.Fatal("arithmetic reverse lookup lost its offset")
|
||||
}
|
||||
if _, found := assigned.inputForOutput(assigned.end); found {
|
||||
t.Fatal("range includes its exclusive end")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user