Index resolution metadata updates
This commit is contained in:
@@ -361,12 +361,30 @@ func newResolutionCoverageIndexFromRecords(records []*resolutionRecord) *resolut
|
||||
return index
|
||||
}
|
||||
|
||||
func newResolutionCoverageIndexFromSnapshots(snapshots []resolutionSnapshot) (*resolutionCoverageIndex, []string) {
|
||||
index := &resolutionCoverageIndex{depths: make([]int, len(snapshots))}
|
||||
pointers := make([]string, len(snapshots))
|
||||
for id, snapshot := range snapshots {
|
||||
path := snapshot.change.Path
|
||||
index.depths[id] = len(path.segments)
|
||||
pointers[id] = path.String()
|
||||
if path.valid() {
|
||||
index.prefix.insert(pointers[id], id)
|
||||
}
|
||||
}
|
||||
return index, pointers
|
||||
}
|
||||
|
||||
func (index *resolutionCoverageIndex) deepestCoveringID(path Path) (int, bool) {
|
||||
if !path.valid() {
|
||||
return 0, false
|
||||
}
|
||||
return index.deepestCoveringPointerID(path.String())
|
||||
}
|
||||
|
||||
func (index *resolutionCoverageIndex) deepestCoveringPointerID(pointer string) (int, bool) {
|
||||
bestID, bestDepth, found := 0, -1, false
|
||||
index.prefix.visitAncestors(path.String(), func(id int) {
|
||||
index.prefix.visitAncestors(pointer, func(id int) {
|
||||
depth := index.depths[id]
|
||||
if !found || depth > bestDepth || (depth == bestDepth && id < bestID) {
|
||||
bestID, bestDepth, found = id, depth, true
|
||||
|
||||
Reference in New Issue
Block a user