lib

class MultiValuedMap<K, V>(isKeyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash)

public let size :

public let keys :

public func put(key : K, value : V)

Associates the key with the given value in the map. Overwrites any existing values previously associated with the key

public func putAll(key : K, values : [V]) : ()

Associates the key with the given values in the map. These new values overwrite any previous values.

public func add(key : K, value : V)

Adds a value to the end of the list associated with the key

public func addFirst(key : K, value : V)

Adds the value to the beginning of the list for the associated key

public func addAll(key : K, values : [V])

Appends all the given values to the existing values associated with the given key

public func getFirst(key : K) : ?V

Retrieves the first value associated with the key

public func get(key : K) : [V]

Retrieves all the values associated with the given key

public func vals() : Iter.Iter<[V]>

public func entries() : Iter.Iter<(K, [V])>

Returns all the entries in the map as a tuple of key and values array

public func flattenedEntries() : Iter.Iter<(K, V)>

Returns all the entries in the map but instead of an iterator with a key and a values array ((K, [V])), it returns every value in the map in a tuple with its associated key ((K, V)).

public func singleValueEntries() : Iter.Iter<(K, V)>

Returns an iterator with key-value tuple pairs with every key in the map and its first value

public func remove(key : K) : [V]

Removes all the values associated with the specified key and returns them

If the key is not found, the function returns an empty array

public func clear()

Removes all the key-value pairs in the map

The MultiValuedMap is an extention of the TrieMap class that stores multiple values for a single key

Internally the values are in a Deque but are returned to the user as arrays.

public func fromEntries<K, V>(
  entries : [(K, [V])],
  isKeyEq : (K, K) -> Bool,
  keyHash : K -> Hash.Hash
) : MultiValuedMap<K, V>