package diff
Import Path
github.com/google/go-cmp/cmp/internal/diff (on go.dev)
Dependency Relation
imports 3 packages, and imported by one package
Involved Source Files
debug_disable.go
Package diff implements an algorithm for producing edit-scripts.
The edit-script is a sequence of operations needed to transform one list
of symbols into another (or vice-versa). The edits allowed are insertions,
deletions, and modifications. The summation of all edits is called the
Levenshtein distance as this problem is well-known in computer science.
This package prioritizes performance over accuracy. That is, the run time
is more important than obtaining a minimal Levenshtein distance.
Package-Level Type Names (total 7, in which 4 are exported)
EditScript represents the series of differences between two lists.
Dist is the Levenshtein distance and is guaranteed to be 0 if and only if
lists X and Y are equal.
LenX is the length of the X list.
LenY is the length of the Y list.
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.
stats returns a histogram of the number of each type of edit operation.
EditScript : expvar.Var
EditScript : fmt.Stringer
EditScript : github.com/aws/smithy-go/middleware.stringer
EditScript : context.stringer
EditScript : runtime.stringer
func Difference(nx, ny int, f EqualFunc) (es EditScript)
func github.com/google/go-cmp/cmp.coalesceAdjacentEdits(name string, es EditScript) (groups []cmp.diffStats)
EditType represents a single operation within an edit-script.
const Identity
const Modified
const UniqueX
const UniqueY
EqualFunc reports whether the symbols at indexes ix and iy are equal.
When called by Difference, the index is guaranteed to be within nx and ny.
func Difference(nx, ny int, f EqualFunc) (es EditScript)
Result is the result of comparison.
NumSame is the number of sub-elements that are equal.
NumDiff is the number of sub-elements that are not equal.
NumDiff int
NumSame int
Equal indicates whether the symbols are equal. Two symbols are equal
if and only if NumDiff == 0. If Equal, then they are also Similar.
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 BoolResult(b bool) Result
Package-Level Functions (total 3, in which 2 are exported)
BoolResult returns a Result that is either Equal or not Equal.
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.
Package-Level Variables (total 2, neither is exported)
Package-Level Constants (total 4, all are exported)
Identity indicates that a symbol pair is identical in both list X and Y.
Modified indicates that a symbol pair is a modification of each other.
UniqueX indicates that a symbol only exists in X and not Y.
UniqueY indicates that a symbol only exists in Y and not X.
The pages are generated with Golds v0.4.9. (GOOS=linux GOARCH=amd64)