Implementation of Multimap using hash tables.

The multimap does not store duplicate key->item pairs. Adding a new key->item pair equal to an existing key->item pair has no effect.

Keys and items may be null.

no subtypes hierarchy

Constructors
HashMultimapshared HashMultimap(Stability keyStability = ..., Stability itemStability = ..., {<Key->Item>*} entries = [])
Parameters:
  • keyStability = linked

    Determines whether a linked hash map with a stable iteration order will be used for this multimap's keys, defaulting to linked (stable).

  • itemStability = linked

    Determines whether a linked hash set with a stable iteration order will be used for the items for each of this multimap's keys, defaulting to linked (stable).

  • entries = []
Attributes
asMapshared actual Map<Key,MutableSet<Item>> asMap

Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values. Note that this.asMap.get(k) is equivalent to this.get(k) only when k is a key contained in the multimap; otherwise it returns null as opposed to an empty collection.

The returned map is a view of the underlying multimap.

Refines MutableSetMultimap.asMap ultimately refines Multimap.asMap
entriesshared actual MutableSet<Key->Item> entries
hashshared actual Integer hash

The hash value of the value, which allows the value to be an element of a hash-based set or key of a hash-based map. Implementations must respect the constraint that:

  • if x==y then x.hash==y.hash.

Therefore, a class which refines equals must also refine hash.

In general, hash values vary between platforms and between executions of the same program.

Note that when executing on a Java Virtual Machine, the 64-bit Integer value returned by an implementation of hash is truncated to a 32-bit integer value by taking the exclusive disjunction of the 32 lowest-order bits with the 32 highest-order bits, before returning the value to the caller.

Refines Identifiable.hash ultimately refines Object.hash
itemsshared actual Collection<Item> items

Returns a view collection containing the item from each key-item pair contained in this multimap, without collapsing duplicates (so items.size == size).

keysshared actual MutableSet<Key> keys

The Category of all keys for which a value is defined by this Correspondence.

Refines MutableSetMultimap.keys ultimately refines Correspondence.keys
sizeshared actual Integer size

The number of elements returned by the iterator of this stream, if the iterator terminates. In the case of an infinite stream, this operation never terminates.

Refines Multimap.size ultimately refines Iterable.size
Inherited Attributes
Attributes inherited from: Object
hash, string
Attributes inherited from: Collection<Element>
empty, permutations, string
Attributes inherited from: Correspondence<Key,Item>
keys
Attributes inherited from: Iterable<Element,Absent>
coalesced, cycled, distinct, empty, exceptLast, first, indexed, last, paired, rest, size, string
Attributes inherited from: Multimap<Key,Item>
Attributes inherited from: MultimapMutator<Key,Item>
Attributes inherited from: MutableMultimap<Key,Item>
Attributes inherited from: MutableSetMultimap<Key,Item>
Attributes inherited from: SetMultimap<Key,Item>
Attributes inherited from: SetMultimapMutator<Key,Item>
Methods
clearshared actual void clear()

Removes all key->item pairs from the multimap, leaving it Multimap.empty.

Refines MutableMultimap.clear ultimately refines MultimapMutator.clear
cloneshared actual SetMultimap<Key,Item> clone()

A shallow copy of this collection, that is, a collection with identical elements which does not change if this collection changes. If this collection is immutable, it is acceptable to return a reference to this collection. If this collection is mutable, a newly instantiated collection must be returned.

Refines SetMultimap.clone ultimately refines Collection.clone
definesshared actual Boolean defines(Key key)

Determines if there is a value defined for the given key.

Refines Multimap.defines ultimately refines Correspondence.defines
equalsshared actual Boolean equals(Object that)

Determine if two values are equal.

For any two non-null objects x and y, x.equals(y) may be written as:

x == y 

Implementations should respect the constraints that:

  • if x===y then x==y (reflexivity),
  • if x==y then y==x (symmetry),
  • if x==y and y==z then x==z (transitivity).

Furthermore it is recommended that implementations ensure that if x==y then x and y have the same concrete class.

A class which explicitly refines equals() is said to support value equality, and the equality operator == is considered much more meaningful for such classes than for a class which simply inherits the default implementation of identity equality from Identifiable.

Note that an implementation of equals() that always returns false does satisfy the constraints given above, as long as the class does not inherit Identifiable. Therefore, in very rare cases where there is no reasonable definition of value equality for a class, for example, function references (Callable), it is acceptable for equals() to be defined to return false for every argument.

Refines Identifiable.equals ultimately refines Object.equals
getshared actual MutableSet<Item> get(Key key)

Returns the value defined for the given key, or null if there is no value defined for the given key.

For any instance c of Correspondence, c.get(key) may be written using the item operator:

c[key]
Refines MutableSetMultimap.get ultimately refines Correspondence.get
iteratorshared actual Iterator<Key->Item> iterator()

An iterator for the elements belonging to this stream.

If this is a nonempty stream with type {Element+}, the iterator must produce at least one element.

Refines Multimap.iterator ultimately refines Iterable.iterator
putshared actual Boolean put(Key key, Item item)

Stores a key->item pair in this multimap.

Some multimap implementations allow duplicate key->item pairs, in which case put always adds a new key->item pair and increases the multimap size by 1. Other implementations prohibit duplicates, and storing a key->item pair that's already in the multimap has no effect.

Returns true if the method increased the size of the multimap, or false if the multimap already contained the key->item pair and doesn't allow duplicates

Refines MutableSetMultimap.put ultimately refines MultimapMutator.put
removeAllshared actual Set<Item> removeAll(Key key)

Removes all items associated with the key key.

Once this method returns, key will not be mapped to any items, so it will not appear in keys, asMap, or any other views.

Returns the items that were removed (possibly empty). The returned collection may be modifiable, but updating it will have no effect on the multimap.

replaceItemsshared actual Set<Item> replaceItems(Key key, {Item*} items)

Stores a collection of items with the same key, replacing any existing items for that key.

If items is empty, this is equivalent to removeAll(key).

Returns the collection of replaced items, or an empty collection if no items were previously associated with the key. The collection may be modifiable, but updating it will have no effect on the multimap.

Inherited Methods
Methods inherited from: Object
equals
Methods inherited from: Category<Element>
contains, containsAny, containsEvery
Methods inherited from: Collection<Element>
clone, combinations, contains
Methods inherited from: Correspondence<Key,Item>
defines, definesAny, definesEvery, get, getAll
Methods inherited from: Iterable<Element,Absent>
any, by, chain, collect, contains, count, defaultNullElements, each, every, filter, find, findLast, flatMap, fold, follow, frequencies, getFromFirst, group, indexes, interpose, iterator, locate, locateLast, locations, longerThan, map, max, narrow, partition, product, reduce, repeat, scan, select, sequence, shorterThan, skip, skipWhile, sort, spread, summarize, tabulate, take, takeWhile
Methods inherited from: Multimap<Key,Item>
Methods inherited from: MultimapMutator<Key,Item>
Methods inherited from: MutableMultimap<Key,Item>
Methods inherited from: MutableSetMultimap<Key,Item>
Methods inherited from: SetMultimap<Key,Item>
Methods inherited from: SetMultimapMutator<Key,Item>