Joutsen v0.5.0+12-g5dd5f7e
Public Member Functions | Properties | List of all members
Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType > Class Template Reference

A map implementation that uses the hashes to find keys and values. More...

Public Member Functions

 BidirectionalDictionary ()
 Creates an empty dictionary. More...
 
 BidirectionalDictionary (Mapping< KeyType, ValueType > map)
 Creates a new dictionary with predefined entries. More...
 
 BidirectionalDictionary (SCG.IEqualityComparer< KeyType > keyComparer, SCG.IEqualityComparer< ValueType > valueComparer)
 Creates a new dictionary using a custom comparers to calculate hashes. More...
 
 BidirectionalDictionary (int initialCapacity)
 Creates a new dictionary with a custom initial size of the hash table. More...
 
 BidirectionalDictionary (Mapping< KeyType, ValueType > map, SCG.IEqualityComparer< KeyType > keyComparer, SCG.IEqualityComparer< ValueType > valueComparer)
 Creates a new dictionary using predefined initial items and custom comparers to calculate hashes. More...
 
 BidirectionalDictionary (int initialCapacity, SCG.IEqualityComparer< KeyType > keyComparer, SCG.IEqualityComparer< ValueType > valueComparer)
 Creates a new dictionary with custom comparers to calculate hashes and a custom internal capacity. More...
 
void Add (KeyType key, ValueType value)
 Adds a new key value pair to the dictionary. More...
 
bool ContainsKey (KeyType key)
 Checks if a key is part of the dictionary. More...
 
bool ContainsValue (ValueType value)
 Checks if a value is part of the dictionary. More...
 
bool TryGetValue (KeyType key, out ValueType value)
 Tries to fetch a value based on a key. More...
 
ValueType GetValue (KeyType key, ValueType defaultValue)
 Fetches the value associated with a key or a default value. More...
 
bool TryGetKey (ValueType value, out KeyType key)
 Tries to fetch a key based on a value. More...
 
KeyType GetKey (ValueType value, KeyType defaultKey)
 Fetches the key associated with a value or a default key. More...
 
void Update (SCG.IEnumerable< SCG.KeyValuePair< KeyType, ValueType > > newValues)
 Adds or updates values in the map. More...
 
bool Remove (KeyType key)
 
bool Remove (ValueType value)
 
void Clear ()
 Removes all key value pairs. More...
 
override String ToString ()
 
IEnumerator< KeyValuePair< KeyType, ValueType > > GetEnumerator ()
 
void Update (SCG.IEnumerable< SCG.KeyValuePair< KeyType, ValueType > > newValues)
 Adds or updates values in the map. More...
 
new bool ContainsKey (KeyType key)
 Checks if a key is part of the map. More...
 
- Public Member Functions inherited from Joutsen.Collections.Generic.Collection< SCG.KeyValuePair< KeyType, ValueType > >
bool Contains (ItemType item, SCG.IEqualityComparer< ItemType > comparer)
 Checks if an item is part of the collection. More...
 
void Add (SCG.IEnumerable< ItemType > items)
 Adds multiple items to the collection. More...
 
bool ContainsKey (KeyType key)
 Checks if a key is part of the mapping. More...
 
ValueType GetValue (KeyType key, ValueType defaultValue)
 Fetches the value associated with a key or a default value. More...
 
bool TryGetValue (KeyType key, out ValueType value)
 Get a value if the key is part of the mapping. More...
 
- Public Member Functions inherited from Joutsen.Collections.Generic.Indexable< KeyType, ValueType >
IndexType IndexOf (ItemType item)
 Fetches the index of an itemin the list. More...
 
IndexType IndexOf (ItemType item, IEqualityComparer< ItemType > comparer)
 Fetches the index of an item in the list using a custom comparer. More...
 

Properties

SCG.IEnumerable< KeyType > Keys [get]
 Returns all the available keys. More...
 
SCG.IEnumerable< ValueType > Values [get]
 Returns all the available values. More...
 
int Count [get]
 Fetches the number of elements in the map. More...
 
ValueType this[KeyType key] [get, set]
 Fetches a value based on the provided key. More...
 
KeyType this[ValueType val] [get, set]
 Fetches a key based on the provided value. More...
 
bool IsReadOnly [get]
 
- Properties inherited from Joutsen.Collections.Generic.Map< KeyType, ValueType >
new ValueType this[KeyType key] [get, set]
 Fetches a or sets a value associated with a key. More...
 
new int Count [get]
 Fetches the number of elements in the map. More...
 
new SCG.IEnumerable< ValueType > Values [get]
 Fetches an iterator for the values in the mapping. More...
 
- Properties inherited from Joutsen.Collections.Generic.Mapping< KeyType, ValueType >
ValueType this[KeyType key] [get]
 Fetches a value associated with a key. More...
 
IEnumerable< KeyType > Keys [get]
 Fetches an iterator for the keys in the mapping. More...
 
IEnumerable< ValueType > Values [get]
 Fetches an iterator for the values in the mapping. More...
 
int Count [get]
 Fetches the number of elements in the mapping. More...
 
- Properties inherited from Joutsen.Collections.Generic.Indexable< KeyType, ValueType >
int Count [get]
 Determines the number of values in the list. More...
 
ItemType this[IndexType index] [get]
 Fetches the value associated with the index. More...
 

Detailed Description

A map implementation that uses the hashes to find keys and values.

Since
Unreleased
Remarks
The BidirectionalDictionary uses Dictionaries internaly for quick access to keys and values. Because of this keys and values need to be unique not only the pairs.

Constructor & Destructor Documentation

◆ BidirectionalDictionary() [1/6]

Creates an empty dictionary.

◆ BidirectionalDictionary() [2/6]

Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.BidirectionalDictionary ( Mapping< KeyType, ValueType >  map)

Creates a new dictionary with predefined entries.

Parameters
mapthe predefined entries of the dictionary
Remarks
Keys and values in the map need to be unique or an exception is thrown.

◆ BidirectionalDictionary() [3/6]

Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.BidirectionalDictionary ( SCG.IEqualityComparer< KeyType >  keyComparer,
SCG.IEqualityComparer< ValueType >  valueComparer 
)

Creates a new dictionary using a custom comparers to calculate hashes.

Parameters
keyComparerthe custom comparer for the keys
valueComparerthe custom comparer for the values

◆ BidirectionalDictionary() [4/6]

Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.BidirectionalDictionary ( int  initialCapacity)

Creates a new dictionary with a custom initial size of the hash table.

Parameters
initialCapacitythe initial capacity of the internal hashtable

◆ BidirectionalDictionary() [5/6]

Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.BidirectionalDictionary ( Mapping< KeyType, ValueType >  map,
SCG.IEqualityComparer< KeyType >  keyComparer,
SCG.IEqualityComparer< ValueType >  valueComparer 
)

Creates a new dictionary using predefined initial items and custom comparers to calculate hashes.

Parameters
mapthe predefined entries of the dictionary
keyComparerthe custom comparer for the keys
valueComparerthe custom comparer for the values
Remarks
Keys and values in the map need to be unique or an exception is thrown.

◆ BidirectionalDictionary() [6/6]

Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.BidirectionalDictionary ( int  initialCapacity,
SCG.IEqualityComparer< KeyType >  keyComparer,
SCG.IEqualityComparer< ValueType >  valueComparer 
)

Creates a new dictionary with custom comparers to calculate hashes and a custom internal capacity.

Parameters
keyComparerthe custom comparer for the keys
valueComparerthe custom comparer for the values
comparerthe custom comparer

Member Function Documentation

◆ Add()

void Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.Add ( KeyType  key,
ValueType  value 
)

Adds a new key value pair to the dictionary.

Parameters
keythe key that cane be used to find the value
valuethe value that cane be used to find the key

◆ Clear()

void Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.Clear ( )

Removes all key value pairs.

◆ ContainsKey()

bool Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.ContainsKey ( KeyType  key)

Checks if a key is part of the dictionary.

Parameters
keythe key to check
Returns
true if the key is in the dictionary, ohterwise false

Implements Joutsen.Collections.Generic.Map< KeyType, ValueType >.

◆ ContainsValue()

bool Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.ContainsValue ( ValueType  value)

Checks if a value is part of the dictionary.

Parameters
valuethe value to check
Returns
true if the value is in the dictionary, ohterwise false

◆ GetEnumerator()

IEnumerator< KeyValuePair< KeyType, ValueType > > Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.GetEnumerator ( )

◆ GetKey()

KeyType Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.GetKey ( ValueType  value,
KeyType  defaultKey 
)

Fetches the key associated with a value or a default key.

Parameters
valuethe value associated with the key to retrieve
defaultKeythe key to return if the value is not found in the map
Returns
the key associated with the value or the default key if the value is not found

◆ GetValue()

ValueType Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.GetValue ( KeyType  key,
ValueType  defaultValue 
)

Fetches the value associated with a key or a default value.

Parameters
keythe key associated with the value to retrieve
defaultValuethe value to return if the key is not found in the map
Returns
the value associated with the key or the default value if the key is not found

Implements Joutsen.Collections.Generic.Mapping< KeyType, ValueType >.

◆ Remove() [1/2]

bool Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.Remove ( KeyType  key)

◆ Remove() [2/2]

bool Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.Remove ( ValueType  value)

◆ ToString()

override String Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.ToString ( )

◆ TryGetKey()

bool Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.TryGetKey ( ValueType  value,
out KeyType  key 
)

Tries to fetch a key based on a value.

Parameters
valuethe value used to find the key
keythe output of the the key if it was found
Returns
true if a key was found based on the value, otherwise false

◆ TryGetValue()

bool Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.TryGetValue ( KeyType  key,
out ValueType  value 
)

Tries to fetch a value based on a key.

Parameters
keythe key used to find the value
valuethe output of the the value if it was found
Returns
true if a value was found based on the key, otherwise false

Implements Joutsen.Collections.Generic.Mapping< KeyType, ValueType >.

◆ Update()

void Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.Update ( SCG.IEnumerable< SCG.KeyValuePair< KeyType, ValueType > >  newValues)

Adds or updates values in the map.

Parameters
newValuesthe pairs that are used to modify the map
Remarks
All values whose associated key exists in the map are updated with the new values. Any key that does not exist is added along with the value associated with it. This method does not delete any keys.

Implements Joutsen.Collections.Generic.Map< KeyType, ValueType >.

Property Documentation

◆ Count

int Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.Count
get

Fetches the number of elements in the map.

Returns
the number of keys in the mapping

Implements Joutsen.Collections.Generic.Map< KeyType, ValueType >.

◆ IsReadOnly

bool Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.IsReadOnly
get

◆ Keys

SCG.IEnumerable<KeyType> Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.Keys
get

Returns all the available keys.

Implements Joutsen.Collections.Generic.Mapping< KeyType, ValueType >.

◆ this[KeyType key]

ValueType Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.this[KeyType key]
getset

Fetches a value based on the provided key.

Parameters
keythe key used to find the value
Returns
the value mapped to the key

Implements Joutsen.Collections.Generic.Map< KeyType, ValueType >.

◆ this[ValueType val]

KeyType Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.this[ValueType val]
getset

Fetches a key based on the provided value.

Parameters
valthe value used to find the key
Returns
the key mapped to the value

◆ Values

SCG.IEnumerable<ValueType> Joutsen.Collections.Generic.BidirectionalDictionary< KeyType, ValueType >.Values
get

Returns all the available values.

Implements Joutsen.Collections.Generic.Map< KeyType, ValueType >.