Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ export class SearchNode {
*/
private _inputCost?: number;

/**
* Counts the number of delete edits modeled directly after insert edits in
* this SearchNode's path. Such a sequence shows up within the calculation
* matrix as a substitution rather than two separate edits; we use this count
* to adjust accordingly.
*/
private readonly deleteAfterInsertEditPairs: number;

/**
* A unique identifier corresponding to the earliest SearchPath containing
* the correction-search graph edge represented by this instance.
Expand Down Expand Up @@ -164,6 +172,8 @@ export class SearchNode {
this.matchedTraversals = priorNode.matchedTraversals.slice();

this.lastEdgeType = param2 as PathEdge;
const isInsertAfterDelete = priorNode.lastEdgeType == PathEdge.INSERTION && this.lastEdgeType == PathEdge.DELETION;
this.deleteAfterInsertEditPairs = priorNode.deleteAfterInsertEditPairs + (isInsertAfterDelete ? 1 : 0);

// Do NOT copy over _inputCost; this is a helper-constructor for methods
// building new nodes... which will have a different cost.
Expand All @@ -180,6 +190,7 @@ export class SearchNode {
this.toKey = toKey || (x => x);
this.spaceId = spaceId;
this.lastEdgeType = PathEdge.ROOT;
this.deleteAfterInsertEditPairs = 0;
}
}

Expand All @@ -189,7 +200,7 @@ export class SearchNode {
* by the current node.
*/
get editCount(): number {
return this.calculation.getHeuristicFinalCost();
return this.calculation.getHeuristicFinalCost() + this.deleteAfterInsertEditPairs;
}

/**
Expand Down