~/bend-docscommunity

src/Myers.bend checks

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

4 imports
import Base
import ./Sequence.bend as S
import ../EdlibTypes.bend as E
import ./Alignment.bend as A

Types

type Peq source · line 11 · raw

Data

type Block source · line 15 · raw

Data

type Carry source · line 20 · raw

Data

Horizontal differences are -1, 0, or +1. Keep both signs explicit rather than relying on signed shifts or two's-complement arithmetic.

type BandEntry source · line 156 · raw

Data

An active entry owns its current block and shares its immutable profile. Dropped leading entries are never visited again. Trailing profiles remain available for expansion; retries share the full profile but reset all blocks.

type Band source · line 159 · raw

Type

type UpdatedBand source · line 162 · raw

Type

type BandStep source · line 165 · raw

Type

Definitions

def split_query.prepend source · line 23 · raw

@h:Char -> @parts:Pair(String, String) -> Pair(String, String)

def split_query source · line 28 · raw

@n:Nat -> @query:String -> Pair(String, String)

def build_peq_word source · line 39 · raw

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

Bit i matches query[i] literally or through an explicit symmetric pair. Unused high bits are wildcards regardless of the pairs, as in buildPeq.

def build_peq_table source · line 51 · raw

@+depth:Nat -> @+query:String -> @+symbol:U32 -> @+step:U32 -> @+pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> Peq

A byte-indexed immutable table replaces the C++ transformed alphabet. Low bits select branches, so lookup takes eight steps for every byte. Both halves of the table have equal, independent work and run in parallel.

def peq_get source · line 60 · raw

@table:Peq -> @+code:U32 -> @bit:Bool -> U32

def build_peq.step source · line 71 · raw

@parts:Pair(String, String) -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @tail:(@_:String -> List<&2, Peq>) -> List<&2, Peq>

def build_peq source · line 77 · raw

@fuel:Nat -> @query:String -> @+pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> List<&2, Peq>

def ceil_div source · line 84 · raw

@+x:Nat -> @+y:Nat -> Nat

def init_blocks source · line 87 · raw

@n:Nat -> @+bottom:U32 -> List<&1, Block>

def calculate_block source · line 96 · raw

@block:Block -> @+eq:U32 -> @hin:Carry -> Pair(Block, Carry)

calculateBlock / Advance_Block from Myers. Addition intentionally wraps at 32 bits. Xv uses the original Eq, before the negative carry is added.

def advance_column.step source · line 115 · raw

@result:Pair(Block, Carry) -> @tail:(@_:Carry -> List<&1, Block>) -> List<&1, Block>

A column and consecutive target columns depend on their predecessor; parallelizing those calls would violate the Myers carry dependency.

def advance_column source · line 121 · raw

@blocks:List<&1, Block> -> @profiles:List<&2, Peq> -> @+symbol:U32 -> @hin:Carry -> List<&1, Block>

def get_block_cell_value source · line 136 · raw

@padding:Nat -> @+pv:U32 -> @+mv:U32 -> @score:U32 -> U32

getBlockCellValues(block)[W], without constructing the other 31 cells. Walking up a row subtracts its positive vertical difference and adds its negative difference. W is always in 0..31, never a whole extra block.

def last_block_score source · line 144 · raw

@blocks:List<&1, Block> -> @+padding:Nat -> Nat

def init_band_entries.step source · line 173 · raw

@parts:Pair(List<&2, BandEntry>, List<&2, Peq>) -> @profile:Peq -> @bottom:U32 -> Pair(List<&2, BandEntry>, List<&2, Peq>)

def init_band_entries source · line 179 · raw

@fuel:Nat -> @profiles:List<&2, Peq> -> @+bottom:U32 -> Pair(List<&2, BandEntry>, List<&2, Peq>)

def init_band.step source · line 189 · raw

@parts:Pair(List<&2, BandEntry>, List<&2, Peq>) -> Band

def init_band source · line 194 · raw

@profiles:List<&2, Peq> -> @+length:Nat -> @+target_length:Nat -> @maximum:Nat -> Band

def advance_band.join source · line 201 · raw

@entry:BandEntry -> @updated:UpdatedBand -> UpdatedBand

def advance_band.last source · line 206 · raw

@result:Pair(Block, Carry) -> @profile:Peq -> @bottom:Nat -> UpdatedBand

def advance_band.next source · line 211 · raw

@result:Pair(Block, Carry) -> @profile:Peq -> @tail:(@_:Carry -> UpdatedBand) -> UpdatedBand

def advance_band source · line 217 · raw

@entries:List<&2, BandEntry> -> @+symbol:U32 -> @hin:Carry -> @+bottom:Nat -> UpdatedBand

def band_keep_last source · line 233 · raw

@+score:Nat -> @bottom:Nat -> @+maximum:Nat -> @length:Nat -> @target_length:Nat -> @column:Nat -> Bool

Edlib's conservative Ukkonen block bounds, rearranged so every term is nonnegative Nat arithmetic. Rows/columns here count consumed characters. The 62/63 constants adapt 2*WORD_SIZE-2/-1 from the pinned 64-bit code.

def band_keep_first source · line 239 · raw

@+score:Nat -> @bottom:Nat -> @+maximum:Nat -> @length:Nat -> @target_length:Nat -> @column:Nat -> Bool

def trim_last.choose source · line 245 · raw

@entry:BandEntry -> @entries:List<&2, BandEntry> -> @rest:List<&2, Peq> -> @keep:Bool -> Pair(List<&2, BandEntry>, List<&2, Peq>)

def trim_last.join source · line 253 · raw

@entry:BandEntry -> @tail:Pair(List<&2, BandEntry>, List<&2, Peq>) -> @keep:Bool -> Pair(List<&2, BandEntry>, List<&2, Peq>)

def trim_last source · line 259 · raw

@entries:List<&2, BandEntry> -> @rest:List<&2, Peq> -> @+bottom:Nat -> @+maximum:Nat -> @+length:Nat -> @+target_length:Nat -> @+column:Nat -> Pair(List<&2, BandEntry>, List<&2, Peq>)

def trim_first.step source · line 270 · raw

@entry:BandEntry -> @tail:List<&2, BandEntry> -> @rest:List<&2, Peq> -> @first:Nat -> @keep:Bool -> @next:(@_:Unit -> Band) -> Band

def trim_first source · line 278 · raw

@entries:List<&2, BandEntry> -> @+rest:List<&2, Peq> -> @+first:Nat -> @+maximum:Nat -> @+length:Nat -> @+target_length:Nat -> @+column:Nat -> Band

def reduce_band.step source · line 291 · raw

@parts:Pair(List<&2, BandEntry>, List<&2, Peq>) -> @first:Nat -> @+maximum:Nat -> @length:Nat -> @target_length:Nat -> @column:Nat -> @work:Nat -> BandStep

def reduce_band source · line 298 · raw

@entries:List<&2, BandEntry> -> @rest:List<&2, Peq> -> @+first:Nat -> @+maximum:Nat -> @+length:Nat -> @+target_length:Nat -> @+column:Nat -> @work:Nat -> BandStep

def expand_band.step source · line 304 · raw

@result:Pair(Block, Carry) -> @entries:List<&2, BandEntry> -> @profile:Peq -> @rest:List<&2, Peq> -> @first:Nat -> @maximum:Nat -> @length:Nat -> @target_length:Nat -> @column:Nat -> @work:Nat -> BandStep

def expand_band source · line 312 · raw

@entries:List<&2, BandEntry> -> @rest:List<&2, Peq> -> @+score:U32 -> @carry:Carry -> @+symbol:U32 -> @first:Nat -> @+maximum:Nat -> @length:Nat -> @target_length:Nat -> @column:Nat -> @work:Nat -> @expand:Bool -> BandStep

def band_step.updated source · line 325 · raw

@updated:UpdatedBand -> @rest:List<&2, Peq> -> @+first:Nat -> @symbol:U32 -> @+length:Nat -> @+target_length:Nat -> @+column:Nat -> @maximum:Nat -> @padding:Nat -> BandStep

def band_step source · line 340 · raw

@band:Band -> @+symbol:U32 -> @length:Nat -> @target_length:Nat -> @column:Nat -> @maximum:Nat -> @padding:Nat -> BandStep

def band_last_score source · line 347 · raw

@entries:List<&2, BandEntry> -> @+padding:Nat -> Nat

def band_finish source · line 356 · raw

@band:Band -> @maximum:Nat -> @padding:Nat -> @blocks:Nat -> @columns:Nat -> Search

def myers_calc_edit_distance_nw.step source · line 368 · raw

@step:BandStep -> @next:(@_:Band -> @_:Nat -> @_:Nat -> Search) -> Search

def myers_calc_edit_distance_nw source · line 373 · raw

@target:String -> @band:Band -> @+length:Nat -> @+target_length:Nat -> @maximum:Nat -> @+padding:Nat -> @+column:Nat -> @blocks:Nat -> Search

def band_attempt source · line 385 · raw

@target:String -> @profiles:List<&2, Peq> -> @+length:Nat -> @+target_length:Nat -> @+maximum:Nat -> @padding:Nat -> Search

def adaptive_search.step source · line 390 · raw

@distance:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EditDistance -> @blocks:Nat -> @columns:Nat -> @attempts:Nat -> @retry:(@_:Unit -> Search) -> Search

def adaptive_search.result source · line 398 · raw

@search:Search -> @blocks:Nat -> @columns:Nat -> @+attempts:Nat -> @retry:(@_:Nat -> @_:Nat -> Search) -> Search

def search_profiles source · line 420 · raw

@target:String -> @profiles:List<&2, Peq> -> @+length:Nat -> @+target_length:Nat -> @threshold:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Threshold -> Search

def search_query source · line 431 · raw

@+query:String -> @target:String -> @+length:Nat -> @target_length:Nat -> @threshold:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Threshold -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @rejected:Bool -> Search

def search_shorter source · line 440 · raw

@query:String -> @target:String -> @+query_length:Nat -> @+target_length:Nat -> @+threshold:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Threshold -> @query_is_shorter:Bool -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> Search

def semiglobal_carry source · line 454 · raw

@mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> Carry

Directional modes never swap query and target. The initial vertical scores are i in both modes, while the top horizontal difference is +1 for SHW and 0 for HW. NW's length/remaining-target band bounds do not apply here.

def init_semiglobal_band source · line 461 · raw

@profiles:List<&2, Peq> -> @length:Nat -> @+maximum:Nat -> Band

def trim_semiglobal source · line 468 · raw

@entries:List<&2, BandEntry> -> @rest:List<&2, Peq> -> @+mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @+index:Nat -> @+maximum:Nat -> Pair(List<&2, BandEntry>, List<&2, Peq>)

If the bottom score is >= k+32 every cell in that block is > k. Only trailing blocks are removed. HW always retains block zero: its free top boundary can seed a new alignment after an arbitrarily long target prefix.

def reduce_semiglobal source · line 482 · raw

@parts:Pair(List<&2, BandEntry>, List<&2, Peq>) -> Band

def expand_semiglobal.result source · line 487 · raw

@result:Pair(Block, Carry) -> @entries:List<&2, BandEntry> -> @profile:Peq -> @rest:List<&2, Peq> -> @mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @maximum:Nat -> Band

def expand_semiglobal.choose source · line 495 · raw

@entries:List<&2, BandEntry> -> @profile:Peq -> @rest:List<&2, Peq> -> @previous:U32 -> @eq:U32 -> @carry:Carry -> @mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @maximum:Nat -> @expand:Bool -> Band

def expand_semiglobal source · line 505 · raw

@updated:UpdatedBand -> @rest:List<&2, Peq> -> @+symbol:U32 -> @mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @+maximum:Nat -> Band

def semiglobal_step source · line 517 · raw

@band:Band -> @+symbol:U32 -> @+mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @maximum:Nat -> Band

def semiglobal_endpoint source · line 523 · raw

@entries:List<&2, BandEntry> -> @rest:List<&2, Peq> -> @padding:Nat -> @column:Nat -> @+best:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best -> 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best

def myers_calc_edit_distance_semiglobal.step source · line 535 · raw

@band:Band -> @padding:Nat -> @column:Nat -> @best:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best -> @next:(@_:Band -> @_:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best -> 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best) -> 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best

def myers_calc_edit_distance_semiglobal source · line 543 · raw

@target:String -> @band:Band -> @+mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @+padding:Nat -> @+column:Nat -> @+maximum:Nat -> @+best:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best -> 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best

Decode the real last query cell at every column, without Edlib's delayed padded endpoints. Tighten k after a better score, but continue for every tie.

def semiglobal_initial_best source · line 558 · raw

@+length:Nat -> @include_before:Bool -> 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best

def semiglobal_maximum source · line 565 · raw

@threshold:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Threshold -> @+length:Nat -> Nat

def semiglobal_best source · line 572 · raw

@target:String -> @profiles:List<&2, Peq> -> @+length:Nat -> @+maximum:Nat -> @+mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best

def hw_start source · line 584 · raw

@+end:Nat -> @reverse_location:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Location -> 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Location

Edlib selects the LAST optimal reverse-SHW end, hence the earliest start for each forward end. Preserve the special forward end -1 with start 0.

def hw_start_best source · line 591 · raw

@+end:Nat -> @best:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best -> 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Location

def hw_location source · line 597 · raw

@location:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Location -> @reverse_target:String -> @target_length:Nat -> @profiles:List<&2, Peq> -> @query_length:Nat -> @maximum:Nat -> 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Location

def hw_locations source · line 609 · raw

@fuel:Nat -> @locations:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Location> -> @+reverse_target:String -> @+target_length:Nat -> @+profiles:List<&2, Peq> -> @+query_length:Nat -> @+maximum:Nat -> List<&2, 0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Location>

Independent starts share one reversed query profile. Split their searches into balanced parallel branches, then concatenate in the original end order.

def configured_found source · line 629 · raw

@task:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Task -> @mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @+query:String -> @+target:String -> @+pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @format:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.CigarFormat -> @best:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best -> 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.AlignResult

def configured_result source · line 645 · raw

@query:String -> @target:String -> @mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @task:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Task -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @format:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.CigarFormat -> @best:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best -> @accepted:Bool -> 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.AlignResult

def configured_finish source · line 654 · raw

@query:String -> @target:String -> @mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @task:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Task -> @threshold:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Threshold -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @format:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.CigarFormat -> @+best:0xd65851cd1dee629f72e346cda168bc1d/src/Alignment.Best -> 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.AlignResult

def semiglobal_align source · line 661 · raw

@+query:String -> @+target:String -> @+mode:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Mode -> @task:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Task -> @+threshold:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Threshold -> @+pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @format:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.CigarFormat -> 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.AlignResult

def search_distance source · line 669 · raw

@search:Search -> 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EditDistance

def found_value source · line 674 · raw

@distance:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EditDistance -> Nat

def align_shorter source · line 681 · raw

@query:String -> @target:String -> @query_length:Nat -> @target_length:Nat -> @query_is_shorter:Bool -> Nat

def distance source · line 686 · raw

@query:String -> @target:String -> Nat

def nw_result source · line 698 · raw

@query:String -> @target:String -> @task:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Task -> @pairs:List<&2, 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EqualityPair> -> @format:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.CigarFormat -> @end:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.Coordinate -> @distance:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.EditDistance -> 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.AlignResult

def edlib_align source · line 708 · raw

@query:String -> @target:String -> @config:0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.AlignConfig -> 0xd65851cd1dee629f72e346cda168bc1d/EdlibTypes.AlignResult

def response source · line 721 · raw

@query:String -> @target:String -> String