hammingDistance<E> function

int hammingDistance<E>(
  1. List<E> source,
  2. List<E> target, {
  3. DualEqualityTest<E, E>? test,
})

Finds the Hamming distance between two lists.

Parameters

  • source and target are two list of items.
  • test is an optional equality matcher.

Details

Hamming distance is between two equal-length list of items is the number of positions at which the corresponding items are different.

If length of the lists are not equal, a RangeError is thrown.


Complexity: Time O(n) | Space O(1)

Implementation

int hammingDistance<E>(
  List<E> source,
  List<E> target, {
  DualEqualityTest<E, E>? test,
}) {
  if (test == null) {
    return hammingDistanceDefault(source, target);
  }
  return hammingDistanceCustom(source, target, test);
}