diff

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package diff compares sequences: the lines of two texts, or the words of two lines. It finds the changes with the histogram algorithm of git (xhistogram.c), which anchors on lines that occur rarely and so keeps the matches people expect in source code, falling back to Myers's O(ND) algorithm, with xdiff's cost limit, where every line repeats too often. Groups of changed lines are then slid to start and end where blank lines and indentation make them read as whole blocks, with git's indent heuristic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Intern

func Intern(a, b []string) ([]int32, []int32)

Intern numbers the distinct strings of a and b, equal strings sharing a number.

Types

type Hunk

type Hunk struct{ A0, A1, B0, B1 int }

Hunk is a change: the elements A0 to A1 of the old sequence replaced by B0 to B1 of the new one. A0 == A1 is an insertion before A0, B0 == B1 a deletion.

func Ints

func Ints(a, b []int32) []Hunk

Ints compares two sequences of interned elements, equal elements having equal values, and returns the hunks turning a into b, in order.

func Lines

func Lines(a, b []string) []Hunk

Lines compares the lines of two texts and returns the hunks of lines turning a into b, slid to read as blocks of code.

type Range

type Range struct{ Start, End int }

Range is a range of bytes, Start to End.

func Chars

func Chars(a, b string) (ra, rb []Range, same float64)

Chars compares two texts character by character, as Words does by words.

func Words

func Words(a, b string) (ra, rb []Range, same float64)

Words compares two texts word by word, as review tools highlight what changed within lines: words (letters, digits and underscores), runs of whitespace and other characters one at a time. It returns the byte ranges of a and b that changed, joined across the whitespace between them, and how much of the two texts stayed the same, from 0 to 1, by their bytes.

Jump to

Keyboard shortcuts

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