~/bend-docscommunity

src/Reconstruction.bend checks

raw source on the hub · import bend-edit-distance@0.2.2.0/src/Reconstruction.bend as Reconstruction

4 imports
import Base
import ./Sequence.bend as S
import ../EdlibTypes.bend as E
import ./DistanceDP.bend as DP

Types

type TraceCell source · line 14 · raw

Data

type Split source · line 125 · raw

Data

Definitions

def diagonal_operation source · line 11 · raw

@matches:Bool -> 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation

def cell_score source · line 17 · raw

@cell:TraceCell -> U32

def choose_operation source · line 22 · raw

@matches:Bool -> @up_is_best:Bool -> @left_is_best:Bool -> 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation

def dp_cell source · line 31 · raw

@above:U32 -> @left:U32 -> @diagonal:U32 -> @+matches:Bool -> TraceCell

def dp_row_cells source · line 39 · raw

@columns:String -> @previous:List<&2, TraceCell> -> @diagonal:U32 -> @left:U32 -> @+symbol:Char -> @+pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> List<&2, TraceCell>

def dp_row source · line 51 · raw

@previous:List<&2, TraceCell> -> @columns:String -> @symbol:Char -> @+index:U32 -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> List<&2, TraceCell>

def dp_initial source · line 61 · raw

@target:String -> @+index:U32 -> List<&2, TraceCell>

def dp_rows source · line 68 · raw

@query:String -> @+target:String -> @previous:List<&2, TraceCell> -> @+index:U32 -> @+pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @directions:List<&2, List<&2, TraceCell>> -> List<&2, List<&2, TraceCell>>

def traceback source · line 82 · raw

@fuel:Nat -> @current:List<&2, TraceCell> -> @previous:List<&2, List<&2, TraceCell>> -> @+width:Nat -> @+column:Nat -> @operations:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation> -> List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation>

Rows and their operations are reversed so left moves consume the current row directly. Entering the row above skips only its unused right suffix. Including boundary rows/columns handles all-insertion/deletion paths.

def dp_trace source · line 102 · raw

@matrix:List<&2, List<&2, TraceCell>> -> @query_length:Nat -> @+target_length:Nat -> List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation>

def dp source · line 111 · raw

@+query:String -> @+target:String -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation>

def small_matrix source · line 119 · raw

@query_length:Nat -> @+target_length:Nat -> Bool

Bound the complete small matrix, including its boundary cells. A one-row problem is also a base case, with linear storage in the column width.

def score_row source · line 122 · raw

@query:String -> @+target:String -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> List<&1, U32>

def split_index source · line 128 · raw

@split:Split -> Nat

def split_score source · line 133 · raw

@split:Split -> U32

def split_update source · line 138 · raw

@index:Nat -> @score:U32 -> @old_index:Nat -> @old_score:U32 -> @better:Bool -> Split

def split_column source · line 149 · raw

@forward:List<&1, U32> -> @backward:List<&1, U32> -> @+index:Nat -> @+best_index:Nat -> @+best_score:U32 -> Nat

Forward[j] + reverse[n-j] is the cost through the midpoint at column j. Strict comparison keeps the first minimum; this is our deterministic split policy and is deliberately separate from upstream Hirschberg compatibility.

def midpoint source · line 162 · raw

@left:String -> @right:String -> @+target:String -> @+pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> Nat

def divide source · line 177 · raw

@fuel:Nat -> @+query:String -> @+target:String -> @+query_length:Nat -> @+target_length:Nat -> @+pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @small:Bool -> List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation>

The fuel is the initial row length; every nonbase call halves that length. Score passes run in balanced parallel calls and are consumed before recursion. Subpaths are evaluated sequentially to bound live score storage even on many threads; the result lists themselves necessarily use O(m+n) space.

def transpose source · line 204 · raw

@operations:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation> -> List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation>

def reconstruct_order source · line 215 · raw

@query:String -> @target:String -> @+query_length:Nat -> @+target_length:Nat -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @small:Bool -> @query_is_taller:Bool -> List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation>

def reconstruct source · line 226 · raw

@+query:String -> @+target:String -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation>

def validate source · line 235 · raw

@operations:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation> -> @query:String -> @target:String -> @+pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @+expected:Nat -> @cost:Nat -> Bool

Edlib codes: Match=0 consumes both, Insert=1 consumes query only, Delete=2 consumes target only, Mismatch=3 consumes both. Validation requires exact consumption, the configured (symmetric, nontransitive) predicate on every diagonal operation, and an edit cost equal to the reported distance.

def valid_path source · line 251 · raw

@query:String -> @target:String -> @operations:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Operation> -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @distance:Nat -> Bool