A dictionary class built on top of InternalSet<KeyValuePair<K,V>>.
- Template Parameters
-
Benchmarks show that this class is not as fast as the standard Dictionary{K,V} in most cases. however, it does have some advantages:
-
MMap allows null as a key (assuming it is based on the second version of Impl.InternalSet{T}).
-
MapOrMMap{K, V}.TryGetValue and MapOrMMap{K, V}.ContainsKey do not throw an incredibly annoying exception if you have the audacity to ask whether there is a null key in the collection.
-
This class supports fast cloning in O(1) time.
-
You can convert a mutable MMap{K,V} into an immutable Map{K,V}, a read-only dictionary that does not change when you change the original MMap.
-
This class has bonus methods defined by IDictionaryEx{K, V}.
-
The persistent map operations Union, Intersect, Except and Xor combine two dictionaries to create a new dictionary, without modifying either of the original dictionaries.
-
The methods With and Without create a new dictionary with a single item added or removed.
The documentation of InternalSet{T} describes how the data structure works.
|
| | MMap (IEqualityComparer< K >?comparer) |
| | Creates an empty map with the specified key comparer. More...
|
| |
| | MMap (IEnumerable< KeyValuePair< K, V >> copy) |
| | Creates a map with the specified elements. More...
|
| |
| | MMap (IEnumerable< KeyValuePair< K, V >> copy, IEqualityComparer< K >?comparer) |
| | Creates a map with the specified elements and key comparer. More...
|
| |
|
void | Add (K key, V value) |
| |
|
bool | Remove (K key) |
| |
|
void | Add (KeyValuePair< K, V > item) |
| |
|
void | Clear () |
| |
| bool | Remove (KeyValuePair< K, V > item) |
| | Removes a pair from the map. More...
|
| |
| virtual MMap< K, V > | Clone () |
| | Creates a copy of this map in O(1) time, by marking the current root node as frozen. More...
|
| |
| int | AddRange (MMap< K, V > data, bool replaceIfPresent=true) |
| | Merges the contents of the specified map into this map. More...
|
| |
| int | AddRange (IEnumerable< KeyValuePair< K, V >> data, bool replaceIfPresent=true) |
| | Merges the contents of the specified sequence into this map. More...
|
| |
| int | AddRange (IEnumerable< KeyValuePair< K, V >> data, DictEditMode mode) |
| | Merges the contents of the specified sequence into this map. More...
|
| |
|
bool | GetAndEdit (ref K key, ref V value, DictEditMode mode) |
| | Combines a get and change operation into a single method call. You rarely need to call this method directly; the following extension methods are based on it: DictionaryExt.SwapIfPresent, DictionaryExt.AddIfNotPresent, DictionaryExt.AddOrGetExisting, DictionaryExt.ReplaceIfPresent, DictionaryExt.SetAndGet.- Parameters
-
| key | Specifies the key that you want to search for in the map. Some implementations will update the key with the version of it found in the dictionary (although the new key is "equal" to the old key, it may be a different object); otherwise the key is left unchanged. |
| value | If the key is found, the old value is saved in this parameter. Otherwise, it is left unchanged. |
| mode | The specific behavior of this method depends on this. See DictEditMode to understand its effect. |
- Returns
- True if the pair's key ALREADY existed, false if not.
This method exists because some collections can optimize certain combinations of operations, avoiding the two traversals through the data structure that would be required by the IDictionary interface. This method shall not throw when the key is null, unless the AddIfNotPresent bit is set in mode and the dictionary does not support a null key.
|
| |
| bool | AddOrFind (ref KeyValuePair< K, V > pair, bool replaceIfPresent) |
| | For internal use. Adds a pair to the map if the key is not present, retrieves the existing key-value pair if the key is present, and optionally replaces the existing pair with a new pair. More...
|
| |
| Maybe< V > | GetAndRemove (K key) |
| | Gets the value associated with the specified key, then removes the pair with that key from the dictionary. More...
|
| |
| bool | GetAndRemove (ref KeyValuePair< K, V > pair) |
| | Gets the pair associated with pair.Key, then removes the pair with that key from the dictionary. More...
|
| |
|
MMap< K, V > | With (K key, V value, bool replaceIfPresent=true) |
| |
|
MMap< K, V > | With (KeyValuePair< K, V > item) |
| |
|
MMap< K, V > | Without (K key) |
| |
|
MMap< K, V > | Union (MapOrMMap< K, V > other) |
| |
|
MMap< K, V > | Union (MapOrMMap< K, V > other, bool replaceWithValuesFromOther) |
| |
|
MMap< K, V > | Intersect (MapOrMMap< K, V > other) |
| |
|
MMap< K, V > | Except (MapOrMMap< K, V > other) |
| |
|
MMap< K, V > | Xor (MapOrMMap< K, V > other) |
| |
|
Map< K, V > | AsImmutable () |
| |
|
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...
|
| |
|
new bool | ContainsKey (K key) |
| |
|
new bool | TryGetValue (K key, out V value) |
| |
|
void | AddRange (IEnumerable< T > e) |
| |
|
void | AddRange (IReadOnlyCollection< T > s) |
| |
|
OutSetT | With (T item) |
| |
|
OutSetT | Without (T item) |
| |
|
OutSetT | Union (InSetT other) |
| |
|
OutSetT | Intersect (InSetT other) |
| |
|
OutSetT | Except (InSetT other) |
| |
|
OutSetT | Xor (InSetT other) |
| |