keysByPrefix method

  1. @override
TTIterable<String> keysByPrefix(
  1. String prefix, {
  2. int maxPrefixEditDistance = 0,
})
inherited

Iterates through TTMultiMap keys such that only keys prefixed by keyMapping(prefix) are included.

  • If keyMapping(prefix) is empty then returns empty Iterable.
  • If maxPrefixEditDistance > 0 then search will expand to all keys whose prefix is within a Hamming edit distance of maxPrefixEditDistance or less. For example searching for prefix 'cow' with maxPrefixEditDistance = 2 may give: cow,cowboy, chicken, crocodile, canary, cat, dog, donkey, goat, hawk, horse, zonkey

Results are ordered by key as:

  1. Results where key is prefixed by prefix (i.e. prefixEditDistance == 0) ordered lexicographically.
  2. Results of increasing edit distance ordered lexographically.

Throws ArgumentError if prefix is empty or null.

Implementation

@override
TTIterable<String> keysByPrefix(String prefix,
    {int maxPrefixEditDistance = 0}) {
  final key = _mapKey(prefix);
  final root = _root;
  return (identical(root, null) || key.isEmpty)
      ? TTIterable<String>.empty()
      : InOrderKeyIterable<V>(root, _version,
          prefixSearchResult:
              root.getClosestPrefixDescendant(key.runes.toList()),
          maxPrefixEditDistance: maxPrefixEditDistance);
}