TTSet class
A Set<String>
with prefix and near neighbour searching capability
across elements.
Usage
final ttSet = ternarytreap.TTSet()
..addAll([
'zebra',
'canary',
'goat',
'cat',
'chicken',
'sheep',
'cow',
'crocodile',
'hawk',
'dingo',
'dog',
'donkey',
'horse',
'kangaroo',
'rabbit',
'pig',
'rat',
'ape',
]);
print(ttSet.join(', '));
(ape, cat, chicken, cow, crocodile, dingo, dog, donkey, goat, hawk, horse, kangaroo, pig, rabbit, rat, sheep, zebra, canary)
Strings that start with 'ra', e.g. rabbit, rat
print(ttSet.lookupByPrefix('ra'));
(rabbit, rat)
Strings that start with 'ra' given max edit distance of 1. Eg: rabbit, rat, kangaroo, hawk, cat
print(ttSet.lookupByPrefix('ra', maxPrefixEditDistance: 1));
(rabbit, rat, hawk, kangaroo, cat)
Keys that start with 'din' given max edit distance of 2 Eg: dingo, donkey, dog, kangaroo, pig
print(ttSet.lookupByPrefix('din', maxPrefixEditDistance: 2));
(dingo, donkey, dog, kangaroo, pig)
Case sensitivity and other key transformations
Pass a KeyMapping during construction to specify key transform to be performed before all operations.
final ttSet = ternarytreap.TTSet(ternarytreap.lowercase)
..addAll(['TeStInG', 'Cat', 'cAt', 'testinG', 'DOG', 'dog']);
print(ttSet);
(cat, dog, testing)
- Inheritance
- Implemented types
- Available Extensions
Constructors
- TTSet({KeyMapping keyMapping = identity})
- Construct a new TTSet
-
TTSet.fromIterable(Iterable<
String> elements, {KeyMapping keyMapping = identity}) -
Construct a new TTSet and fill with
elements
. -
TTSet.fromJson(Map<
String, dynamic> json, {KeyMapping keyMapping = identity}) -
Construct a new TTSet from
json
.
Properties
- first → String
-
The first element.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Whether this collection has no elements.
no setterinherited
- isNotEmpty → bool
-
Whether this collection has at least one element.
no setterinherited
-
iterator
→ TTIterator<
String> -
An iterator that iterates over the elements of this set.
no setteroverride
- keyMapping → KeyMapping
-
The KeyMapping in use by this TTSet
no setter
- last → String
-
The last element.
no setterinherited
- length → int
-
The number of elements in this.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- single → String
-
Checks that this iterable has only one element, and returns that element.
no setterinherited
Methods
-
add(
String value) → bool -
Adds
value
to the set.override -
addAll(
Iterable< String> elements) → void -
Adds all
elements
to this set.inherited -
any(
bool test(String element)) → bool -
Checks whether any element of this iterable satisfies
test
.inherited -
cast<
R> () → Set< R> -
Provides a view of this set as a set of
R
instances.inherited -
clear(
) → void -
Removes all elements from the set.
inherited
-
contains(
Object? element) → bool -
Whether
value
is in the set.override -
containsAll(
Iterable< Object?> other) → bool -
Whether this set contains all the elements of
other
.inherited -
difference(
Set< Object?> other) → Set<String> -
Creates a new set with the elements of this that are not in
other
.inherited -
elementAt(
int index) → String -
Returns the
index
th 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 -
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> -
Creates the lazy concatenation of this iterable and
other
.inherited -
forEach(
void f(String element)) → void -
Invokes
action
on each element of this iterable in iteration order.inherited -
intersection(
Set< Object?> other) → Set<String> -
Creates a new set which is the intersection between this set and
other
.inherited -
join(
[String separator = ""]) → String -
Converts each element to a String and concatenates the strings.
inherited
-
lastWhere(
bool test(String value), {String orElse()?}) → String -
The last element that satisfies the given predicate
test
.inherited -
longestCommonKeyPrefixByKeyPrefix(
String prefix) → String - Find the longest common key prefix for all keys prefixed by prefix.
-
lookup(
Object? element) → String? -
If an object equal to
object
is in the set, return it.override -
lookupByPrefix(
String prefix, {int maxPrefixEditDistance = 0}) → TTIterable< String> -
Iterates through TTSet elements such
that only elements prefixed by keyMapping
(
prefix
)
are included. -
map<
T> (T f(String element)) → Iterable< T> -
The current elements of this iterable modified by
toElement
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent 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
-
remove(
Object? value) → bool -
Removes
value
from the set.override -
removeAll(
Iterable< Object?> elements) → void -
Removes each element of
elements
from this set.inherited -
removeWhere(
bool test(String element)) → void -
Removes all elements of this set that satisfy
test
.inherited -
retainAll(
Iterable< Object?> elements) → void -
Removes all elements of this set that are not elements in
elements
.inherited -
retainWhere(
bool test(String element)) → void -
Removes all elements of this set that fail to satisfy
test
.inherited -
singleWhere(
bool test(String value), {String orElse()?}) → String -
The single element that satisfies
test
.inherited -
skip(
int n) → Iterable< String> -
Creates an Iterable that provides all but the first
count
elements.inherited -
skipWhile(
bool test(String value)) → Iterable< String> -
Creates an
Iterable
that skips leading elements whiletest
is satisfied.inherited -
take(
int n) → Iterable< String> -
Creates a lazy iterable of the
count
first elements of this iterable.inherited -
takeWhile(
bool test(String value)) → Iterable< String> -
Creates a lazy iterable of the leading elements satisfying
test
.inherited -
toJson(
) → Map< String, dynamic> - Return structure for Json encoding
-
toList(
{bool growable = true}) → List< String> -
Creates a List containing the elements of this Iterable.
inherited
-
toSet(
) → Set< String> -
Creates a Set with the same elements and behavior as this
Set
.override -
toString(
) → String -
A string representation of this object.
inherited
-
union(
Set< String> other) → Set<String> -
Creates a new set which contains all the elements of this set and
other
.inherited -
where(
bool f(String element)) → Iterable< String> -
Creates a new lazy Iterable with all elements that satisfy the
predicate
test
.inherited -
whereType<
T> () → Iterable< T> -
Creates a new lazy Iterable with all elements that have type
T
.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited