A Go implementation of "An O(NP) Sequence Comparison Algorithm".
$ go get -u github.com/hattya/go.diff
package main
import (
"fmt"
"github.com/hattya/go.diff"
)
func main() {
a := []rune("acbdeacbed")
b := []rune("acebdabbabed")
cl := diff.Runes(a, b)
i := 0
for _, c := range cl {
for ; i < c.A; i++ {
fmt.Printf(" %c\n", a[i])
}
for j := c.A; j < c.A+c.Del; j++ {
fmt.Printf("- %c\n", a[j])
}
for j := c.B; j < c.B+c.Ins; j++ {
fmt.Printf("+ %c\n", b[j])
}
i += c.Del
}
for ; i < len(a); i++ {
fmt.Printf(" %c\n", a[i])
}
}
go.diff is distributed under the terms of the MIT License.
S. Wu, U. Manber, G. Myers, and W. Miller, "An O(NP) Sequence Comparison Algorithm" August 1989