Keep sequence projection storage proportional to assigned items
This commit is contained in:
@@ -1,33 +1,17 @@
|
||||
package engine
|
||||
|
||||
type sequenceItemProjectionIndex struct {
|
||||
outputByInput []int
|
||||
inputByOutput []int
|
||||
outputByInput map[int]int
|
||||
inputByOutput map[int]int
|
||||
}
|
||||
|
||||
func newSequenceItemProjectionIndex(projections []sequenceItemProjection) sequenceItemProjectionIndex {
|
||||
maxInput := -1
|
||||
maxOutput := -1
|
||||
for _, projection := range projections {
|
||||
if projection.inputIndex > maxInput {
|
||||
maxInput = projection.inputIndex
|
||||
}
|
||||
if projection.outputIndex > maxOutput {
|
||||
maxOutput = projection.outputIndex
|
||||
}
|
||||
}
|
||||
index := sequenceItemProjectionIndex{
|
||||
outputByInput: make([]int, maxInput+1),
|
||||
inputByOutput: make([]int, maxOutput+1),
|
||||
}
|
||||
for input := range index.outputByInput {
|
||||
index.outputByInput[input] = -1
|
||||
}
|
||||
for output := range index.inputByOutput {
|
||||
index.inputByOutput[output] = -1
|
||||
outputByInput: make(map[int]int, len(projections)),
|
||||
inputByOutput: make(map[int]int, len(projections)),
|
||||
}
|
||||
for _, projection := range projections {
|
||||
if projection.inputIndex >= 0 && projection.inputIndex < len(index.outputByInput) && projection.outputIndex >= 0 && projection.outputIndex < len(index.inputByOutput) {
|
||||
if projection.inputIndex >= 0 && projection.outputIndex >= 0 {
|
||||
index.outputByInput[projection.inputIndex] = projection.outputIndex
|
||||
index.inputByOutput[projection.outputIndex] = projection.inputIndex
|
||||
}
|
||||
@@ -36,15 +20,11 @@ func newSequenceItemProjectionIndex(projections []sequenceItemProjection) sequen
|
||||
}
|
||||
|
||||
func (index sequenceItemProjectionIndex) outputForInput(inputIndex int) (int, bool) {
|
||||
if inputIndex < 0 || inputIndex >= len(index.outputByInput) || index.outputByInput[inputIndex] < 0 {
|
||||
return 0, false
|
||||
}
|
||||
return index.outputByInput[inputIndex], true
|
||||
output, found := index.outputByInput[inputIndex]
|
||||
return output, found
|
||||
}
|
||||
|
||||
func (index sequenceItemProjectionIndex) inputForOutput(outputIndex int) (int, bool) {
|
||||
if outputIndex < 0 || outputIndex >= len(index.inputByOutput) || index.inputByOutput[outputIndex] < 0 {
|
||||
return 0, false
|
||||
}
|
||||
return index.inputByOutput[outputIndex], true
|
||||
input, found := index.inputByOutput[outputIndex]
|
||||
return input, found
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user