Prepare occurrence chronology keys before sorting
This commit is contained in:
@@ -93,8 +93,10 @@ func (n *Normalizer) PrepareNormalize(ctx context.Context, req contracts.Normali
|
||||
}
|
||||
|
||||
type normalizedRecord struct {
|
||||
occurrence dnd.NPCOccurrence
|
||||
inputIndex int
|
||||
occurrence dnd.NPCOccurrence
|
||||
inputIndex int
|
||||
earliest int
|
||||
hasEvidence bool
|
||||
}
|
||||
|
||||
func normalizeList(input dnd.NPCOccurrenceList, documentIndex source.DocumentIndex, order shared.SourceRefOrder, registry *npcregistry.Registry) (dnd.NPCOccurrenceList, []diagnostics.Finding, error) {
|
||||
@@ -109,7 +111,8 @@ func normalizeList(input dnd.NPCOccurrenceList, documentIndex source.DocumentInd
|
||||
if err != nil {
|
||||
return dnd.NPCOccurrenceList{}, nil, fmt.Errorf("occurrences[%d]: %w", index, err)
|
||||
}
|
||||
records[index] = normalizedRecord{occurrence: occurrence, inputIndex: index}
|
||||
earliest, hasEvidence := order.EarliestValid(occurrence.SourceRefs)
|
||||
records[index] = normalizedRecord{occurrence: occurrence, inputIndex: index, earliest: earliest, hasEvidence: hasEvidence}
|
||||
if refsChanged {
|
||||
findings = append(findings, diagnostics.Finding{
|
||||
Scope: occurrenceScope(index),
|
||||
@@ -121,7 +124,14 @@ func normalizeList(input dnd.NPCOccurrenceList, documentIndex source.DocumentInd
|
||||
}
|
||||
|
||||
sort.SliceStable(records, func(left, right int) bool {
|
||||
return occurrencemodel.Less(order, records[left].occurrence, records[right].occurrence)
|
||||
l, r := records[left], records[right]
|
||||
if l.hasEvidence != r.hasEvidence {
|
||||
return l.hasEvidence
|
||||
}
|
||||
if l.hasEvidence && l.earliest != r.earliest {
|
||||
return l.earliest < r.earliest
|
||||
}
|
||||
return occurrencemodel.LessAfterEvidence(order, l.occurrence, r.occurrence)
|
||||
})
|
||||
for position, record := range records {
|
||||
if position == record.inputIndex {
|
||||
|
||||
Reference in New Issue
Block a user