QueryableOrderedSet<T> class

This is an implementation of OrderedSet that allows you to more efficiently query the list.

You can register a set of queries, i.e., predefined sub-types, whose results, i.e., subsets of this set, are then cached. Since the queries have to be type checks, and types are runtime constants, this can be vastly optimized.

If you find yourself doing a lot of:

  orderedSet.whereType<Foo>()

On your code, and are concerned you are iterating a very long O(n) list to find a handful of elements, specially if this is done every tick, you can use this class, that pays a small O(number of registers) cost on add, but lets you find (specific) subsets at O(0).

Note that you can change strictMode to allow for querying for unregistered types; if you do so, the registration cost is payed on the first query.

Inheritance
Available extensions

Constructors

QueryableOrderedSet({int comparator(T e1, T e2)?, bool strictMode = true})

Properties

first → T
The first element.
no setterinherited
firstOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The first element of this iterator, or null if the iterable is empty.
no setter
hashCode int
The hash code for this object.
no setterinherited
indexed Iterable<(int, T)>

Available on Iterable<T>, provided by the IterableExtensions extension

Pairs of elements of the indices and elements of this iterable.
no setter
isEmpty bool
Whether this collection has no elements.
no setterinherited
isNotEmpty bool
Whether this collection has at least one element.
no setterinherited
iterator Iterator<T>
A new Iterator that allows iterating the elements of this Iterable.
no setterinherited
last → T
The last element.
no setterinherited
lastOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The last element of this iterable, or null if the iterable is empty.
no setter
length int
Gets the current length of this.
no setterinherited
nonNulls Iterable<T>

Available on Iterable<T?>, provided by the NullableIterableExtensions extension

The non-null elements of this iterable.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single → T
Checks that this iterable has only one element, and returns that element.
no setterinherited
singleOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The single element of this iterator, or null.
no setter
strictMode bool
Controls whether running an unregistered query throws an error or performs just-in-time filtering.
final
wait Future<List<T>>

Available on Iterable<Future<T>>, provided by the FutureIterable extension

Waits for futures in parallel.
no setter

Methods

add(T t) bool
Adds the element e to this, and returns whether the element was added or not. If the element already exists in the collection, it isn't added.
override
addAll(Iterable<T> elements) int
Adds each element of the provided elements to this and returns the number of elements added.
inherited
any(bool test(T element)) bool
Checks whether any element of this iterable satisfies test.
inherited
asNameMap() Map<String, T>

Available on Iterable<T>, provided by the EnumByName extension

Creates a map from the names of enum values to the values.
byName(String name) → T

Available on Iterable<T>, provided by the EnumByName extension

Finds the enum value in this list with name name.
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
clear() → void
Removes all elements of this.
override
contains(Object? element) bool
Whether the collection contains an element equal to element.
inherited
elementAt(int index) → T
Returns the indexth element.
inherited
elementAtOrNull(int index) → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The element at position index of this iterable, or null.
every(bool test(T element)) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(T element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(T element), {T orElse()?}) → T
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, T element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<T> other) Iterable<T>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(T element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
isRegistered<C>() bool
Whether type C is registered as a cache
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(T element), {T orElse()?}) → T
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(T e)) 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
query<C extends T>() Iterable<C>
Allow you to find a subset of this set with all the elements e for which the condition e is C is true. This is equivalent to
rebalanceAll() → void
Allows you to rebalance the whole tree. If you are dealing with non-deterministic compare functions, you probably need to consider rebalancing. If the result of the priority function for some elements changes, rebalancing is needed. In general, be careful with using comparing functions that can change. If only a few known elements need rebalancing, you can use rebalanceWhere. Note: rebalancing is not stable.
inherited
rebalanceWhere(bool test(T element)) → void
Allows you to rebalance only a portion of the tree. If you are dealing with non-deterministic compare functions, you probably need to consider rebalancing. If the priority function changed for certain known elements but not all, you can use this instead of rebalanceAll. In general be careful with using comparing functions that can change. Note: rebalancing is not stable.
inherited
reduce(T combine(T value, T element)) → T
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
register<C extends T>() → void
Adds a new cache for a subtype C of T, allowing you to call query. If the cache already exists this operation is a no-op.
remove(T e) bool
Remove a single element that is equal to e.
override
removeAll(Iterable<T> elements) Iterable<T>
Remove all elements and returns the removed elements.
inherited
removeAt(int index) bool
Removes the element at index.
inherited
removeWhere(bool test(T element)) Iterable<T>
Remove all elements that match the test condition; returns the removed elements.
inherited
reversed() Iterable<T>
The tree's elements in reversed order, cached when possible.
inherited
singleWhere(bool test(T element), {T orElse()?}) → T
The single element that satisfies test.
inherited
skip(int count) Iterable<T>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(T value)) Iterable<T>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
take(int count) Iterable<T>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(T value)) Iterable<T>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable = true}) List<T>
Creates a List containing the elements of this Iterable.
inherited
toSet() Set<T>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
Returns a string representation of (some of) the elements of this.
inherited
where(bool test(T element)) Iterable<T>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<C>() Iterable<C>
Creates a new lazy Iterable with all elements that have type C.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited