Table of Contents

Class LinearDictionary<TKey, TValue>

Namespace
Uncreated.Warfare.Util.List
Assembly
Uncreated.Warfare.dll

An implementation of IDictionary<TKey, TValue> that uses equality operators to identify keys instead of hash codes, can be faster and have less of a memory impact in smaller collections.

public class LinearDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, IEnumerable

Type Parameters

TKey

Unique key in the dictionary.

TValue

Non-uniuqe value in the dictionary.

Inheritance
LinearDictionary<TKey, TValue>
Implements
IDictionary<TKey, TValue>
ICollection<KeyValuePair<TKey, TValue>>
IReadOnlyDictionary<TKey, TValue>
IEnumerable<KeyValuePair<TKey, TValue>>
Inherited Members
Extension Methods

Constructors

LinearDictionary(bool, params KeyValuePair<TKey, TValue>[])

public LinearDictionary(bool isReadOnly, params KeyValuePair<TKey, TValue>[] underlyingItems)

Parameters

isReadOnly bool
underlyingItems KeyValuePair<TKey, TValue>[]

LinearDictionary(IEqualityComparer<TKey>?, bool, params KeyValuePair<TKey, TValue>[])

public LinearDictionary(IEqualityComparer<TKey>? comparer, bool isReadOnly, params KeyValuePair<TKey, TValue>[] underlyingItems)

Parameters

comparer IEqualityComparer<TKey>
isReadOnly bool
underlyingItems KeyValuePair<TKey, TValue>[]

LinearDictionary(IEqualityComparer<TKey>?, params KeyValuePair<TKey, TValue>[])

public LinearDictionary(IEqualityComparer<TKey>? comparer, params KeyValuePair<TKey, TValue>[] underlyingItems)

Parameters

comparer IEqualityComparer<TKey>
underlyingItems KeyValuePair<TKey, TValue>[]

LinearDictionary(IEqualityComparer<TKey>?, int)

public LinearDictionary(IEqualityComparer<TKey>? comparer, int capacity = 0)

Parameters

comparer IEqualityComparer<TKey>
capacity int

LinearDictionary(params KeyValuePair<TKey, TValue>[])

public LinearDictionary(params KeyValuePair<TKey, TValue>[] underlyingItems)

Parameters

underlyingItems KeyValuePair<TKey, TValue>[]

LinearDictionary(int)

public LinearDictionary(int capacity = 0)

Parameters

capacity int

Properties

Capacity

The number of elements this dictionary can store before the underlying storage has to be resized.

public int Capacity { get; set; }

Property Value

int

Count

public int Count { get; }

Property Value

int

IsReadOnly

Defines methods to manipulate generic collections.

public bool IsReadOnly { get; }

Property Value

bool

this[TKey]

Gets or sets the element with the specified key.

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

Parameters

key TKey

The key of the element to get or set.

Property Value

TValue

The element with the specified key.

Exceptions

ArgumentNullException

key is null.

KeyNotFoundException

The property is retrieved and key is not found.

NotSupportedException

The property is set and the IDictionary<TKey, TValue> is read-only.

Keys

public LinearDictionary<TKey, TValue>.KeyCollection Keys { get; }

Property Value

LinearDictionary<TKey, TValue>.KeyCollection

Values

public LinearDictionary<TKey, TValue>.ValueCollection Values { get; }

Property Value

LinearDictionary<TKey, TValue>.ValueCollection

Methods

Add(TKey, TValue)

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

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

Clear()

Removes all items from the ICollection<T>.

public void Clear()

Exceptions

NotSupportedException

The ICollection<T> is read-only.

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.

CopyTo(Array, int)

Copies the elements of the ICollection to an Array, starting at a particular Array index.

public void CopyTo(Array array, int index)

Parameters

array Array

The one-dimensional Array that is the destination of the elements copied from ICollection. The Array must have zero-based indexing.

index int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

ArgumentOutOfRangeException

index is less than zero.

ArgumentException
    <code class="paramref">array</code> is multidimensional.  

-or-
The number of elements in the source ICollection is greater than the available space from index to the end of the destination array.
-or-
The type of the source ICollection cannot be cast automatically to the type of the destination array.

CopyTo(KeyValuePair<TKey, TValue>[], int)

Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.

public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)

Parameters

array KeyValuePair<TKey, TValue>[]

The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

ArgumentOutOfRangeException

arrayIndex is less than 0.

ArgumentException

The number of elements in the source ICollection<T> is greater than the available space from arrayIndex to the end of the destination array.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public LinearDictionary<TKey, TValue>.Enumerator GetEnumerator()

Returns

LinearDictionary<TKey, TValue>.Enumerator

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

GetOrAdd(TKey, out TValue, Func<TValue>)

Add an item if it's key doesn't already exist.

public bool GetOrAdd(TKey key, out TValue existingValue, Func<TValue> factory)

Parameters

key TKey
existingValue TValue
factory Func<TValue>

Returns

bool

true if the object is not found and added, otherwise false.

GetOrAdd(TKey, out TValue, Lazy<TValue>)

Add an item if it's key doesn't already exist.

public bool GetOrAdd(TKey key, out TValue existingValue, Lazy<TValue> value)

Parameters

key TKey
existingValue TValue
value Lazy<TValue>

Returns

bool

true if the object is not found and added, otherwise false.

GetOrAdd<TState>(TKey, out TValue, in TState, Func<TState, TValue>)

Add an item if it's key doesn't already exist.

public bool GetOrAdd<TState>(TKey key, out TValue existingValue, in TState state, Func<TState, TValue> value)

Parameters

key TKey
existingValue TValue
state TState
value Func<TState, TValue>

Returns

bool

true if the object is not found and added, otherwise false.

Type Parameters

TState

Remove(TKey)

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

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

TryGetKey(Func<TValue, bool>, out TKey)

Gets a key that passes a predicate.

public bool TryGetKey(Func<TValue, bool> predicate, out TKey key)

Parameters

predicate Func<TValue, bool>
key TKey

Returns

bool

TryGetKey(TValue, out TKey)

Gets a key that has a value equal to value.

public bool TryGetKey(TValue value, out TKey key)

Parameters

value TValue
key TKey

Returns

bool

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.

TryRemove(TKey, out TValue)

Remove an item by it's key and output the old value.

public bool TryRemove(TKey key, out TValue value)

Parameters

key TKey
value TValue

Returns

bool

true if the object is found and removed, otherwise false.