PrefixMatcher class

A TernaryTreap specialised for String values.

Use for prefix matching in autocompletion tasks etc.

A single Key can map to multiple Input strings. This relationship is formed by specified KeyMapping.

Iterating PrefixMatcher will return all input strings ordered first by Key then by insertion order.

PrefixMatcher is the function:

  • f : K ↦ ℘ (I) ∖ ∅

such that:

  • K is the set of all Key strings
  • I is the set of all Input strings
  • ℘ (I) ∖ ∅ is the powerset of I exluding the empty set

final  PrefixMatcher matcher = PrefixMatcher(TernaryTreap.lowerCollapse)

..addAll(['cat', 'Cat', 'CAT', 'CanaRy', 'CANARY']);


print(matcher.match('can'));


(CanaRy, CANARY)

Constructors

PrefixMatcher([KeyMapping keyMapping])
Constructs a new PrefixMatcher. [...]

Properties

iterator → Iterator<String>
Returns a new Iterator that allows iterating the elements of this Iterable. [...]
read-only
length → int
Returns the number of elements in this. [...]
read-only
ternaryTreap TernaryTreap<String>
Underlying TernaryTreap
final
first → String
Returns the first element.
read-only, inherited
hashCode → int
The hash code for this object.
read-only, inherited
isEmpty → bool
Returns true if there are no elements in this collection.
read-only, inherited
isNotEmpty → bool
Returns true if there is at least one element in this collection.
read-only, inherited
last → String
Returns the last element.
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited
single → String
Checks that this iterable has only one element, and returns that element.
read-only, inherited

Methods

add(String str) → void
Insert an input string for later querying. [...]
addAll(Iterable<String> iterable) → void
Add all strings from iterable to the PrefixMatcher.
contains(Object key) → bool
Does specified key exist?. [...]
match(String prefix) → Iterable<String>
Return an Iterable of previously added strings that start with prefix. [...]
remove(String key) → Iterable<String>
Remove specified string key and return list of strings that were associated with key See TernaryTreap.remove
any(bool test(String element)) → bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() → Iterable<R>
Provides a view of this iterable as an iterable of R instances.
inherited
elementAt(int index) → String
Returns the indexth element.
inherited
every(bool f(String element)) → bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> f(String element)) → Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(String value), {String orElse()}) → String
Returns the first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, String element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<String> other) → Iterable<String>
Returns the lazy concatentation of this iterable and other.
inherited
forEach(void f(String element)) → void
Applies the function f to each element of this collection in iteration order.
inherited
join([String separator = ""]) → String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(String value), {String orElse()}) → String
Returns the last element that satisfies the given predicate test.
inherited
map<T>(T f(String element)) → Iterable<T>
Returns a new lazy Iterable with elements that are created by calling f on each element of this Iterable in iteration order.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
reduce(String combine(String value, String element)) → String
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
singleWhere(bool test(String element), {String orElse()}) → String
Returns the single element that satisfies test.
inherited
skip(int count) → Iterable<String>
Returns an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(String value)) → Iterable<String>
Returns an Iterable that skips leading elements while test is satisfied.
inherited
take(int count) → Iterable<String>
Returns a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(String value)) → Iterable<String>
Returns a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable: true}) → List<String>
Creates a List containing the elements of this Iterable.
inherited
toSet() → Set<String>
Creates a Set containing the same elements as this iterable.
inherited
toString() → String
Returns a string representation of this object.
inherited
where(bool f(String element)) → Iterable<String>
Returns a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() → Iterable<T>
Returns a new lazy Iterable with all elements that have type T.
inherited

Operators

operator [](String key) → Iterable<String>
@returns Iterable of String objects corresponding to key. [...]
operator ==(dynamic other) → bool
The equality operator.
inherited