Struct StringKeyDictionary<TValue>
An optimized System.Collections.Generic.Dictionary<TKey, TValue>-like data structure with a System.String key requirement.
Namespace: GDX.Collections.Generic
Syntax
[Serializable]
public struct StringKeyDictionary<TValue>
Type Parameters
| Name | Description |
|---|---|
| TValue |
Constructors
| Improve this Doc View SourceStringKeyDictionary(Int32)
Initializes the dictionary with at least minCapacity capacity.
Declaration
public StringKeyDictionary(int minCapacity)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | minCapacity | The minimal initial capacity to reserve. |
Fields
| Improve this Doc View SourceBuckets
Declaration
public int[] Buckets
Field Value
| Type | Description |
|---|---|
| System.Int32[] |
Count
Declaration
public int Count
Field Value
| Type | Description |
|---|---|
| System.Int32 |
Entries
Declaration
public StringKeyEntry<TValue>[] Entries
Field Value
| Type | Description |
|---|---|
| StringKeyEntry<TValue>[] |
FreeListHead
Declaration
public int FreeListHead
Field Value
| Type | Description |
|---|---|
| System.Int32 |
Properties
| Improve this Doc View SourceItem[String]
Directly access a value by key.
Declaration
public TValue this[string key] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The target key to look for a value identified by. |
Property Value
| Type | Description |
|---|---|
| TValue |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown when a null |
| System.Collections.Generic.KeyNotFoundException | Thrown when the |
Methods
| Improve this Doc View SourceAddSafe(String, TValue)
Adds the key value pair to the dictionary, checking for duplicate entries and expanding if necessary.
Declaration
public bool AddSafe(string key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to add. |
| TValue | value | The value to add. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the entry was successfully created. |
AddUnchecked(String, TValue)
Adds the key value pair to the dictionary, without checking for available capacity or duplicate entries.
Declaration
public void AddUnchecked(string key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to add. |
| TValue | value | The value to add. |
AddWithExpandCheck(String, TValue)
Adds the key value pair to the dictionary, expanding if necessary but not checking for duplicate entries.
Declaration
public void AddWithExpandCheck(string key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to add. |
| TValue | value | The value to add. |
AddWithUniqueCheck(String, TValue)
Adds the key value pair to the dictionary, checking for duplicates but not expanding if necessary.
Declaration
public bool AddWithUniqueCheck(string key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to add. |
| TValue | value | The value to add. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the entry was successfully created. |
Clear()
Clears the dictionary.
Declaration
public void Clear()
ContainsKey(String)
Checks if the dictionary contains the given key.
Declaration
public bool ContainsKey(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to check for. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the dictionary contains the key. |
ExpandWhenFull()
Resizes the dictionary with the assumption that it is full. Do not use otherwise.
Declaration
public void ExpandWhenFull()
IndexOf(String)
Finds the index of the entry corresponding to a key.
Declaration
public int IndexOf(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to find the index of. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The index of the entry, or -1 if the entry does not exist. |
MoveNext(ref Int32)
Iterates the dictionary. NOTE: if you suspect the dictionary might be modified while iterating, this will not catch the error -- use the other overload instead.
Declaration
public bool MoveNext(ref int iteratedIndexCount)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | iteratedIndexCount | The number of indices iterated so far - pass in 0 at the start of iteration. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Whether or not the iterator found an entry |
MoveNext(ref Int32, out StringKeyEntry<TValue>)
Iterates the dictionary. NOTE: if you suspect the dictionary might be modified while iterating, this will not catch the error -- use the other overload instead.
Declaration
public bool MoveNext(ref int iteratedIndexCount, out StringKeyEntry<TValue> entry)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | iteratedIndexCount | The number of indices iterated so far - pass in 0 at the start of iteration. |
| StringKeyEntry<TValue> | entry | The entry returned by the iterator |
Returns
| Type | Description |
|---|---|
| System.Boolean | Whether or not the iterator found an entry |
MoveNext(ref Int32, Int32, in Int32, out StringKeyEntry<TValue>)
Iterates the dictionary.
Declaration
public IteratorState MoveNext(ref int iteratedIndexCount, int iteratorVersion, in int dictionaryVersion, out StringKeyEntry<TValue> entry)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | iteratedIndexCount | The number of indices iterated so far - pass in 0 at the start of iteration. |
| System.Int32 | iteratorVersion | The version when iteration started. |
| System.Int32 | dictionaryVersion | The current version of the dictionary - update this on add, remove, or clear operations. |
| StringKeyEntry<TValue> | entry | The entry returned by the iterator |
Returns
| Type | Description |
|---|---|
| IteratorState | Whether the iterator found an entry, finished iteration, or could not continue due to an invalid version. |
Reserve(Int32)
Expands the dictionary if it does not have enough empty space for capacityToReserve.
Declaration
public void Reserve(int capacityToReserve)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | capacityToReserve |
TryGetValue(String, out TValue)
Attempts to get the value for the given key; returns true if key was found, false otherwise.
Declaration
public bool TryGetValue(string key, out TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to retrieve. |
| TValue | value | The value of the entry found. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the entry was found; false otherwise. |
TryModifyValue(String, TValue)
Replaces the value of the entry if the entry exists.
Declaration
public bool TryModifyValue(string key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key of the entry to modify. |
| TValue | value | The new value of the entry. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the entry was found. |
TryRemove(String)
Removes the entry if it exists.
Declaration
public bool TryRemove(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to remove. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the entry was found. |
TryRemoveNoValueClear(String)
Removes the entry if it exists, but does not remove the value of the key value pair.
Declaration
public bool TryRemoveNoValueClear(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | key | The key to remove. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the entry was found. |