module

Similar::Algorithms

Reopen module to add the high-level API methods

Class methods

common_prefix_len(old, old_range : Range(Int32, Int32), new, new_range : Range(Int32, Int32)) : Int32

Given two lookups and ranges calculates the length of the common prefix.

Source
common_suffix_len(old, old_range : Range(Int32, Int32), new, new_range : Range(Int32, Int32)) : Int32

Given two lookups and ranges calculates the length of common suffix.

Source
diff(alg : Similar::Algorithm, d : DiffHook, old, old_range : Range(Int32, Int32), new, new_range : Range(Int32, Int32)) : Nil

Creates a diff between old and new with the given algorithm.

Diffs old, between indices old_range and new between indices new_range.

Source
diff_deadline(alg : Similar::Algorithm, d : DiffHook, old, old_range : Range(Int32, Int32), new, new_range : Range(Int32, Int32), deadline = nil) : Nil

Creates a diff between old and new with the given algorithm with deadline.

Diffs old, between indices old_range and new between indices new_range.

This diff is done with an optional deadline that defines the maximal execution time permitted before it bails and falls back to an approximation. Note that not all algorithms behave well if they reach the deadline (LCS for instance produces a very simplistic diff when the deadline is reached in all cases).

Source
diff_slices(alg : Similar::Algorithm, d : DiffHook, old : Array, new : Array) : Nil

Shortcut for diffing slices with a specific algorithm.

Source
diff_slices_deadline(alg : Similar::Algorithm, d : DiffHook, old : Array, new : Array, deadline = nil) : Nil

Shortcut for diffing slices with a specific algorithm.

Source
is_empty_range(range : Range(Int32, Int32)) : Bool

Utility function to check if a range is empty.

Source
unique(lookup, range : Range(Int32, Int32))

Returns only unique items in the sequence as vector.

Each item is wrapped in a UniqueItem so that both the value and the index can be extracted.

Source

Nested types