Skip to content

arrays.diff

fn diff #

fn diff[T](a []T, b []T) &DiffContext[T]

diff returns the difference of two arrays.

fn DiffContextFlag.from #

fn DiffContextFlag.from[W](input W) !DiffContextFlag

fn DiffContextFlag.zero #

fn DiffContextFlag.zero() DiffContextFlag

fn (DiffContextFlag) is_empty #

fn (e &DiffContextFlag) is_empty() bool

fn (DiffContextFlag) has #

fn (e &DiffContextFlag) has(flag_ DiffContextFlag) bool

fn (DiffContextFlag) all #

fn (e &DiffContextFlag) all(flag_ DiffContextFlag) bool

fn (DiffContextFlag) set #

fn (mut e DiffContextFlag) set(flag_ DiffContextFlag)

fn (DiffContextFlag) set_all #

fn (mut e DiffContextFlag) set_all()

fn (DiffContextFlag) clear #

fn (mut e DiffContextFlag) clear(flag_ DiffContextFlag)

fn (DiffContextFlag) clear_all #

fn (mut e DiffContextFlag) clear_all()

fn (DiffContextFlag) toggle #

fn (mut e DiffContextFlag) toggle(flag_ DiffContextFlag)

fn (DiffContext[T]) generate_patch #

fn (mut c DiffContext[T]) generate_patch(param DiffGenStrParam) string

generate_patch generate a diff string of two arrays.

struct DiffChange #

struct DiffChange {
pub mut:
	a   int // position in input a []T
	b   int // position in input b []T
	del int // delete Del elements from input a
	ins int // insert Ins elements from input b
}

DiffChange contains one or more deletions or inserts at one position in two arrays.

struct DiffContext #

struct DiffContext[T] {
mut:
	a     []T
	b     []T
	flags []DiffContextFlag
	max   int
	// forward and reverse d-path endpoint x components
	forward []int
	reverse []int
pub mut:
	changes []DiffChange
}

struct DiffGenStrParam #

@[params]
struct DiffGenStrParam {
pub mut:
	colorful     bool
	unified      int = 3 // how many context lines before/after diff block
	block_header bool // output `@@ -3,4 +3,5 @@` or not
}