~/bend-docscommunity

text.bend checks

raw source on the hub · import bend-kit-text@0.2.2.1/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.1/text.bend as Tty
import bend-kit-bytes@0.3.3.1/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.

type Move source · line 15 · raw

Data

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.

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.

type Pt source · line 81 · raw

Data

type Job source · line 257 · raw

Data

A segment still to diff, or moves ready to emit.

type ByteRange source · line 456 · raw

Data

type Row source · line 641 · raw

Data

A Gap is a Same line outside every hunk. dold and dnew count the old and new lines a row consumes.

type Hunk source · line 657 · raw

Data

type Wr source · line 820 · raw

Data

The finished lines, newest first, and the line being built.

type Fw source · line 962 · raw

Data

The finished lines, newest first; the words of the open line, newest first; its width; and its last code point.

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.pick source · line 422 · raw

@nl:Bool -> @c:Char -> @ls:List<&2, String> -> List<&2, String>

def lines source · line 430 · 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 438 · raw

@s:String -> @+h:U32 -> U32

32-bit FNV-1a, a key for diff_by.

def fnv source · line 445 · raw

@s:String -> U32

def diff_lines source · line 448 · raw

@a:String -> @b:String -> List<&2, Edit<String>>

def diff_chars source · line 451 · raw

@a:String -> @b:String -> List<&2, Edit<Char>>

def byte_range.key source · line 459 · raw

@r:ByteRange -> U32

def byte_lines.finish source · line 464 · raw

@last:Bool -> @+start:U32 -> @+end:U32 -> @h:U32 -> @out:List<&2, ByteRange> -> List<&2, ByteRange>

def byte_lines.step source · line 471 · 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 479 · 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 490 · raw

@+n:U32 -> @r:Pair(Array<U32>, List<&2, ByteRange>) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, List<&2, ByteRange>)

def byte_lines source · line 495 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, List<&2, ByteRange>)

Ranges include LF; CR and all other octets are ordinary bytes.

def byte_equal.b source · line 499 · raw

@a:Array<U32> -> @x:U32 -> @r:Pair(Array<U32>, U32) -> Pair(Array<U32>, Pair(Array<U32>, Bool))

def byte_equal.a source · line 503 · raw

@r:Pair(Array<U32>, U32) -> @b:Array<U32> -> @j:U32 -> Pair(Array<U32>, Pair(Array<U32>, Bool))

def byte_equal.go source · line 507 · 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 516 · 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 523 · 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.go source · line 534 · raw

@f:Nat -> @r:Pair(Array<U32>, U32) -> @+i:U32 -> @out:List<&2, U32> -> Pair(Array<U32>, List<&2, U32>)

def byte_values.push source · line 543 · raw

@first:Bool -> @vs:List<&2, U32> -> @out:List<&2, List<&2, U32>> -> List<&2, List<&2, U32>>

def byte_values source · line 550 · 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 559 · raw

@a:List<&2, U32> -> @b:List<&2, U32> -> Bool

def byte_diff.fallback.b source · line 568 · 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 572 · 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 577 · 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 uses exact octet lists only on the fallback path.

def byte_diff.checked source · line 584 · 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 588 · raw

@an:U32 -> @bn:U32 -> @r:Pair(Array<U32>, Pair(Array<U32>, List<&2, Edit<ByteRange>>)) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, List<&2, Edit<ByteRange>>))

def byte_diff.arrays source · line 592 · raw

@a:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @+old:List<&2, ByteRange> -> @+new:List<&2, ByteRange> -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, List<&2, Edit<ByteRange>>))

def byte_diff.new source · line 598 · raw

@a:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @old:List<&2, ByteRange> -> @r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, List<&2, ByteRange>) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, List<&2, Edit<ByteRange>>))

def byte_diff.old source · line 602 · raw

@r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, List<&2, ByteRange>) -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, List<&2, Edit<ByteRange>>))

def diff_bytes source · line 607 · raw

@a:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, List<&2, Edit<ByteRange>>))

Returns both owned buffers and a shortest line script whose ranges refer to them.

def far source · line 612 · raw

U32

def ahead.next source · line 615 · raw

@+r:List<&2, U32> -> U32

def ahead.cons source · line 622 · raw

@+change:Bool -> @+r:List<&2, U32> -> List<&2, U32>

def is_change source · line 625 · raw

@-A:Data -> @e:Edit<A> -> Bool

def ahead source · line 633 · 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 645 · raw

@es:List<&2, Edit<String>> -> @ds:List<&2, U32> -> @+ctx:U32 -> @+back:U32 -> List<&2, Row>

def range.pick source · line 661 · 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 669 · raw

@+start:U32 -> @+len:U32 -> String

def hunk.show source · line 672 · raw

@h:Hunk -> String

def close source · line 678 · raw

@cur:Maybe<&2, Hunk> -> @out:List<&2, String> -> List<&2, String>

def open source · line 685 · raw

@cur:Maybe<&2, Hunk> -> @+o:U32 -> @+n:U32 -> Hunk

def eol source · line 693 · 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 696 · raw

@h:Hunk -> @+text:String -> @+dold:U32 -> @+dnew:U32 -> Hunk

def emit source · line 702 · 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 711 · raw

@hs:List<&2, String> -> @old_name:String -> @new_name:String -> String

def unified source · line 720 · 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 733 · raw

@xs:List<&2, U32> -> @+d:U32 -> U32

def lev.init source · line 740 · raw

@n:Nat -> @+i:U32 -> List<&2, U32>

def distance source · line 760 · raw

@a:String -> @b:String -> U32

Levenshtein distance by code point.

def words.flush source · line 765 · raw

@cur:String -> @out:List<&2, String> -> List<&2, String>

def words.step source · line 773 · 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 782 · raw

@s:String -> @st:Pair(String, List<&2, String>) -> List<&2, String>

def words source · line 791 · raw

@s:String -> List<&2, String>

Runs of non-space chars.

def fits source · line 794 · raw

@+line:String -> @+width:U32 -> Bool

def single.of source · line 797 · raw

@gs:List<&2, String> -> Bool

def single source · line 805 · raw

@+s:String -> Bool

One grapheme cluster: the only kind of line that may be wider than the width.

def ok.pick source · line 808 · raw

@f:Bool -> @+s:String -> Bool

def ok source · line 816 · 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 823 · raw

@f:Bool -> @out:List<&2, String> -> @s:String -> @+c:Char -> Wr

def step0 source · line 830 · raw

@st:Wr -> @+c:Char -> @+width:U32 -> Wr

def run0 source · line 838 · 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 845 · raw

@ok:Bool -> @out:List<&2, String> -> @+g:String -> @+width:U32 -> Wr

def step1.pick source · line 852 · raw

@f:Bool -> @out:List<&2, String> -> @s:String -> @+g:String -> @+width:U32 -> Wr

def step1 source · line 859 · raw

@st:Wr -> @+g:String -> @+width:U32 -> Wr

def run1 source · line 867 · raw

@gs:List<&2, String> -> @+width:U32 -> @st:Wr -> Wr

Grapheme clusters, for a word wider than the line.

def start2 source · line 874 · raw

@ok:Bool -> @out:List<&2, String> -> @+w:String -> @+width:U32 -> Wr

def step2.pick source · line 881 · raw

@f:Bool -> @out:List<&2, String> -> @s:String -> @+w:String -> @+width:U32 -> Wr

def step2 source · line 888 · raw

@st:Wr -> @+w:String -> @+width:U32 -> Wr

def run2 source · line 895 · raw

@ws:List<&2, String> -> @+width:U32 -> @st:Wr -> Wr

def wrap.lines source · line 902 · raw

@st:Wr -> List<&2, String>

def wrap.slow source · line 910 · 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 913 · raw

@ls:List<&2, String> -> @+width:U32 -> Bool

def printable source · line 920 · raw

@+c:U32 -> Bool

def ascii source · line 924 · raw

@s:String -> Bool

Only printable ASCII, so each char is one cluster one column wide.

def last.go source · line 931 · raw

@s:String -> @+c:U32 -> U32

def last source · line 939 · raw

@s:String -> U32

The last code point of s, or 0.

def two source · line 942 · raw

@gs:List<&2, String> -> Bool

def apart source · line 950 · 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 954 · 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 965 · raw

@cur:List<&2, String> -> String

def fw.close source · line 968 · raw

@out:List<&2, String> -> @cur:List<&2, String> -> List<&2, String>

def fw.from source · line 975 · raw

@st:Wr -> Fw

def fw.begin source · line 982 · raw

@fits:Bool -> @out:List<&2, String> -> @+w:String -> @+ww:U32 -> @+width:U32 -> @+aw:Bool -> Fw

def fw.start source · line 989 · raw

@asc:Bool -> @out:List<&2, String> -> @+w:String -> @+width:U32 -> Fw

def fw.add source · line 998 · 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 1006 · 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 1016 · 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 1024 · raw

@st:Fw -> @+aw:Bool -> @+w:String -> @+width:U32 -> Fw

def fw.step source · line 1031 · raw

@st:Fw -> @+w:String -> @+width:U32 -> Fw

def fw.run source · line 1034 · raw

@ws:List<&2, String> -> @+width:U32 -> @st:Fw -> Fw

def fw.lines source · line 1041 · raw

@st:Fw -> List<&2, String>

def wrap.fast source · line 1047 · 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 1050 · raw

@good:Bool -> @ls:List<&2, String> -> @text:String -> @+width:U32 -> List<&2, String>

def wrap source · line 1060 · 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 725 · 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 747 · 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 756 · 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.