MultiMap<K, V> class

An associative collection that stores elements as key-value pairs, sorted by key, and allows multiple elements with the same key.

In the C++ STL, this matches the behavior of std::multimap. It utilizes a balanced tree structure under the hood, mapping keys to a list of values.

Mixed-in types

Constructors

MultiMap([int compare(K, K)?])
Creates an empty MultiMap.
MultiMap.from(Iterable<Pair<K, V>> elements, [int compare(K, K)?])
Creates a MultiMap containing the key-value pairs of the given iterable.

Properties

empty bool
Returns true if the map is empty.
no setter
first Pair<K, V>
The first element.
no setterinherited
hashCode int
The hash code for this object.
no setteroverride
isEmpty bool
Whether this collection has no elements.
no setterinherited
isNotEmpty bool
Returns true if the map is not empty.
no setteroverride
iterator Iterator<Pair<K, V>>
A new Iterator that allows iterating the elements of this Iterable.
no setteroverride
last Pair<K, V>
The last element.
no setterinherited
length int
The number of elements in this Iterable.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single Pair<K, V>
Checks that this iterable has only one element, and returns that element.
no setterinherited
size int
Returns the total number of key-value pairs in the map.
no setter

Methods

any(bool test(Pair<K, V> element)) bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
clear() → void
Removes all elements from the map.
contains(Object? element) bool
Whether the collection contains an element equal to element.
inherited
containsKey(K key) bool
Returns true if the map contains the exact key. Time complexity: O(log N).
count(K key) int
Returns the number of values associated with the exact key. Time complexity: O(log N).
elementAt(int index) Pair<K, V>
Returns the indexth element.
inherited
equalRange(K key) Iterable<V>
Returns an iterable of all values associated with the key. Time complexity: O(log N).
erase(K key) int
Removes all values associated with the exact key. Time complexity: O(log N).
every(bool test(Pair<K, V> element)) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(Pair<K, V> element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(Pair<K, V> element), {Pair<K, V> orElse()?}) Pair<K, V>
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, Pair<K, V> element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<Pair<K, V>> other) Iterable<Pair<K, V>>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(Pair<K, V> element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
insert(K key, V value) → void
Inserts a new key-value pair into the map. Time complexity: O(log N).
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(Pair<K, V> element), {Pair<K, V> orElse()?}) Pair<K, V>
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(Pair<K, V> 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
reduce(Pair<K, V> combine(Pair<K, V> value, Pair<K, V> element)) Pair<K, V>
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
singleWhere(bool test(Pair<K, V> element), {Pair<K, V> orElse()?}) Pair<K, V>
The single element that satisfies test.
inherited
skip(int count) Iterable<Pair<K, V>>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(Pair<K, V> value)) Iterable<Pair<K, V>>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
swap(MultiMap<K, V> other) → void
Exchanges the contents of this map with those of other.
take(int count) Iterable<Pair<K, V>>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(Pair<K, V> value)) Iterable<Pair<K, V>>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable = true}) List<Pair<K, V>>
Creates a List containing the elements of this Iterable.
inherited
toSet() Set<Pair<K, V>>
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(Pair<K, V> element)) Iterable<Pair<K, V>>
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.
override