type EditType … const Identity … const UniqueX … const UniqueY … const Modified … type EditScript … // String returns a human-readable string representing the edit-script where // Identity, UniqueX, UniqueY, and Modified are represented by the // '.', 'X', 'Y', and 'M' characters, respectively. func (es EditScript) String() string { … } // stats returns a histogram of the number of each type of edit operation. func (es EditScript) stats() (s struct{ … } // Dist is the Levenshtein distance and is guaranteed to be 0 if and only if // lists X and Y are equal. func (es EditScript) Dist() int { … } // LenX is the length of the X list. func (es EditScript) LenX() int { … } // LenY is the length of the Y list. func (es EditScript) LenY() int { … } type EqualFunc … type Result … // BoolResult returns a Result that is either Equal or not Equal. func BoolResult(b bool) Result { … } // Equal indicates whether the symbols are equal. Two symbols are equal // if and only if NumDiff == 0. If Equal, then they are also Similar. func (r Result) Equal() bool { … } // Similar indicates whether two symbols are similar and may be represented // by using the Modified type. As a special case, we consider binary comparisons // (i.e., those that return Result{1, 0} or Result{0, 1}) to be similar. // // The exact ratio of NumSame to NumDiff to determine similarity may change. func (r Result) Similar() bool { … } var randBool … // Difference reports whether two lists of lengths nx and ny are equal // given the definition of equality provided as f. // // This function returns an edit-script, which is a sequence of operations // needed to convert one list into the other. The following invariants for // the edit-script are maintained: // - eq == (es.Dist()==0) // - nx == es.LenX() // - ny == es.LenY() // // This algorithm is not guaranteed to be an optimal solution (i.e., one that // produces an edit-script with a minimal Levenshtein distance). This algorithm // favors performance over optimality. The exact output is not guaranteed to // be stable and may change over time. func Difference(nx, ny int, f EqualFunc) (es EditScript) { … } type path … // connect appends any necessary Identity, Modified, UniqueX, or UniqueY types // to the edit-script to connect p.point to dst. func (p *path) connect(dst point, f EqualFunc) { … } func (p *path) append(t EditType) { … } type point … func (p *point) add(dx, dy int) { … } // zigzag maps a consecutive sequence of integers to a zig-zag sequence. // // [0 1 2 3 4 5 ...] => [0 -1 +1 -2 +2 ...] func zigzag(x int) int { … }