Table of Contents

Class BaseFlexDictionary<TKey, TValue>

Namespace
Garyon.DataStructures
Assembly
Garyon.dll

A dictionary that allows indexing or setting values on non-existing keys without throwing exceptions.

public abstract class BaseFlexDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable where TKey : notnull

Type Parameters

TKey

The type of the keys that are being added to the dictionary.

TValue

The type of the values that are being paired with the keys in the dictionary.

Inheritance
BaseFlexDictionary<TKey, TValue>
Implements
IDictionary<TKey, TValue>
ICollection<KeyValuePair<TKey, TValue>>
IEnumerable<KeyValuePair<TKey, TValue>>
Derived
FlexDictionary<TKey, TValue>
Inherited Members
Extension Methods

Constructors

BaseFlexDictionary(BaseFlexDictionary<TKey, TValue>)

public BaseFlexDictionary(BaseFlexDictionary<TKey, TValue> other)

Parameters

other BaseFlexDictionary<TKey, TValue>

BaseFlexDictionary(IEnumerable<KeyValuePair<TKey, TValue>>)

public BaseFlexDictionary(IEnumerable<KeyValuePair<TKey, TValue>> kvps)

Parameters

kvps IEnumerable<KeyValuePair<TKey, TValue>>

BaseFlexDictionary(IEnumerable<TKey>, TValue)

public BaseFlexDictionary(IEnumerable<TKey> collection, TValue initialValue)

Parameters

collection IEnumerable<TKey>
initialValue TValue

BaseFlexDictionary(int)

public BaseFlexDictionary(int capacity)

Parameters

capacity int

Fields

Dictionary

The internal Dictionary<TKey, TValue> instance.

protected readonly Dictionary<TKey, TValue> Dictionary

Field Value

Dictionary<TKey, TValue>

Properties

Count

Gets the number of elements contained in the ICollection<T>.

public int Count { get; }

Property Value

int

The number of elements contained in the ICollection<T>.

this[TKey]

Gets or sets the value of the specified key. If the key does not exist, it will be added to the dictionary.

public virtual TValue this[TKey key] { get; set; }

Parameters

key TKey

The key whose value to get or set.

Property Value

TValue

The value of the key. When getting a non-existent key, it will have TValue's default value.

Keys

Gets an ICollection<T> containing the keys of the IDictionary<TKey, TValue>.

public ICollection<TKey> Keys { get; }

Property Value

ICollection<TKey>

An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.

Values

Gets an ICollection<T> containing the values in the IDictionary<TKey, TValue>.

public ICollection<TValue> Values { get; }

Property Value

ICollection<TValue>

An ICollection<T> containing the values in the object that implements IDictionary<TKey, TValue>.

Methods

Add(KeyValuePair<TKey, TValue>)

Adds an item to the ICollection<T>.

public virtual void Add(KeyValuePair<TKey, TValue> kvp)

Parameters

kvp KeyValuePair<TKey, TValue>

Exceptions

NotSupportedException

The ICollection<T> is read-only.

Add(TKey, TValue)

Adds an element with the provided key and value to the IDictionary<TKey, TValue>.

public virtual void Add(TKey key, TValue value)

Parameters

key TKey

The object to use as the key of the element to add.

value TValue

The object to use as the value of the element to add.

Exceptions

ArgumentNullException

key is null.

ArgumentException

An element with the same key already exists in the IDictionary<TKey, TValue>.

NotSupportedException

The IDictionary<TKey, TValue> is read-only.

AddWithInitializationValue(TKey)

protected void AddWithInitializationValue(TKey key)

Parameters

key TKey

Clear()

Removes all items from the ICollection<T>.

public void Clear()

Exceptions

NotSupportedException

The ICollection<T> is read-only.

Clone()

Clones this FlexDictionary<TKey, TValue> and adds all its keys to the resulting instance.

public abstract BaseFlexDictionary<TKey, TValue> Clone()

Returns

BaseFlexDictionary<TKey, TValue>

The cloned instance containing the same key-value pairs.

ContainsKey(TKey)

Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.

public bool ContainsKey(TKey key)

Parameters

key TKey

The key to locate in the IDictionary<TKey, TValue>.

Returns

bool

true if the IDictionary<TKey, TValue> contains an element with the key; otherwise, false.

Exceptions

ArgumentNullException

key is null.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<TKey, TValue>>

An enumerator that can be used to iterate through the collection.

GetNewEntryInitializationValue()

Gets the value that will be stored by default upon creating a new entry through the this accessor. This does not affect the Add(TKey, TValue) function.

protected abstract TValue GetNewEntryInitializationValue()

Returns

TValue

The new value that will be stored in the new entry.

Remove(TKey)

Removes the element with the specified key from the IDictionary<TKey, TValue>.

public virtual bool Remove(TKey key)

Parameters

key TKey

The key of the element to remove.

Returns

bool

true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original IDictionary<TKey, TValue>.

Exceptions

ArgumentNullException

key is null.

NotSupportedException

The IDictionary<TKey, TValue> is read-only.

RemoveKeys(IEnumerable<TKey>)

Removes a collection of keys from this FlexDictionary<TKey, TValue>. Keys that are not present will be simply ignored.

public int RemoveKeys(IEnumerable<TKey> keys)

Parameters

keys IEnumerable<TKey>

The keys to remove. Must not be null.

Returns

int

The number of keys that were removed.

RemoveKeys(params TKey[])

Removes a collection of keys from this FlexDictionary<TKey, TValue>. Keys that are not present will be simply ignored.

public int RemoveKeys(params TKey[] keys)

Parameters

keys TKey[]

The keys to remove. Must not be null.

Returns

int

The number of keys that were removed.

TryGetValue(TKey, out TValue)

Gets the value associated with the specified key.

public bool TryGetValue(TKey key, out TValue value)

Parameters

key TKey

The key whose value to get.

value TValue

When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Returns

bool

true if the object that implements IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.