Enhanced C#
Language of your choice: library documentation
|
An immutable dictionary. More...
An immutable dictionary.
This class is a read-only dictionary, known in comp-sci nerd speak as a "persistent" data structure (not to be confused with the normal meaning of "persistent" as something that is saved to disk–this data structure is designed only to exist in memory). Map
allows modification only by creating new dictionaries. To create new dictionaries, this class provides the following methods:
See MMap<K,V> and InternalSet<T> for more information.
Public static fields | |
static readonly Map< K, V > | Empty = new Map<K, V>(InternalSet<K>.DefaultComparer) |
Properties | |
new InternalSet< KeyValuePair< K, V > > | FrozenInternalSet [get] |
new ICollection< K > | Keys [get] |
new ICollection< V > | Values [get] |
bool | IsReadOnly [get] |
Properties inherited from Loyc.Collections.MapOrMMap< K, V > | |
bool | IsEmpty [get] |
IEqualityComparer< K > | KeyComparer [get] |
InternalSet< KeyValuePair< K, V > > | FrozenInternalSet [get] |
V | this[K key] [get] |
V | this[K key, V defaultValue] [get] |
Retrieves the value associated with the specified key, or returns defaultValue if the key is not found. More... | |
int | Count [get] |
IEnumerable< K > | Keys [get] |
IEnumerable< V > | Values [get] |
Properties inherited from Loyc.Collections.IIndexed< K, V > | |
V | this[K key] [get] |
Gets the value associated with the specified key. More... | |
Public Member Functions | |
Map () | |
Creates an empty map. Consider using Empty instead. More... | |
Map (IEqualityComparer< K > comparer) | |
Creates an empty map with the specified key comparer. More... | |
Map (IEnumerable< KeyValuePair< K, V >> list) | |
Creates a map with the specified elements. More... | |
Map (IEnumerable< KeyValuePair< K, V >> list, IEqualityComparer< K > comparer) | |
Creates a map with the specified elements and key comparer. More... | |
Map< K, V > | With (K key, V value, bool replaceIfPresent=true) |
Returns a copy of the current map with an additional key-value pair. More... | |
Map< K, V > | Without (K key) |
Returns a copy of the current map without the specified key. More... | |
Map< K, V > | With (KeyValuePair< K, V > item) |
Map< K, V > | Union (MapOrMMap< K, V > other) |
Returns a copy of the current map with the specified items added; each item is added only if the key is not already present. More... | |
Map< K, V > | Union (MapOrMMap< K, V > other, bool replaceWithValuesFromOther) |
Returns a copy of the current map with the specified items added. More... | |
Map< K, V > | Intersect (MapOrMMap< K, V > other) |
Returns a copy of the current map with all keys removed from this map that are not present in the other map. The Values in 'other' are ignored. More... | |
Map< K, V > | Except (MapOrMMap< K, V > other) |
Returns a copy of the current map with all keys removed from this map that are present in the other map. The Values in 'other' are ignored. More... | |
Map< K, V > | Xor (MapOrMMap< K, V > other) |
Duplicates the current map and then modifies it so that it contains only keys that are present either in the current map or in the specified other map, but not both. More... | |
MMap< K, V > | AsMutable () |
Public Member Functions inherited from Loyc.Collections.MapOrMMap< K, V > | |
bool | ContainsKey (K key) |
bool | TryGetValue (K key, out V value) |
bool | Contains (KeyValuePair< K, V > item) |
void | CopyTo (KeyValuePair< K, V >[] array, int arrayIndex) |
InternalSet< KeyValuePair< K, V > >.Enumerator | GetEnumerator () |
V | TryGetValue (K key, V defaultValue) |
Synonym for this[key, defaultValue]. More... | |
virtual long | CountMemory (int sizeOfPair) |
Measures the total size of all objects allocated to this collection, in bytes, including the size of this object itself; see InternalSet<T>.CountMemory. More... | |
Public Member Functions inherited from Loyc.Collections.ITryGet< K, V > | |
V | TryGet (K key, out bool fail) |
Gets the item for the specified key or index, and does not throw an exception on failure. More... | |
Static Public Member Functions | |
static | operator MMap< K, V > (Map< K, V > copy) |
Additional Inherited Members | |
Protected Member Functions inherited from Loyc.Collections.MapOrMMap< K, V > | |
MapOrMMap (IEqualityComparer< K > comparer) | |
MapOrMMap (IEnumerable< KeyValuePair< K, V >> list) | |
MapOrMMap (IEnumerable< KeyValuePair< K, V >> list, IEqualityComparer< K > comparer) | |
Protected static fields inherited from Loyc.Collections.MapOrMMap< K, V > | |
static readonly EqualityComparer< V > | DefaultValueComparer = EqualityComparer<V>.Default |
|
inline |
Creates an empty map. Consider using Empty instead.
This is marked Obsolete
instead of protected
so that this class is compatible with the generic constraint known in C# as new()
.
|
inline |
Creates an empty map with the specified key comparer.
|
inline |
Creates a map with the specified elements.
|
inline |
Creates a map with the specified elements and key comparer.
|
inline |
Returns a copy of the current map with all keys removed from this map that are present in the other map. The Values in 'other' are ignored.
|
inline |
Returns a copy of the current map with all keys removed from this map that are not present in the other map. The Values in 'other' are ignored.
|
inline |
Returns a copy of the current map with the specified items added; each item is added only if the key is not already present.
Referenced by Loyc.Collections.Map< object, Loyc.Syntax.Precedence >.Union().
|
inline |
Returns a copy of the current map with the specified items added.
replaceWithValuesFromOther | When a key is present in both maps, the values from 'other' replace the values in the current map. If this is false, the values in this map are not replaced. |
|
inline |
Returns a copy of the current map with an additional key-value pair.
replaceIfPresent | If true, the existing key-value pair is replaced if present. Otherwise, the existing key-value pair is left unchanged. |
Referenced by Loyc.Syntax.ParsingService.Register().
|
inline |
Returns a copy of the current map without the specified key.
Referenced by Loyc.Syntax.ParsingService.Unregister().
|
inline |
Duplicates the current map and then modifies it so that it contains only keys that are present either in the current map or in the specified other map, but not both.