shadow:standard@CanIterate<V>, shadow:standard@CanIndexNullable<K,V>, shadow:standard@CanIndexStore<K,V>
interface Map<K is CanEqual<K>, V is CanEqual<V>>
Interface Map<K,V>
defines the operations that a class must implement to be a map, also known as a symbol table. A map is used to store key-value pairs with key type K
and value type V
. It should be possible to find keys quickly, allowing for efficient insertion and retrieval of associated values. Map<K,V>
differs from OrderedMap<K,V>
in that an ordering of key values is not required.
Modifiers | Return Types | Method and Description |
---|---|---|
public |
(Map<K,V>) |
clear() Removes all key-value pairs from the map. |
public readonly |
(boolean) |
containsKey(K key) Method should check whether the map contains a matching key. |
public readonly |
(boolean) |
containsValue(V value) Method should check whether the map contains a matching value. |
public readonly |
(boolean) |
isEmpty() Method should check whether or not the map is empty. |
public |
(nullable V) |
remove(K key) Method should remove the given key and its associated value. |
Modifiers | Return Types | Method and Description |
---|---|---|
public readonly get |
(int) |
size() Property should get the number of key-value pairs stored in the map as an |
public readonly get |
(long) |
sizeLong() Property should get the number of key-value pairs stored in the map as a |
public clear() => (Map<K,V>)
Removes all key-value pairs from the map. This operation should run in constant time.
map after being cleared
public readonly containsKey(K key) => (boolean)
Method should check whether the map contains a matching key. Since maps are usually organized by values, this operation should be efficient, running in either constant or logarithmic time, depending on the implementation.
key
- key to search for
true
if key is found
public readonly containsValue(V value) => (boolean)
Method should check whether the map contains a matching value. Note that maps are not usually organized by values, so this operation may require a linear search of the entire map.
value
- value to search for
true
if value is found
public readonly isEmpty() => (boolean)
Method should check whether or not the map is empty.
true
if the map is empty
public remove(K key) => (nullable V)
Method should remove the given key and its associated value.
key
- key to search for
associated value if key is present, null
otherwise
public readonly get size() => (int)
Property should get the number of key-value pairs stored in the map as an int
.
size of the map
public readonly get sizeLong() => (long)
Property should get the number of key-value pairs stored in the map as a long
.
size of the list