Index inherited step membership
This commit is contained in:
@@ -2,6 +2,7 @@ package engine
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ConfigKit/internal/document"
|
||||
)
|
||||
@@ -74,10 +75,44 @@ func copyInheritanceSubtree(target, incoming map[string]Origin, node *document.N
|
||||
})
|
||||
}
|
||||
|
||||
type inheritanceStepKey struct {
|
||||
from string
|
||||
to string
|
||||
reference string
|
||||
locations string
|
||||
}
|
||||
|
||||
func inheritanceStepKeyForPaths(from, to, reference Path, locations []Location) inheritanceStepKey {
|
||||
return inheritanceStepKey{
|
||||
from: from.String(), to: to.String(), reference: reference.String(),
|
||||
locations: inheritanceLocationsKey(locations),
|
||||
}
|
||||
}
|
||||
|
||||
func inheritanceLocationsKey(locations []Location) string {
|
||||
encoded := strconv.AppendInt(nil, int64(len(locations)), 10)
|
||||
encoded = append(encoded, ';')
|
||||
for _, location := range locations {
|
||||
encoded = strconv.AppendInt(encoded, int64(len(location.SourceID)), 10)
|
||||
encoded = append(encoded, ':')
|
||||
encoded = append(encoded, location.SourceID...)
|
||||
encoded = append(encoded, ';')
|
||||
encoded = strconv.AppendInt(encoded, int64(location.Line), 10)
|
||||
encoded = append(encoded, ';')
|
||||
encoded = strconv.AppendInt(encoded, int64(location.Column), 10)
|
||||
encoded = append(encoded, ';')
|
||||
}
|
||||
return string(encoded)
|
||||
}
|
||||
|
||||
// Materialize concrete steps only for an inspection record. The linked private
|
||||
// traces remain compact when one parent supplies many descendant values.
|
||||
func projectInheritanceSteps(origin Origin) []InheritanceStep {
|
||||
steps := cloneInheritanceSteps(origin.Inheritance)
|
||||
seen := make(map[inheritanceStepKey]struct{}, len(steps))
|
||||
for _, step := range steps {
|
||||
seen[inheritanceStepKeyForPaths(step.From, step.To, step.Reference, step.Locations)] = struct{}{}
|
||||
}
|
||||
for _, contributor := range origin.contributors {
|
||||
var reverse []*inheritanceTrace
|
||||
for link := contributor.trace; link != nil; link = link.previous {
|
||||
@@ -91,17 +126,13 @@ func projectInheritanceSteps(origin Origin) []InheritanceStep {
|
||||
continue
|
||||
}
|
||||
next := appendInheritancePath(transfer.to, relative)
|
||||
step := InheritanceStep{
|
||||
From: current.clone(), To: next.clone(), Reference: transfer.reference.clone(),
|
||||
Locations: cloneLocations(transfer.locations),
|
||||
}
|
||||
if !slices.ContainsFunc(steps, func(existing InheritanceStep) bool {
|
||||
return existing.From.String() == step.From.String() &&
|
||||
existing.To.String() == step.To.String() &&
|
||||
existing.Reference.String() == step.Reference.String() &&
|
||||
slices.Equal(existing.Locations, step.Locations)
|
||||
}) {
|
||||
steps = append(steps, step)
|
||||
key := inheritanceStepKeyForPaths(current, next, transfer.reference, transfer.locations)
|
||||
if _, found := seen[key]; !found {
|
||||
seen[key] = struct{}{}
|
||||
steps = append(steps, InheritanceStep{
|
||||
From: current.clone(), To: next.clone(), Reference: transfer.reference.clone(),
|
||||
Locations: cloneLocations(transfer.locations),
|
||||
})
|
||||
}
|
||||
current = next
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user