edit

package
v0.0.0-...-4e6772a Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: BSD-3-Clause Imports: 3 Imported by: 1

Documentation

Overview

Package edit provides edit scripts. Edit scripts are a core notion for diffs. They represent a way to go from A to B by a sequence of insertions, deletions, and equal elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Op

type Op int8

An Op is a edit operation in a Script.

const (
	Del Op = -1 // delete
	Eq  Op = 0  // equal
	Ins Op = 1  // insert
)

func (Op) String

func (i Op) String() string

type Range

type Range struct {
	LowA, HighA int
	LowB, HighB int
}

A Range is a pair of clopen index ranges. It represents the elements A[LowA:HighA] and B[LowB:HighB].

func (*Range) IsDelete

func (r *Range) IsDelete() bool

IsDelete reports whether r represents a deletion in a Script. If so, the deleted elements are A[LowA:HighA].

func (*Range) IsEqual

func (r *Range) IsEqual() bool

IsEqual reports whether r represents a series of equal elements in a Script. If so, the elements A[LowA:HighA] are equal to the elements B[LowB:HighB].

func (*Range) IsInsert

func (r *Range) IsInsert() bool

IsInsert reports whether r represents an insertion in a Script. If so, the inserted elements are B[LowB:HighB].

func (*Range) Len

func (r *Range) Len() int

Len reports the number of elements in r. In a deletion, it is the number of deleted elements. In an insertion, it is the number of inserted elements. For equal elements, it is the number of equal elements.

func (*Range) Op

func (r *Range) Op() Op

Op reports what kind of operation r represents. This can also be determined by calling r.IsInsert, r.IsDelete, and r.IsEqual, but this form is sometimes more convenient to use.

type Script

type Script struct {
	Ranges []Range
}

A Script is an edit script to alter A into B.

func NewScript

func NewScript(r ...Range) Script

NewScript returns a Script containing the ranges r. It is only a convenience wrapper used to reduce line noise.

func (*Script) IsIdentity

func (s *Script) IsIdentity() bool

IsIdentity reports whether s is the identity edit script, that is, whether A and B are identical.

func (*Script) Stat

func (s *Script) Stat() (ins, del int)

Stat reports the total number of insertions and deletions in s.

Jump to

Keyboard shortcuts

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