class

Similar::DiffOp

Inherits Reference < Object

Abstract base class for diff operations.

Instance methods

apply_to_hook(d : DiffHook) : Nil

Apply this operation to a diff hook.

Source
as_tag_tuple

Transform the op into a tuple of diff tag and ranges.

This is useful when operating on slices. The returned format is (tag, i1..i2, j1..j2):

  • Replace: a[i1..i2] should be replaced by b[j1..j2]
  • Delete: a[i1..i2] should be deleted (j1 == j2 in this case).
  • Insert: b[j1..j2] should be inserted at a[i1..i2] (i1 == i2 in this case).
  • Equal: a[i1..i2] is equal to b[j1..j2].
Source
empty?

Returns true if the operation is empty (both ranges empty).

Source
grow_left(adjust : Int32) : Nil

Grows the operation on the left.

Source
grow_right(adjust : Int32) : Nil

Grows the operation on the right.

Source
iter_changes(old, new)

Returns an iterator over the changes this operation expands to.

This method is a convenient way to automatically resolve the different ways in which a change could be encoded (insert/delete vs replace), look up the value from the appropriate slice and also handle correct index handling.

Source
new_range

Returns the new range.

Source
old_range

Returns the old range.

Source
shift_left(adjust : Int32) : Nil

Shifts the operation left by adjusting indices.

Source
shift_right(adjust : Int32) : Nil

Shifts the operation right by adjusting indices.

Source
shrink_left(adjust : Int32) : Nil

Shrinks the operation on the left.

Source
shrink_right(adjust : Int32) : Nil

Shrinks the operation on the right.

Source
tag

Returns the tag of the operation.

Source

Nested types