Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public static fields | Properties | Public Member Functions | Static Public Member Functions | List of all members
Loyc.Collections.Map< K, V > Class Template Reference

An immutable dictionary. More...


Source file:
Inheritance diagram for Loyc.Collections.Map< K, V >:
Loyc.Collections.MapOrMMap< K, V > Loyc.Collections.ISetOperations< in T, in InSetT, out OutSetT >

Remarks

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]
 
this[K key] [get]
 
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]
 

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 ()
 
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.ISetOperations< in T, in InSetT, out OutSetT >
OutSetT With (T item)
 
OutSetT Without (T item)
 
OutSetT Union (InSetT other)
 
OutSetT Intersect (InSetT other)
 
OutSetT Except (InSetT other)
 
OutSetT Xor (InSetT other)
 

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
 

Constructor & Destructor Documentation

Loyc.Collections.Map< K, V >.Map ( )
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().

Loyc.Collections.Map< K, V >.Map ( IEqualityComparer< K >  comparer)
inline

Creates an empty map with the specified key comparer.

Loyc.Collections.Map< K, V >.Map ( IEnumerable< KeyValuePair< K, V >>  list)
inline

Creates a map with the specified elements.

Loyc.Collections.Map< K, V >.Map ( IEnumerable< KeyValuePair< K, V >>  list,
IEqualityComparer< K >  comparer 
)
inline

Creates a map with the specified elements and key comparer.

Member Function Documentation

Map<K,V> Loyc.Collections.Map< K, V >.Except ( MapOrMMap< K, V >  other)
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.

Map<K,V> Loyc.Collections.Map< K, V >.Intersect ( MapOrMMap< K, V >  other)
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.

Map<K,V> Loyc.Collections.Map< K, V >.Union ( MapOrMMap< K, V >  other)
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.

References Loyc.Collections.Map< K, V >.Union().

Referenced by Loyc.Collections.Map< K, V >.Union().

Map<K, V> Loyc.Collections.Map< K, V >.Union ( MapOrMMap< K, V >  other,
bool  replaceWithValuesFromOther 
)
inline

Returns a copy of the current map with the specified items added.

Parameters
replaceWithValuesFromOtherWhen 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.
Map<K, V> Loyc.Collections.Map< K, V >.With ( key,
value,
bool  replaceIfPresent = true 
)
inline

Returns a copy of the current map with an additional key-value pair.

Parameters
replaceIfPresentIf true, the existing key-value pair is replaced if present. Otherwise, the existing key-value pair is left unchanged.
Returns
A map with the specified key. If the key was already present and replaceIfPresent is false, the same set ('this') is returned.
Map<K, V> Loyc.Collections.Map< K, V >.Without ( key)
inline

Returns a copy of the current map without the specified key.

Returns
A map without the specified key. If the key was not present, the same set ('this') is returned.
Map<K,V> Loyc.Collections.Map< K, V >.Xor ( MapOrMMap< K, V >  other)
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.