Struct NativeParallelMultiHashMap<TKey, TValue>
An unordered, expandable associative array. Each key can have more than one associated value.
Implements
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
[NativeContainer]
public struct NativeParallelMultiHashMap<TKey, TValue> : INativeDisposable where TKey : struct, IEquatable<TKey> where TValue : struct
Type Parameters
Name | Description |
---|---|
TKey | The type of the keys. |
TValue | The type of the values. |
Remarks
Unlike a regular NativeParallelHashMap, a NativeParallelMultiHashMap can store multiple key-value pairs with the same key.
The keys are not deduplicated: two key-value pairs with the same key are stored as fully separate key-value pairs.
Constructors
NativeParallelMultiHashMap(int, AllocatorHandle)
Returns a newly allocated multi hash map.
Declaration
public NativeParallelMultiHashMap(int capacity, AllocatorManager.AllocatorHandle allocator)
Parameters
Type | Name | Description |
---|---|---|
int | capacity | The number of key-value pairs that should fit in the initial allocation. |
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
Properties
Capacity
Returns the number of key-value pairs that fit in the current allocation.
Declaration
public int Capacity { get; set; }
Property Value
Type | Description |
---|---|
int | The number of key-value pairs that fit in the current allocation. |
Exceptions
Type | Condition |
---|---|
Exception | Thrown if |
IsCreated
Whether this hash map has been allocated (and not yet deallocated).
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
bool | True if this hash map has been allocated (and not yet deallocated). |
IsEmpty
Whether this hash map is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool | True if the hash map is empty or if the hash map has not been constructed. |
Methods
Add(TKey, TValue)
Adds a new key-value pair.
Declaration
public void Add(TKey key, TValue item)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to add. |
TValue | item | The value to add. |
Remarks
If a key-value pair with this key is already present, an additional separate key-value pair is added.
AsParallelWriter()
Returns a parallel writer for this hash map.
Declaration
public NativeParallelMultiHashMap<TKey, TValue>.ParallelWriter AsParallelWriter()
Returns
Type | Description |
---|---|
NativeParallelMultiHashMap<TKey, TValue>.ParallelWriter | A parallel writer for this hash map. |
Clear()
Removes all key-value pairs.
Declaration
public void Clear()
Remarks
Does not change the capacity.
ContainsKey(TKey)
Returns true if a given key is present in this hash map.
Declaration
public bool ContainsKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to look up. |
Returns
Type | Description |
---|---|
bool | True if the key was present in this hash map. |
Count()
Returns the current number of key-value pairs in this hash map.
Declaration
public int Count()
Returns
Type | Description |
---|---|
int | The current number of key-value pairs in this hash map. |
Remarks
Key-value pairs with matching keys are counted as separate, individual pairs.
CountValuesForKey(TKey)
Returns the number of values associated with a given key.
Declaration
public int CountValuesForKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to look up. |
Returns
Type | Description |
---|---|
int | The number of values associated with the key. Returns 0 if the key was not present. |
Dispose()
Releases all resources (memory and safety handles).
Declaration
public void Dispose()
Dispose(JobHandle)
Creates and schedules a job that will dispose this hash map.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps | A job handle. The newly scheduled job will depend upon this handle. |
Returns
Type | Description |
---|---|
JobHandle | The handle of a new job that will dispose this hash map. |
GetEnumerator()
Returns an enumerator over the key-value pairs of this hash map.
Declaration
public NativeParallelMultiHashMap<TKey, TValue>.KeyValueEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
NativeParallelMultiHashMap<TKey, TValue>.KeyValueEnumerator | An enumerator over the key-value pairs of this hash map. |
Remarks
A key with N values is visited by the enumerator N times.
GetKeyArray(AllocatorHandle)
Returns an array with a copy of all the keys (in no particular order).
Declaration
public NativeArray<TKey> GetKeyArray(AllocatorManager.AllocatorHandle allocator)
Parameters
Type | Name | Description |
---|---|---|
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
Returns
Type | Description |
---|---|
NativeArray<TKey> | An array with a copy of all the keys (in no particular order). |
Remarks
A key with N values is included N times in the array.
Use `GetUniqueKeyArray` of <xref href="Unity.Collections.NativeParallelHashMapExtensions" data-throw-if-not-resolved="false"></xref> instead if you only want one occurrence of each key.
GetKeyValueArrays(AllocatorHandle)
Returns a NativeKeyValueArrays with a copy of all the keys and values (in no particular order).
Declaration
public NativeKeyValueArrays<TKey, TValue> GetKeyValueArrays(AllocatorManager.AllocatorHandle allocator)
Parameters
Type | Name | Description |
---|---|---|
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
Returns
Type | Description |
---|---|
NativeKeyValueArrays<TKey, TValue> | A NativeKeyValueArrays with a copy of all the keys and values (in no particular order). |
Remarks
A key with N values is included N times in the array.
GetValueArray(AllocatorHandle)
Returns an array with a copy of all the values (in no particular order).
Declaration
public NativeArray<TValue> GetValueArray(AllocatorManager.AllocatorHandle allocator)
Parameters
Type | Name | Description |
---|---|---|
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
Returns
Type | Description |
---|---|
NativeArray<TValue> | An array with a copy of all the values (in no particular order). |
Remarks
The values are not deduplicated. If you sort the returned array, you can use Unique<T>(NativeArray<T>) to remove duplicate values.
GetValuesForKey(TKey)
Returns an enumerator over the values of an individual key.
Declaration
public NativeParallelMultiHashMap<TKey, TValue>.Enumerator GetValuesForKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to get an enumerator for. |
Returns
Type | Description |
---|---|
NativeParallelMultiHashMap<TKey, TValue>.Enumerator | An enumerator over the values of a key. |
Remove(NativeParallelMultiHashMapIterator<TKey>)
Removes a single key-value pair.
Declaration
public void Remove(NativeParallelMultiHashMapIterator<TKey> it)
Parameters
Type | Name | Description |
---|---|---|
NativeParallelMultiHashMapIterator<TKey> | it | An iterator representing the key-value pair to remove. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the iterator is invalid. |
Remove(TKey)
Removes a key and its associated value(s).
Declaration
public int Remove(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to remove. |
Returns
Type | Description |
---|---|
int | The number of removed key-value pairs. If the key was not present, returns 0. |
SetValue(TValue, NativeParallelMultiHashMapIterator<TKey>)
Sets a new value for an existing key-value pair.
Declaration
public bool SetValue(TValue item, NativeParallelMultiHashMapIterator<TKey> it)
Parameters
Type | Name | Description |
---|---|---|
TValue | item | The new value. |
NativeParallelMultiHashMapIterator<TKey> | it | The iterator representing a key-value pair. |
Returns
Type | Description |
---|---|
bool | True if a value was overwritten. |
TryGetFirstValue(TKey, out TValue, out NativeParallelMultiHashMapIterator<TKey>)
Gets an iterator for a key.
Declaration
public bool TryGetFirstValue(TKey key, out TValue item, out NativeParallelMultiHashMapIterator<TKey> it)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key. |
TValue | item | Outputs the associated value represented by the iterator. |
NativeParallelMultiHashMapIterator<TKey> | it | Outputs an iterator. |
Returns
Type | Description |
---|---|
bool | True if the key was present. |
TryGetNextValue(out TValue, ref NativeParallelMultiHashMapIterator<TKey>)
Advances an iterator to the next value associated with its key.
Declaration
public bool TryGetNextValue(out TValue item, ref NativeParallelMultiHashMapIterator<TKey> it)
Parameters
Type | Name | Description |
---|---|---|
TValue | item | Outputs the next value. |
NativeParallelMultiHashMapIterator<TKey> | it | A reference to the iterator to advance. |
Returns
Type | Description |
---|---|
bool | True if the key was present and had another value. |