text.bend checks
raw source on the hub · import bend-kit-text@0.2.2.5/text.bend as Text
Text utilities: Myers diff with unified output, Levenshtein distance, and word wrap by display width.
4 imports
import Base import bend-kit-unicode@0.1.0.0/unicode.bend as Unicode import bend-kit-tty@0.1.0.2/text.bend as Tty import bend-kit-bytes@0.3.3.3/bytes.bend as Bytes
Types
type Edit source · line 10 · raw
@-A:Data -> Data
Same pairs an old item with the new item it matched; before keeps old items, after keeps new ones.
Same@-A:Data -> @old:A -> @new:A -> Edit<A>
Del@-A:Data -> @old:A -> Edit<A>
Ins@-A:Data -> @new:A -> Edit<A>
type Move source · line 15 · raw
Data
MSameMove
MDelMove
MInsMove
type Ctx source · line 74 · raw
@-A:Data -> Type
The items, and the forward and reverse frontiers: v[off + k] is the furthest x on diagonal k = x - y.
Ctx@-A:Data -> @a:Array<A> -> @b:Array<A> -> @vf:Array<U32> -> @vb:Array<U32> -> Ctx<A>
type Geo source · line 78 · raw
Data
A segment of n items of a from os, and m items of b from ns. off centres the frontiers.
Geo@os:U32 -> @ns:U32 -> @n:U32 -> @m:U32 -> @off:U32 -> Geo
type Pt source · line 81 · raw
Data
Pt@x:U32 -> @y:U32 -> Pt
type Job source · line 257 · raw
Data
A segment still to diff, or moves ready to emit.
JSolve@os:U32 -> @oe:U32 -> @ns:U32 -> @ne:U32 -> Job
JEmit@ms:List<&2, Move> -> Job
type ByteRange source · line 451 · raw
Data
ByteRange@offset:U32 -> @length:U32 -> @key:U32 -> ByteRange
type Row source · line 655 · raw
Data
A Gap is a Same line outside every hunk. dold and dnew count the old and new lines a row consumes.
GapRow
Line@text:String -> @dold:U32 -> @dnew:U32 -> Row
type Hunk source · line 671 · raw
Data
Hunk@o:U32 -> @n:U32 -> @ol:U32 -> @nl:U32 -> @body:List<&2, String> -> Hunk
type Wr source · line 834 · raw
Data
The finished lines, newest first, and the line being built.
Wr@out:List<&2, String> -> @cur:Maybe<&2, String> -> Wr
type Fw source · line 976 · raw
Data
The finished lines, newest first; the words of the open line, newest first; its width; and its last code point.
Fw@out:List<&2, String> -> @cur:List<&2, String> -> @cw:U32 -> @end:U32 -> Fw
Definitions
def before source · line 20 · raw
@-A:Data -> @es:List<&2, Edit<A>> -> List<&2, A>
def after source · line 31 · raw
@-A:Data -> @es:List<&2, Edit<A>> -> List<&2, A>
def walk.ins source · line 42 · raw
@-A:Data -> @b:List<&2, A> -> List<&2, Edit<A>>
def walk.rest source · line 49 · raw
@-A:Data -> @a:List<&2, A> -> @b:List<&2, A> -> List<&2, Edit<A>>
def walk source · line 58 · raw
@-A:Data -> @ms:List<&2, Move> -> @a:List<&2, A> -> @b:List<&2, A> -> List<&2, Edit<A>>
Replays moves over a and b. A move that does not fit is skipped, and leftovers become Del then Ins, so before and after give a and b back for any moves.
def geo.os source · line 84 · raw
@+g:Geo -> U32
def geo.ns source · line 89 · raw
@+g:Geo -> U32
def geo.n source · line 94 · raw
@+g:Geo -> U32
def geo.m source · line 99 · raw
@+g:Geo -> U32
def geo.off source · line 104 · raw
@+g:Geo -> U32
def at.point source · line 155 · raw
@rev:Bool -> @+g:Geo -> @+k:U32 -> @+x:U32 -> @+x0:U32 -> Maybe<&2, Pt>
def at.overlap source · line 162 · raw
@hit:Bool -> @rev:Bool -> @g:Geo -> @k:U32 -> @x:U32 -> @x0:U32 -> Maybe<&2, Pt>
def changes source · line 261 · raw
@+dels:U32 -> @+ins:U32 -> List<&2, Move>
def canon.flush source · line 327 · raw
@d:Nat -> @i:Nat -> @rest:List<&2, Move> -> List<&2, Move>
def canon source · line 331 · raw
@ms:List<&2, Move> -> @+d:Nat -> @+i:Nat -> List<&2, Move>
Each run of changes puts its deletes first, as diff does.
def lines.push source · line 415 · raw
@c:Char -> @ls:List<&2, String> -> List<&2, String>
def lines source · line 423 · raw
@s:String -> List<&2, String>
Lines with their "\n". Only the last line can lack one, and joining the lines gives s back.
def fnv.go source · line 433 · raw
@s:String -> @+h:U32 -> U32
32-bit FNV-1a, a key for diff_by.
def fnv source · line 440 · raw
@s:String -> U32
def diff_lines source · line 443 · raw
@a:String -> @b:String -> List<&2, Edit<String>>
def diff_chars source · line 446 · raw
@a:String -> @b:String -> List<&2, Edit<Char>>
def byte_range.key source · line 454 · raw
@r:ByteRange -> U32
def byte_lines.finish source · line 459 · raw
@last:Bool -> @+start:U32 -> @+end:U32 -> @h:U32 -> @out:List<&2, ByteRange> -> List<&2, ByteRange>
def byte_lines.step source · line 466 · raw
@nl:Bool -> @+start:U32 -> @+end:U32 -> @+h:U32 -> @out:List<&2, ByteRange> -> Pair(U32, Pair(U32, List<&2, ByteRange>))
def byte_lines.go source · line 474 · raw
@f:Nat -> @r:Pair(Array<U32>, U32) -> @+i:U32 -> @st:Pair(U32, Pair(U32, List<&2, ByteRange>)) -> Pair(Array<U32>, List<&2, ByteRange>)
def byte_lines.wrap source · line 485 · raw
@+n:U32 -> @r:Pair(Array<U32>, List<&2, ByteRange>) -> Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, List<&2, ByteRange>)
def byte_lines source · line 490 · raw
@b:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, List<&2, ByteRange>)
Ranges include LF; CR and all other octets are ordinary bytes.
def byte_equal.b source · line 494 · raw
@a:Array<U32> -> @x:U32 -> @r:Pair(Array<U32>, U32) -> Pair(Array<U32>, Pair(Array<U32>, Bool))
def byte_equal.a source · line 498 · raw
@r:Pair(Array<U32>, U32) -> @b:Array<U32> -> @j:U32 -> Pair(Array<U32>, Pair(Array<U32>, Bool))
def byte_equal.go source · line 502 · raw
@f:Nat -> @r:Pair(Array<U32>, Pair(Array<U32>, Bool)) -> @+i:U32 -> @+j:U32 -> @+ok:Bool -> Pair(Array<U32>, Pair(Array<U32>, Bool))
def byte_equal.size source · line 511 · raw
@eq:Bool -> @a:Array<U32> -> @b:Array<U32> -> @+i:U32 -> @+j:U32 -> @n:U32 -> Pair(Array<U32>, Pair(Array<U32>, Bool))
def byte_paired source · line 518 · raw
@es:List<&2, Edit<ByteRange>> -> @r:Pair(Array<U32>, Pair(Array<U32>, Bool)) -> @+ok:Bool -> Pair(Array<U32>, Pair(Array<U32>, Bool))
def byte_values.word.high source · line 529 · raw
@r:Pair(Array<U32>, U32) -> @low:U32 -> @+shift:Nat -> Pair(Array<U32>, U32)
def byte_values.word.pick source · line 533 · raw
@aligned:Bool -> @r:Pair(Array<U32>, U32) -> @+i:U32 -> Pair(Array<U32>, U32)
def byte_values.word source · line 541 · raw
@a:Array<U32> -> @+i:U32 -> Pair(Array<U32>, U32)
def byte_values.tail source · line 544 · raw
@r:Pair(Array<U32>, U32) -> @n:U32 -> @out:List<&2, U32> -> Pair(Array<U32>, List<&2, U32>)
def byte_values.go source · line 548 · raw
@f:Nat -> @r:Pair(Array<U32>, U32) -> @+i:U32 -> @+n:U32 -> @out:List<&2, U32> -> Pair(Array<U32>, List<&2, U32>)
def byte_values.push source · line 557 · raw
@first:Bool -> @vs:List<&2, U32> -> @out:List<&2, List<&2, U32>> -> List<&2, List<&2, U32>>
def byte_values source · line 564 · raw
@rs:List<&2, ByteRange> -> @r:Pair(Array<U32>, List<&2, U32>) -> @out:List<&2, List<&2, U32>> -> @+first:Bool -> Pair(Array<U32>, List<&2, List<&2, U32>>)
def byte_values.eq source · line 573 · raw
@a:List<&2, U32> -> @b:List<&2, U32> -> Bool
def byte_diff.fallback.b source · line 582 · raw
@a:Array<U32> -> @av:List<&2, List<&2, U32>> -> @r:Pair(Array<U32>, List<&2, List<&2, U32>>) -> @old:List<&2, ByteRange> -> @new:List<&2, ByteRange> -> Pair(Array<U32>, Pair(Array<U32>, List<&2, Edit<ByteRange>>))
def byte_diff.fallback.a source · line 586 · raw
@r:Pair(Array<U32>, List<&2, List<&2, U32>>) -> @b:Array<U32> -> @old:List<&2, ByteRange> -> @+new:List<&2, ByteRange> -> Pair(Array<U32>, Pair(Array<U32>, List<&2, Edit<ByteRange>>))
def byte_diff.pick source · line 591 · raw
@ok:Bool -> @es:List<&2, Edit<ByteRange>> -> @a:Array<U32> -> @b:Array<U32> -> @+old:List<&2, ByteRange> -> @+new:List<&2, ByteRange> -> Pair(Array<U32>, Pair(Array<U32>, List<&2, Edit<ByteRange>>))
A collision compares exact packed words, a partial word, and the byte length.
def byte_diff.checked source · line 598 · raw
@r:Pair(Array<U32>, Pair(Array<U32>, Bool)) -> @es:List<&2, Edit<ByteRange>> -> @old:List<&2, ByteRange> -> @new:List<&2, ByteRange> -> Pair(Array<U32>, Pair(Array<U32>, List<&2, Edit<ByteRange>>))
def byte_diff.wrap source · line 602 · raw
@an:U32 -> @bn:U32 -> @r:Pair(Array<U32>, Pair(Array<U32>, List<&2, Edit<ByteRange>>)) -> Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, List<&2, Edit<ByteRange>>))
def byte_diff.arrays source · line 606 · raw
@a:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> @b:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> @+old:List<&2, ByteRange> -> @+new:List<&2, ByteRange> -> Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, List<&2, Edit<ByteRange>>))
def byte_diff.new source · line 612 · raw
@a:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> @old:List<&2, ByteRange> -> @r:Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, List<&2, ByteRange>) -> Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, List<&2, Edit<ByteRange>>))
def byte_diff.old source · line 616 · raw
@r:Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, List<&2, ByteRange>) -> @b:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, List<&2, Edit<ByteRange>>))
def diff_bytes source · line 621 · raw
@a:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> @b:0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes -> Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, Pair(0x3f4d48cfd4df31741ee4b528a4e7773e/bytes.Bytes, List<&2, Edit<ByteRange>>))
Returns both owned buffers and a shortest line script whose ranges refer to them.
def far source · line 626 · raw
U32
def ahead.next source · line 629 · raw
@+r:List<&2, U32> -> U32
def ahead.cons source · line 636 · raw
@+change:Bool -> @+r:List<&2, U32> -> List<&2, U32>
def is_change source · line 639 · raw
@-A:Data -> @e:Edit<A> -> Bool
def ahead source · line 647 · raw
@-A:Data -> @es:List<&2, Edit<A>> -> List<&2, U32>
For each edit, how many edits ahead the next change is: 0 for a change.
def rows source · line 659 · raw
@es:List<&2, Edit<String>> -> @ds:List<&2, U32> -> @+ctx:U32 -> @+back:U32 -> List<&2, Row>
def range.pick source · line 675 · raw
@empty:Bool -> @+start:U32 -> @+len:U32 -> String
GNU form: an empty range names the line before it, and a one-line range drops ",1".
def range source · line 683 · raw
@+start:U32 -> @+len:U32 -> String
def hunk.show source · line 686 · raw
@h:Hunk -> String
def close source · line 692 · raw
@cur:Maybe<&2, Hunk> -> @out:List<&2, String> -> List<&2, String>
def open source · line 699 · raw
@cur:Maybe<&2, Hunk> -> @+o:U32 -> @+n:U32 -> Hunk
def eol source · line 707 · raw
@+text:String -> String
Text whose line lacks "\n" is the last line of its file, as diff -u marks it.
def hunk.add source · line 710 · raw
@h:Hunk -> @+text:String -> @+dold:U32 -> @+dnew:U32 -> Hunk
def emit source · line 716 · raw
@rs:List<&2, Row> -> @+o:U32 -> @+n:U32 -> @cur:Maybe<&2, Hunk> -> @out:List<&2, String> -> List<&2, String>
o and n count the old and new lines before the row.
def unified.fin source · line 725 · raw
@hs:List<&2, String> -> @old_name:String -> @new_name:String -> String
def unified source · line 734 · raw
@old_name:String -> @new_name:String -> @+es:List<&2, Edit<String>> -> @+ctx:U32 -> String
Unified diff text with ctx lines of context around each change; "" when nothing changed. Each line must end with "\n" except the last line of a file, as lines() gives them.
def lev.last source · line 747 · raw
@xs:List<&2, U32> -> @+d:U32 -> U32
def lev.init source · line 754 · raw
@n:Nat -> @+i:U32 -> List<&2, U32>
def distance source · line 774 · raw
@a:String -> @b:String -> U32
Levenshtein distance by code point.
def words.flush source · line 779 · raw
@cur:String -> @out:List<&2, String> -> List<&2, String>
def words.step source · line 787 · raw
@sp:Bool -> @+c:Char -> @st:Pair(String, List<&2, String>) -> Pair(String, List<&2, String>)
cur holds the word being read, reversed.
def words.go source · line 796 · raw
@s:String -> @st:Pair(String, List<&2, String>) -> List<&2, String>
def words source · line 805 · raw
@s:String -> List<&2, String>
Runs of non-space chars.
def fits source · line 808 · raw
@+line:String -> @+width:U32 -> Bool
def single.of source · line 811 · raw
@gs:List<&2, String> -> Bool
def single source · line 819 · raw
@+s:String -> Bool
One grapheme cluster: the only kind of line that may be wider than the width.
def ok.pick source · line 822 · raw
@f:Bool -> @+s:String -> Bool
def ok source · line 830 · raw
@+s:String -> @+width:U32 -> Bool
What wrap promises for each line: it fits, or it is one grapheme cluster.
def step0.pick source · line 837 · raw
@f:Bool -> @out:List<&2, String> -> @s:String -> @+c:Char -> Wr
def step0 source · line 844 · raw
@st:Wr -> @+c:Char -> @+width:U32 -> Wr
def run0 source · line 852 · raw
@s:String -> @+width:U32 -> @st:Wr -> Wr
Code points, for a piece that neither fits nor segments as one cluster. One code point is one cluster.
def start1 source · line 859 · raw
@ok:Bool -> @out:List<&2, String> -> @+g:String -> @+width:U32 -> Wr
def step1.pick source · line 866 · raw
@f:Bool -> @out:List<&2, String> -> @s:String -> @+g:String -> @+width:U32 -> Wr
def step1 source · line 873 · raw
@st:Wr -> @+g:String -> @+width:U32 -> Wr
def run1 source · line 881 · raw
@gs:List<&2, String> -> @+width:U32 -> @st:Wr -> Wr
Grapheme clusters, for a word wider than the line.
def start2 source · line 888 · raw
@ok:Bool -> @out:List<&2, String> -> @+w:String -> @+width:U32 -> Wr
def step2.pick source · line 895 · raw
@f:Bool -> @out:List<&2, String> -> @s:String -> @+w:String -> @+width:U32 -> Wr
def step2 source · line 902 · raw
@st:Wr -> @+w:String -> @+width:U32 -> Wr
def run2 source · line 909 · raw
@ws:List<&2, String> -> @+width:U32 -> @st:Wr -> Wr
def wrap.lines source · line 916 · raw
@st:Wr -> List<&2, String>
def wrap.slow source · line 924 · raw
@text:String -> @+width:U32 -> List<&2, String>
Wraps by measuring each candidate line whole. wrap falls back to it.
def all_ok source · line 927 · raw
@ls:List<&2, String> -> @+width:U32 -> Bool
def printable source · line 934 · raw
@+c:U32 -> Bool
def ascii source · line 938 · raw
@s:String -> Bool
Only printable ASCII, so each char is one cluster one column wide.
def last.go source · line 945 · raw
@s:String -> @+c:U32 -> U32
def last source · line 953 · raw
@s:String -> U32
The last code point of s, or 0.
def two source · line 956 · raw
@gs:List<&2, String> -> Bool
def apart source · line 964 · raw
@+c:U32 -> Bool
Whether a cluster boundary falls between code point c and a space. Only a Prepend c joins one.
def fw.end source · line 968 · raw
@aw:Bool -> @w:String -> U32
The end of a line after word w. Any printable ASCII char stands for the last char of a printable ASCII word.
def fw.line source · line 979 · raw
@cur:List<&2, String> -> String
def fw.close source · line 982 · raw
@out:List<&2, String> -> @cur:List<&2, String> -> List<&2, String>
def fw.from source · line 989 · raw
@st:Wr -> Fw
def fw.begin source · line 996 · raw
@fits:Bool -> @out:List<&2, String> -> @+w:String -> @+ww:U32 -> @+width:U32 -> @+aw:Bool -> Fw
def fw.start source · line 1003 · raw
@asc:Bool -> @out:List<&2, String> -> @+w:String -> @+width:U32 -> Fw
def fw.add source · line 1012 · raw
@fits:Bool -> @out:List<&2, String> -> @+cur:List<&2, String> -> @+nw:U32 -> @+w:String -> @+width:U32 -> @+aw:Bool -> Fw
def fw.join source · line 1020 · raw
@sure:Bool -> @+gs:List<&2, String> -> @out:List<&2, String> -> @+cur:List<&2, String> -> @+cw:U32 -> @+w:String -> @+width:U32 -> @+aw:Bool -> Fw
A boundary between the line and the space keeps the line's clusters apart from those of the space and the word, so the widths add.
def fw.next source · line 1030 · raw
@asc:Bool -> @out:List<&2, String> -> @+cur:List<&2, String> -> @+cw:U32 -> @+end:U32 -> @+w:String -> @+width:U32 -> @+aw:Bool -> Fw
Printable ASCII on both sides of the space needs no segmentation: each char is one cluster one column wide.
def fw.step.go source · line 1038 · raw
@st:Fw -> @+aw:Bool -> @+w:String -> @+width:U32 -> Fw
def fw.step source · line 1045 · raw
@st:Fw -> @+w:String -> @+width:U32 -> Fw
def fw.run source · line 1048 · raw
@ws:List<&2, String> -> @+width:U32 -> @st:Fw -> Fw
def fw.lines source · line 1055 · raw
@st:Fw -> List<&2, String>
def wrap.fast source · line 1061 · raw
@text:String -> @+width:U32 -> List<&2, String>
The same lines as wrap.slow, adding widths when no cluster spans the joining space.
def wrap.pick source · line 1064 · raw
@good:Bool -> @ls:List<&2, String> -> @text:String -> @+width:U32 -> List<&2, String>
def wrap source · line 1074 · raw
@+text:String -> @+width:U32 -> List<&2, String>
Greedy word wrap to width display columns. Whitespace runs separate words; lines join words with one space. A word wider than width breaks between grapheme clusters; a cluster wider than width stays whole on its own line. The fast path's lines are checked with ok; if one fails, every line is measured whole instead.
Templates
template same.b source · line 109 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @x:A -> @a:Array<A> -> @r:Pair(Array<A>, A) -> Pair(Array<A>, Pair(Array<A>, Bool))
template same.a source · line 113 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @r:Pair(Array<A>, A) -> @b:Array<A> -> @+j:U32 -> Pair(Array<A>, Pair(Array<A>, Bool))
template probe.in source · line 117 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @inr:Bool -> @a:Array<A> -> @b:Array<A> -> @+rev:Bool -> @+g:Geo -> @+x:U32 -> @+y:U32 -> Pair(Array<A>, Pair(Array<A>, Bool))
template probe source · line 127 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @a:Array<A> -> @b:Array<A> -> @+rev:Bool -> @+g:Geo -> @+x:U32 -> @+y:U32 -> Pair(Array<A>, Pair(Array<A>, Bool))
Whether item x of the segment of a matches item y of the segment of b. rev counts from the segment end.
template snake source · line 130 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @fuel:Nat -> @r:Pair(Array<A>, Pair(Array<A>, Bool)) -> @+rev:Bool -> @+g:Geo -> @+x:U32 -> @+y:U32 -> Pair(Array<A>, Pair(Array<A>, U32))
template slide source · line 144 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @a:Array<A> -> @b:Array<A> -> @+rev:Bool -> @+g:Geo -> @+x:U32 -> @+y:U32 -> Pair(Array<A>, Pair(Array<A>, U32))
The x where the run of matches from (x, y) ends.
template ctx.mk source · line 148 · raw
@-A:Data -> @rev:Bool -> @a:Array<A> -> @b:Array<A> -> @v:Array<U32> -> @w:Array<U32> -> Ctx<A>
v is the frontier that moves, w the other one.
template at.hit source · line 169 · raw
@-A:Data -> @r:Pair(Array<U32>, U32) -> @a:Array<A> -> @b:Array<A> -> @v:Array<U32> -> @+rev:Bool -> @+g:Geo -> @+k:U32 -> @+x:U32 -> @+x0:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
template at.chk source · line 173 · raw
@-A:Data -> @on:Bool -> @a:Array<A> -> @b:Array<A> -> @v:Array<U32> -> @w:Array<U32> -> @+rev:Bool -> @+g:Geo -> @+k:U32 -> @+x:U32 -> @+x0:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
template at.snk source · line 181 · raw
@-A:Data -> @r:Pair(Array<A>, Pair(Array<A>, U32)) -> @v:Array<U32> -> @w:Array<U32> -> @+rev:Bool -> @+g:Geo -> @+d:U32 -> @+k:U32 -> @+x0:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
Myers' overlap test: forward d-paths meet reverse (d-1)-paths when n - m is odd, reverse d-paths when even.
template at.hi source · line 192 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @r:Pair(Array<U32>, U32) -> @+lo:U32 -> @a:Array<A> -> @b:Array<A> -> @w:Array<U32> -> @+rev:Bool -> @+g:Geo -> @+d:U32 -> @+k:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
Myers' rule for diagonal k: go down from k+1 when V[k-1] < V[k+1], else right from k-1.
template at.lo source · line 198 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @r:Pair(Array<U32>, U32) -> @a:Array<A> -> @b:Array<A> -> @w:Array<U32> -> @+rev:Bool -> @+g:Geo -> @+d:U32 -> @+k:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
template at source · line 203 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @rev:Bool -> @c:Ctx<A> -> @+g:Geo -> @+d:U32 -> @+k:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
One diagonal of one sweep.
template sweep source · line 211 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @fuel:Nat -> @r:Pair(Ctx<A>, Maybe<&2, Pt>) -> @+rev:Bool -> @+g:Geo -> @+d:U32 -> @+k:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
Diagonals k, k + 2, ... until fuel runs out or a sweep meets the other frontier.
template round.back source · line 224 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @r:Pair(Ctx<A>, Maybe<&2, Pt>) -> @+g:Geo -> @+d:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
template round source · line 232 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @c:Ctx<A> -> @+g:Geo -> @+d:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
template middle.go source · line 235 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @fuel:Nat -> @r:Pair(Ctx<A>, Maybe<&2, Pt>) -> @+g:Geo -> @+d:U32 -> Pair(Ctx<A>, Maybe<&2, Pt>)
template middle source · line 249 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @c:Ctx<A> -> @+g:Geo -> Pair(Ctx<A>, Maybe<&2, Pt>)
Myers' middle snake: grow d-paths from both ends of the segment until they meet. The meeting point is on a shortest path.
template plan.split source · line 264 · raw
@-A:Data -> @r:Pair(Ctx<A>, Maybe<&2, Pt>) -> @+os:U32 -> @+oe:U32 -> @+ns:U32 -> @+ne:U32 -> Pair(Ctx<A>, List<&2, Job>)
template plan.mid source · line 272 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @ea:Bool -> @eb:Bool -> @c:Ctx<A> -> @+os:U32 -> @+oe:U32 -> @+ns:U32 -> @+ne:U32 -> @+off:U32 -> Pair(Ctx<A>, List<&2, Job>)
template plan.wrap source · line 281 · raw
@-A:Data -> @r:Pair(Ctx<A>, List<&2, Job>) -> @+p:U32 -> @+s:U32 -> Pair(Ctx<A>, List<&2, Job>)
template plan.suf source · line 286 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @r:Pair(Array<A>, Pair(Array<A>, U32)) -> @vf:Array<U32> -> @vb:Array<U32> -> @+p:U32 -> @+os:U32 -> @+oe:U32 -> @+ns:U32 -> @+ne:U32 -> @+off:U32 -> Pair(Ctx<A>, List<&2, Job>)
template plan.pre source · line 295 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @r:Pair(Array<A>, Pair(Array<A>, U32)) -> @vf:Array<U32> -> @vb:Array<U32> -> @+os:U32 -> @+oe:U32 -> @+ns:U32 -> @+ne:U32 -> @+off:U32 -> Pair(Ctx<A>, List<&2, Job>)
template plan source · line 302 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @c:Ctx<A> -> @+os:U32 -> @+oe:U32 -> @+ns:U32 -> @+ne:U32 -> @+off:U32 -> Pair(Ctx<A>, List<&2, Job>)
Jobs for one segment, last first: the common suffix, the middle, then the common prefix.
template plan.then source · line 307 · raw
@-A:Data -> @r:Pair(Ctx<A>, List<&2, Job>) -> @t:List<&2, Job> -> Pair(Ctx<A>, List<&2, Job>)
template solve source · line 312 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @fuel:Nat -> @r:Pair(Ctx<A>, List<&2, Job>) -> @+off:U32 -> @acc:List<&2, Move> -> List<&2, Move>
Runs jobs from the end of the script back to its start, so each emit prepends.
template fill source · line 342 · raw
@-A:Data -> @xs:List<&2, A> -> @arr:Array<A> -> @+i:U32 -> Array<A>
template array source · line 350 · raw
@-A:Data -> @+n:U32 -> @+v:A -> Array<A>
An array of n slots or more.
template moves.go source · line 354 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @+x:A -> @+y:A -> @+a:List<&2, A> -> @+b:List<&2, A> -> List<&2, Move>
Each split leaves two smaller segments, and each segment plans at most 4 jobs.
template moves source · line 362 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @+a:List<&2, A> -> @+b:List<&2, A> -> List<&2, Move>
template diff source · line 374 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @+a:List<&2, A> -> @+b:List<&2, A> -> List<&2, Edit<A>>
A shortest edit script from a to b. eq decides which items match.
template keys source · line 377 · raw
@-A:Data -> @-key:(@_:A -> U32) -> @xs:List<&2, A> -> List<&2, U32>
template paired source · line 385 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @ms:List<&2, Move> -> @a:List<&2, A> -> @b:List<&2, A> -> Bool
Whether every pair that walk would match is equal by eq.
template moves_by.pick source · line 398 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @ok:Bool -> @ms:List<&2, Move> -> @+a:List<&2, A> -> @+b:List<&2, A> -> List<&2, Move>
template moves_by source · line 406 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @-key:(@_:A -> U32) -> @+a:List<&2, A> -> @+b:List<&2, A> -> List<&2, Move>
Diffs the keys, then checks each matched pair with eq. If two unequal items share a key and get matched, it diffs the items instead.
template diff_by source · line 412 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @-key:(@_:A -> U32) -> @+a:List<&2, A> -> @+b:List<&2, A> -> List<&2, Edit<A>>
diff, but Myers compares U32 keys, which is much faster than comparing items such as strings. Equal items must have equal keys. The script is the same length as diff's.
template lev.row source · line 739 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @b:List<&2, A> -> @up:List<&2, U32> -> @+x:A -> @+diag:U32 -> @+left:U32 -> List<&2, U32>
template lev.go source · line 761 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @a:List<&2, A> -> @+b:List<&2, A> -> @prev:List<&2, U32> -> @+i:U32 -> U32
template edit_distance source · line 770 · raw
@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @a:List<&2, A> -> @+b:List<&2, A> -> U32
Fewest inserts, deletes, and substitutions that turn a into b.