@@ -1,15 +1,15 @@ -// Package diff provides a diff implementation -// for finite, indexable sequences with comparable elements +// Package diff provides a diff algorithm implementation +// for finite, indexable sequences with comparable elements. package diff import ( bits "0dev.org/bits" ) // Interface abstracts the required knowledge to perform a diff -// on any two comparable, fixed-length sequences +// on any two fixed-length sequences with comparable elements. type Interface interface { // The sequences' lengths Len() (int, int) // True when the sequences' elements at those indices are equal Equal(int, int) bool @@ -126,5 +126,21 @@ inMatch = false // ... and reset the current one } } return } + +// A diff.Interface implementation with plugable Equal function +type D struct { + Len1, Len2 int + EqualFunc func(i, j int) bool +} + +// Required per diff.Interface +func (d D) Len() (int, int) { + return d.Len1, d.Len2 +} + +// Required per diff.Interface +func (d D) Equal(i, j int) bool { + return d.EqualFunc(i, j) +}