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
Properties | Public Member Functions | Protected Member Functions | Protected static fields | List of all members
Loyc.Collections.MapOrMMap< K, V > Class Template Reference

Common base class that contains code shared between Map{K,V} and MMap{K,V}. More...


Source file:
Inheritance diagram for Loyc.Collections.MapOrMMap< K, V >:
Loyc.Collections.Map< K, V > Loyc.Collections.MMap< K, V >

Remarks

Common base class that contains code shared between Map{K,V} and MMap{K,V}.

You might notice that although Map{K,V} and MMap{K,V} have a common base class, Set{T} and MSet{T} do not, and this is a mere implementation detail. Since Set{T} is immutable, and small, and its fields can safely be initialized to 0 or null, its default value is a valid set and it makes sense to implement is as a struct. The same observation would apply to Map{K,V} except for one problem: the comparer. The user can supply a comparer of type IEqualityComparer<K>, but but Map{K,V} contains a set of type InternalSet<KeyValuePair<K,V>>, which requires a comparer of type IEqualityComparer<KeyValuePair<K,V>>. In general, a wrapper object is necessary to provide this comparer, and I decided to use the set itself as the wrapper object. Therefore, Map{K,V} implements this interface, and it must be a class so that it is not boxed every time it is converted to this interface.

Finally, since Map{K,V} and MMap{K,V} are both classes and share some of the same code, I decided to factor out the common code into this base class. The end.

Properties

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

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...
 

Protected Member Functions

 MapOrMMap (IEqualityComparer< K > comparer)
 
 MapOrMMap (IEnumerable< KeyValuePair< K, V >> list)
 
 MapOrMMap (IEnumerable< KeyValuePair< K, V >> list, IEqualityComparer< K > comparer)
 

Protected static fields

static readonly
EqualityComparer< V > 
DefaultValueComparer = EqualityComparer<V>.Default
 

Member Function Documentation

virtual long Loyc.Collections.MapOrMMap< K, V >.CountMemory ( int  sizeOfPair)
inlinevirtual

Measures the total size of all objects allocated to this collection, in bytes, including the size of this object itself; see InternalSet{T}.CountMemory.

V Loyc.Collections.MapOrMMap< K, V >.TryGetValue ( key,
defaultValue 
)
inline

Synonym for this[key, defaultValue].

Property Documentation

V Loyc.Collections.MapOrMMap< K, V >.this[K key, V defaultValue]
get

Retrieves the value associated with the specified key, or returns defaultValue if the key is not found.