diff

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 3 Imported by: 0

README

diff

Fast diff library for Myers algorithm. The algorithm is described in "An O(ND) Difference Algorithm and its Variations", Eugene Myers, Algorithmica Vol. 1 No. 2, 1986, pp. 251-266.

BenchmarkBytesDiff/bytestrings-12         	      74	  16075247 ns/op	   91153 B/op	      12 allocs/op
BenchmarkDiff-12                          	  638715	      1882 ns/op	     680 B/op	       6 allocs/op
BenchmarkInts-12                          	  582735	      1971 ns/op	     728 B/op	       7 allocs/op
BenchmarkDiffRunes-12                     	  574765	      1919 ns/op	     728 B/op	       7 allocs/op
BenchmarkDiffBytes-12                     	   66489	     19385 ns/op	    3408 B/op	       8 allocs/op
BenchmarkDiffByteStrings-12               	   72484	     16184 ns/op	    3392 B/op	       8 allocs/op

Documentation

Overview

Package diff implements a difference algorithm. The algorithm is described in "An O(ND) Difference Algorithm and its Variations", Eugene Myers, Algorithmica Vol. 1 No. 2, 1986, pp. 251-266.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFileLines

func GetFileLines(filename string) ([]string, error)

func PrintDiffSlices

func PrintDiffSlices(src, dst []string)

Types

type Change

type Change struct {
	A, B int // position in input a and b
	Del  int // delete Del elements from input a
	Ins  int // insert Ins elements from input b
}

A Change contains one or more deletions or inserts at one position in two sequences.

func ByteStringSlices

func ByteStringSlices(a, b []string) []Change

ByteStrings returns the differences of two strings in bytes.

func ByteStrings

func ByteStrings(a, b string) []Change

ByteStrings returns the differences of two strings in bytes.

func Bytes

func Bytes(a, b []byte) []Change

Bytes returns the difference of two byte slices

func Diff

func Diff(n, m int, data Data) []Change

Diff returns the differences of data. data.Equal is called repeatedly with 0<=i<n and 0<=j<m

func Granular

func Granular(granularity int, changes []Change) []Change

Granular merges neighboring changes smaller than the specified granularity. The changes must be ordered by ascending positions as returned by this package.

func Ints

func Ints(a, b []int) []Change

Ints returns the difference of two int slices

func Runes

func Runes(a, b []rune) []Change

Runes returns the difference of two rune slices

type Data

type Data interface {
	// Equal returns whether the elements at i and j are considered equal.
	Equal(i, j int) bool
}

A type that satisfies diff.Data can be diffed by this package. It typically has two sequences A and B of comparable elements.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL