diffmyers

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(from, to [][]byte, edits []Edit) ([]byte, error)

Print prints the edits in the unified diff format without the header.

Ref: https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html

Types

type Edit

type Edit struct {
	// Kind is the kind of edit. It is either an insert or a delete.
	Kind EditKind
	// FromPosition is the line to edit in the original sequence.
	FromPosition int
	// ToPosition is the line in the new sequence. It is only valid for
	// inserts.
	ToPosition int
}

Edit is an delete or insert operation.

func Diff

func Diff(from, to [][]byte) []Edit

Diff does a diff. It returns a [[]Edit] which when applied to the original sequence will result in the new sequence.

The algorithm is based on the paper "An O(ND) Difference Algorithm and Its Variations" by Eugene W. Myers. The paper is available at https://citeseerx.ist.psu.edu/doc/10.1.1.4.6927.

It implements the linear space refinement of the algorithm described in section 4b. This is the same algorithm used by git.

type EditKind

type EditKind int

EditKind is the kind of edit.

const (
	// EditKindDelete is a delete.
	EditKindDelete EditKind = iota + 1
	// EditKindInsert is an insert.
	EditKindInsert
)

Jump to

Keyboard shortcuts

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