Struct IntKeyDictionary<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 IntKeyDictionary<TValue>
Type Parameters
Name | Description |
---|---|
TValue |
Constructors
| Improve this Doc View SourceIntKeyDictionary(Int32)
Initializes the dictionary with at least minCapacity
capacity.
Declaration
public IntKeyDictionary(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 IntKeyEntry<TValue>[] Entries
Field Value
Type | Description |
---|---|
IntKeyEntry<TValue>[] |
FreeListHead
Declaration
public int FreeListHead
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
| Improve this Doc View SourceItem[Int32]
Directly access a value by key.
Declaration
public TValue this[int key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | 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(Int32, TValue)
Adds the key value pair to the dictionary, checking for duplicate entries and expanding if necessary.
Declaration
public bool AddSafe(int key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key | The key to add. |
TValue | value | The value to add. |
Returns
Type | Description |
---|---|
System.Boolean | True if the entry was successfully created. |
AddUnchecked(Int32, TValue)
Adds the key value pair to the dictionary, without checking for available capacity or duplicate entries.
Declaration
public void AddUnchecked(int key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key | The key to add. |
TValue | value | The value to add. |
AddWithExpandCheck(Int32, TValue)
Adds the key value pair to the dictionary, expanding if necessary but not checking for duplicate entries.
Declaration
public void AddWithExpandCheck(int key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key | The key to add. |
TValue | value | The value to add. |
AddWithUniqueCheck(Int32, TValue)
Adds the key value pair to the dictionary, checking for duplicates but not expanding if necessary.
Declaration
public bool AddWithUniqueCheck(int key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | 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(Int32)
Checks if the dictionary contains the given key.
Declaration
public bool ContainsKey(int key)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | 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(Int32)
Finds the index of the entry corresponding to a key.
Declaration
public int IndexOf(int key)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | 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.
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 |
Remarks
If you use iteratedIndexCount
during iteration, you need to decrement it by 1 to
properly access the current iterations index.
If you suspect the dictionary might be modified while iterating, this will not catch the error. You must use the other overload instead.
MoveNext(ref Int32, out IntKeyEntry<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 IntKeyEntry<TValue> entry)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | iteratedIndexCount | The number of indices iterated so far - pass in 0 at the start of iteration. |
IntKeyEntry<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 IntKeyEntry<TValue>)
Iterates the dictionary.
Declaration
public IteratorState MoveNext(ref int iteratedIndexCount, int iteratorVersion, in int dictionaryVersion, out IntKeyEntry<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. |
IntKeyEntry<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(Int32, out TValue)
Attempts to get the value for the given key; returns true if key was found, false otherwise.
Declaration
public bool TryGetValue(int key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | 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(Int32, TValue)
Replaces the value of the entry if the entry exists.
Declaration
public bool TryModifyValue(int key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | 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(Int32)
Removes the entry if it exists.
Declaration
public bool TryRemove(int key)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key | The key to remove. |
Returns
Type | Description |
---|---|
System.Boolean | True if the entry was found. |
TryRemoveNoValueClear(Int32)
Removes the entry if it exists, but does not remove the value of the key value pair.
Declaration
public bool TryRemoveNoValueClear(int key)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key | The key to remove. |
Returns
Type | Description |
---|---|
System.Boolean | True if the entry was found. |