class

Similar::Algorithms::IdentifyDistinct(Int)

Inherits Reference < Object

A utility struct to convert distinct items to unique integers.

This can be helpful on larger inputs to speed up the comparisons performed by doing a first pass where the data set gets reduced to (small) integers.

The idea is that instead of passing two sequences to a diffling algorithm you first pass it via IdentifyDistinct:

old = ["foo", "bar", "baz"]
new = ["foo", "blah", "baz"]
h = IdentifyDistinct(Int32).new(old, 0...old.size, new, 0...new.size)
ops = Similar.capture_diff(
  Algorithm::Myers,
  h.old_lookup,
  h.old_range,
  h.new_lookup,
  h.new_range
)

The indexes are the same as with the passed source ranges.

Constructors

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

Creates an int hasher for two sequences.

Source

Instance methods

new_lookup

Returns a lookup for the new side.

Source
new_range

Convenience method to get back the new range.

Source
old_lookup

Returns a lookup for the old side.

Source
old_range

Convenience method to get back the old range.

Source