diff

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultWagnerThreshold = 500

DefaultWagnerThreshold is the point at which the algorithms switch from Hirschberg to Wagner-Fischer. When both length of the comparable are smaller than this value Wagner-Fischer is used. The Wagner matrix will never be larger than this value of entries. If this is less than 4 the Wagner algorithm will not be used.

Variables

This section is empty.

Functions

func Default

func Default() differs.Diff

Default creates the default diff algorithm with default configuration.

The default is a hybrid Hirschberg with Wagner-Fischer using a reduction at each step and the default Wagner threshold.

func EnumerateValues

func EnumerateValues[T comparable, S ~[]T](result differs.Result, a, b S) collections.Enumerator[collections.Tuple2[step.Step, S]]

EnumerateValues will iterate the given result from a diff of the two given slices where the enumeration contains the correct values for each step.

Typically this is used for lines of a document. The number of A and B values must be the same as used when creating the given results.

func Hirschberg

func Hirschberg(length int, useReduce bool) differs.Diff

Hirschberg creates a new Hirschberg algorithm instance for performing a diff.

The given length is the initial score vector size. If the vector is too small it will be reallocated to the larger size. Use -1 to not preallocate the vectors. The useReduce flag indicates if the equal padding edges should be checked at each step of the algorithm or not.

func Hybrid

func Hybrid(length int, useReduce bool, size int) differs.Diff

Hybrid creates a new hybrid Hirschberg with Wagner-Fischer cutoff for performing a diff.

The given length is the initial score vector size of the Hirschberg algorithm. If the vector is too small it will be reallocated to the larger size. Use -1 to not preallocate the vectors. The useReduce flag indicates if the equal padding edges should be checked at each step of the algorithm or not.

The given size is the amount of matrix space, width * height, to use for the Wagner-Fischer. This must be greater than 4 fo use the cutoff. The larger the size, the more memory is used creating the matrix but the earlier the Wagner-Fischer algorithm can take over.

func Inline

func Inline[T comparable, S ~[]T](path differs.Result, a, b S, separator string) []string

Inline gets the difference with all values that are of the same step type joined into one string prefixed with a symbol indicating the step type.

func Merge

func Merge(path differs.Result, a, b []string) []string

Merge gets the labelled difference between the two slices using a similar output to the git merge differences output.

func PlusMinus

func PlusMinus(path differs.Result, a, b []string) []string

PlusMinus gets the labelled difference between the two slices. It formats the results by prepending a "+" to new strings in [b], a "-" for any to removed strings from [a], and " " if the strings are the same.

func Wagner

func Wagner(size int) differs.Diff

Wagner creates a new Wagner-Fischer algorithm instance for performing a diff.

The given size is the amount of matrix space, width * height, to preallocate for the Wagner-Fischer algorithm. Use -1 to not preallocate any matrix.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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