bitapScore function

double bitapScore(
  1. String pattern,
  2. {int errors = 0,
  3. int currentLocation = 0,
  4. int expectedLocation = 0,
  5. int distance = 100}
)

Calculates a score to a given bitap pattern

Implementation

double bitapScore(
  String pattern, {
  int errors = 0,
  int currentLocation = 0,
  int expectedLocation = 0,
  int distance = 100,
}) {
  final accuracy = errors / pattern.length;
  final proximity = (expectedLocation - currentLocation).abs();

  if (distance == 0.0) {
    // Dodge divide by zero error.
    return proximity != 0 ? 1.0 : accuracy;
  }

  return accuracy + (proximity / distance);
}