~/bend-docscommunity

text.bend checks

raw source on the hub · import bend-kit-text@0.2.2.0/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 244 · raw

Data

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

type ByteRange source · line 443 · raw

Data

type Row source · line 628 · 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 644 · raw

Data

type Wr source · line 807 · raw

Data

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

type Fw source · line 949 · 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 changes source · line 248 · raw

@+dels:U32 -> @+ins:U32 -> List<&2, Move>

def canon.flush source · line 314 · raw

@d:Nat -> @i:Nat -> @rest:List<&2, Move> -> List<&2, Move>

def canon source · line 318 · 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 402 · raw

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

def lines.pick source · line 409 · raw

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

def lines source · line 417 · 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 425 · raw

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

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

def fnv source · line 432 · raw

@s:String -> U32

def diff_lines source · line 435 · raw

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

def diff_chars source · line 438 · raw

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

def byte_range.key source · line 446 · raw

@r:ByteRange -> U32

def byte_lines.finish source · line 451 · raw

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

def byte_lines.step source · line 458 · 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 466 · 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 477 · raw

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

def byte_lines source · line 482 · 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 486 · raw

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

def byte_equal.a source · line 490 · raw

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

def byte_equal.go source · line 494 · 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 503 · 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 510 · 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 521 · 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 530 · raw

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

def byte_values source · line 537 · 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 546 · raw

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

def byte_diff.fallback.b source · line 555 · 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 559 · 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 564 · 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 571 · 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 575 · 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 579 · 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 585 · 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 589 · 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 594 · 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 599 · raw

U32

def ahead.next source · line 602 · raw

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

def ahead.cons source · line 609 · raw

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

def is_change source · line 612 · raw

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

def ahead source · line 620 · 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 632 · raw

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

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

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

def hunk.show source · line 659 · raw

@h:Hunk -> String

def close source · line 665 · raw

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

def open source · line 672 · raw

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

def eol source · line 680 · 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 683 · raw

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

def emit source · line 689 · 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 698 · raw

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

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

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

def lev.init source · line 727 · raw

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

def distance source · line 747 · raw

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

Levenshtein distance by code point.

def words.flush source · line 752 · raw

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

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

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

def words source · line 778 · raw

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

Runs of non-space chars.

def fits source · line 781 · raw

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

def single.of source · line 784 · raw

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

def single source · line 792 · raw

@+s:String -> Bool

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

def ok.pick source · line 795 · raw

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

def ok source · line 803 · 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 810 · raw

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

def step0 source · line 817 · raw

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

def run0 source · line 825 · 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 832 · raw

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

def step1.pick source · line 839 · raw

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

def step1 source · line 846 · raw

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

def run1 source · line 854 · raw

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

Grapheme clusters, for a word wider than the line.

def start2 source · line 861 · raw

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

def step2.pick source · line 868 · raw

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

def step2 source · line 875 · raw

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

def run2 source · line 882 · raw

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

def wrap.lines source · line 889 · raw

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

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

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

def printable source · line 907 · raw

@+c:U32 -> Bool

def ascii source · line 911 · raw

@s:String -> Bool

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

def last.go source · line 918 · raw

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

def last source · line 926 · raw

@s:String -> U32

The last code point of s, or 0.

def two source · line 929 · raw

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

def apart source · line 937 · 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 941 · 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 952 · raw

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

def fw.close source · line 955 · raw

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

def fw.from source · line 962 · raw

@st:Wr -> Fw

def fw.begin source · line 969 · raw

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

def fw.start source · line 976 · raw

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

def fw.add source · line 985 · 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 993 · 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 1003 · 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 1011 · raw

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

def fw.step source · line 1018 · raw

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

def fw.run source · line 1021 · raw

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

def fw.lines source · line 1028 · raw

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

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

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

def wrap source · line 1047 · 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 155 · 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 160 · 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 168 · 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 179 · 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 185 · 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 190 · 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 198 · 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 211 · 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 219 · 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 222 · 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 236 · 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 251 · 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 259 · 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 268 · 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 273 · 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 282 · 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 289 · 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 294 · raw

@-A:Data -> @r:Pair(Ctx<A>, List<&2, Job>) -> @t:List<&2, Job> -> Pair(Ctx<A>, List<&2, Job>)

template solve source · line 299 · 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 329 · raw

@-A:Data -> @xs:List<&2, A> -> @arr:Array<A> -> @+i:U32 -> Array<A>

template array source · line 337 · raw

@-A:Data -> @+n:U32 -> @+v:A -> Array<A>

An array of n slots or more.

template moves.go source · line 341 · 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 349 · raw

@-A:Data -> @-eq:(@_:A -> @_:A -> Bool) -> @+a:List<&2, A> -> @+b:List<&2, A> -> List<&2, Move>

template diff source · line 361 · 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 364 · raw

@-A:Data -> @-key:(@_:A -> U32) -> @xs:List<&2, A> -> List<&2, U32>

template paired source · line 372 · 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 385 · 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 393 · 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 399 · 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 712 · 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 734 · 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 743 · 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.