module K8S::Hashdiff

Extended Modules

Defined in:

k8s/hashdiff.cr
k8s/hashdiff/hashdiff.cr
k8s/hashdiff/lcs.cr
k8s/hashdiff/linear_compare_arrays.cr
k8s/hashdiff/util.cr

Instance Method Summary

Instance Method Detail

def best_diff(obj1, obj2, **options) #

Best diff two objects, which tries to generate the smallest change set using different similarity values.

Hashdiff.best_diff is useful in case of comparing two objects which include similar hashes in arrays.

The options to use when comparing

  • :strict (Boolean) [true] whether numeric values will be compared on type as well as value. Set to false to allow comparing Integer, Float, BigDecimal to each other
  • :indifferent (Boolean) [false] whether to treat hash keys indifferently. Set to true to ignore differences between symbol keys (ie. {a: 1} ~= {'a' => 1})
  • :delimiter (String) ['.'] the delimiter used when returning nested key references
  • :numeric_tolerance (Numeric) [0] should be a positive numeric value. Value by which numeric differences must be greater than. By default, numeric values are compared exactly; with the :tolerance option, the difference between numeric values must be greater than the given value.
  • :strip (Boolean) [false] whether or not to call #strip on strings before comparing
  • :array_path (Boolean) [false] whether to return the path references for nested values in an array, can be used for patch compatibility with non string keys.
  • :use_lcs (Boolean) [true] whether or not to use an implementation of the Longest common subsequence algorithm for comparing arrays, produces better diffs but is slower.

returns an array of change tuples. e.g. [{ '+', 'a.b', '45' }, { '-', 'a.c', '5' }, { '~', 'a.x', '45', '63 }']

  a = {'x' => [{'a' => 1, 'c' => 3, 'e' => 5}, {'y' => 3}]}
  b = {'x' => [{'a' => 1, 'b' => 2, 'e' => 5}] }
  diff = Hashdiff.best_diff(a, b)
  diff.should == [{'-', 'x[0].c', 3}, {'+', 'x[0].b', 2}, {'-', 'x[1].y', 3}, {'-', 'x[1]', {}}]

[View source]
def comparable?(obj1 : T, obj2 : L, strict = true) : Bool forall T, L #

check if objects are comparable


[View source]
def compare_values(obj1 : Number, obj2 : Number, **options) : Bool #

check for equality or "closeness" within given tolerance


[View source]
def compare_values(obj1 : String, obj2 : String, **options) : Bool #

check for equality or "closeness" within given tolerance


[View source]
def compare_values(obj1 : T, obj2 : L, **options) : Bool forall T, L #

check for equality or "closeness" within given tolerance


[View source]
def count_diff(diffs) #

count node differences


[View source]
def count_nodes(obj) #

count total nodes for an object


[View source]
def decode_property_path(path, delimiter = '.') #

decode property path into an array [String] path Property-string [String] delimiter Property-string delimiter

e.g. "a.b[3].c" => ['a', 'b', 3, 'c']


[View source]
def diff(obj1 : NamedTuple, obj2 : NamedTuple, **options) #

[View source]
def diff(obj1 : T, obj2 : L, **options) forall T, L #

ameba:disable Metrics/CyclomaticComplexity


[View source]
def diff_array_lcs(arraya, arrayb, **options, &) #

diff array using LCS algorithm


[View source]
def lcs(arraya, arrayb, **options) : Array(Tuple(Int32, Int32)) #

caculate array difference using LCS algorithm http://en.wikipedia.org/wiki/Longest_common_subsequence_problem ameba:disable Metrics/CyclomaticComplexity


[View source]
def node(hash : Hash(K, V), parts : Array(W)) forall K, V, W #

get the node of hash by given path parts


[View source]
def prefix_append_array_index(prefix : Array(T), array_index : V, **opts) forall T, V #

[View source]
def prefix_append_array_index(prefix : String, array_index, **opts) #

[View source]
def prefix_append_key(key : V, prefix : Array(T), **opts) forall T, V #

[View source]
def prefix_append_key(key, prefix : String, **opts) #

[View source]
def similar?(obja, objb, **options) : Bool #

judge whether two objects are similar


[View source]