Struct NativeMultiHashMap<TKey, TValue>
Unordered associative array, a collection of keys and values. This container can store multiple values for every key.
Namespace: Unity.Collections
Syntax
public struct NativeMultiHashMap<TKey, TValue> : INativeDisposable, IDisposable, IEnumerable<KeyValue<TKey, TValue>> where TKey : struct, IEquatable<TKey> where TValue : struct
Type Parameters
Name | Description |
---|---|
TKey | The type of the keys in the container. |
TValue | The type of the values in the container. |
Constructors
NativeMultiHashMap(Int32, Allocator)
Constructs a new container with the specified initial capacity and type of memory allocation.
Declaration
public NativeMultiHashMap(int capacity, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Int32 | capacity | The initial capacity of the container. If the list grows larger than its capacity, the internal array is copied to a new, larger array. |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Properties
Capacity
The number of items that can fit in the container.
Declaration
public int Capacity { get; set; }
Property Value
Type | Description |
---|---|
Int32 | The number of items that the container can hold before it resizes its internal storage. |
Remarks
Capacity specifies the number of items the container can currently hold. You can change Capacity to fit more or fewer items. Changing Capacity creates a new array of the specified size, copies the old array to the new one, and then deallocates the original array memory.
IsCreated
Reports whether memory for the container is allocated.
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
Boolean | True if this container object's internal storage has been allocated. |
Remarks
Note that the container storage is not created if you use the default constructor. You must specify at least an allocation type to construct a usable container.
Warning: the IsCreated
property can't be used to determine whether a copy of a container is still valid.
If you dispose any copy of the container, the container storage is deallocated. However, the properties of
the other copies of the container (including the original) are not updated. As a result the IsCreated
property
of the copies still return true
even though the container storage has been deallocated.
Accessing the data of a native container that has been disposed throws a
IsEmpty
Reports whether container is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
Boolean | True if this container empty. |
Methods
Add(TKey, TValue)
Add an element with the specified key and value into the container. If the key already exist an ArgumentException will be thrown.
Declaration
public void Add(TKey key, TValue item)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to add. |
TValue | item | The value of the element to add. |
AsParallelWriter()
Returns parallel writer instance.
Declaration
public NativeMultiHashMap<TKey, TValue>.ParallelWriter AsParallelWriter()
Returns
Type | Description |
---|---|
NativeMultiHashMap.ParallelWriter<> | Parallel writer instance. |
Clear()
Clears the container.
Declaration
public void Clear()
Remarks
Containers capacity remains unchanged.
ContainsKey(TKey)
Determines whether an key is in the container.
Declaration
public bool ContainsKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to locate in the container. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the container contains the key. |
Count()
The current number of items in the container.
Declaration
public int Count()
Returns
Type | Description |
---|---|
Int32 | The item count. |
CountValuesForKey(TKey)
Count number of values for specified key.
Declaration
public int CountValuesForKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to locate in the container. |
Returns
Type | Description |
---|---|
Int32 |
Dispose()
Disposes of this multi-hashmap and deallocates its memory immediately.
Declaration
public void Dispose()
Dispose(JobHandle)
Safely disposes of this container and deallocates its memory when the jobs that use it have completed.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps | The job handle or handles for any scheduled jobs that use this container. |
Returns
Type | Description |
---|---|
JobHandle | A new job handle containing the prior handles as well as the handle for the job that deletes the container. |
Implements
Remarks
You can call this function dispose of the container immediately after scheduling the job. Pass
the JobHandle returned by
the Job.Schedule
method using the jobHandle
parameter so the job scheduler can dispose the container after all jobs
using it have run.
GetEnumerator()
Returns an IEnumerator interface for the container.
Declaration
public NativeMultiHashMap<TKey, TValue>.KeyValueEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
NativeMultiHashMap.KeyValueEnumerator<> | An IEnumerator interface for the container. |
GetKeyArray(Allocator)
Returns array populated with keys.
Declaration
public NativeArray<TKey> GetKeyArray(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Returns
Type | Description |
---|---|
NativeArray<TKey> | Array of keys. |
Remarks
Number of returned keys will match number of values in the container. If key contains multiple values it will appear number of times how many values are associated to the same key. If only unique key values desired use GetUniqueKeyArray instead.
GetKeyValueArrays(Allocator)
Returns arrays populated with keys and values.
Declaration
public NativeKeyValueArrays<TKey, TValue> GetKeyValueArrays(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Returns
Type | Description |
---|---|
NativeKeyValueArrays<TKey, TValue> | Array of keys-values. |
Remarks
If key contains multiple values, returned key array will contain multiple identical keys.
GetValueArray(Allocator)
Returns array populated with values.
Declaration
public NativeArray<TValue> GetValueArray(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Returns
Type | Description |
---|---|
NativeArray<TValue> | Array of values. |
GetValuesForKey(TKey)
Returns an enumerator for key that iterates through a container.
Declaration
public NativeMultiHashMap<TKey, TValue>.Enumerator GetValuesForKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | Key to enumerate values for. |
Returns
Type | Description |
---|---|
NativeMultiHashMap.Enumerator<> | An IEnumerator object that can be used to iterate through the container. |
Remove(TKey)
Removes all elements with the specified key from the container.
Declaration
public int Remove(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to remove. |
Returns
Type | Description |
---|---|
Int32 | Returns number of removed items. |
Remove(NativeMultiHashMapIterator<TKey>)
Removes all elements with the specified iterator the container.
Declaration
public void Remove(NativeMultiHashMapIterator<TKey> it)
Parameters
Type | Name | Description |
---|---|---|
NativeMultiHashMapIterator<TKey> | it | Iterator pointing at value to remove. |
SetValue(TValue, NativeMultiHashMapIterator<TKey>)
Replace value at iterator.
Declaration
public bool SetValue(TValue item, NativeMultiHashMapIterator<TKey> it)
Parameters
Type | Name | Description |
---|---|---|
TValue | item | Value. |
NativeMultiHashMapIterator<TKey> | it | Iterator |
Returns
Type | Description |
---|---|
Boolean | Returns true if value was sucessfuly replaced. |
TryGetFirstValue(TKey, out TValue, out NativeMultiHashMapIterator<TKey>)
Retrieve iterator for the first value for the key.
Declaration
public bool TryGetFirstValue(TKey key, out TValue item, out NativeMultiHashMapIterator<TKey> it)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key. |
TValue | item | Output value. |
NativeMultiHashMapIterator<TKey> | it | Iterator. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the container contains the key. |
TryGetNextValue(out TValue, ref NativeMultiHashMapIterator<TKey>)
Retrieve iterator to the next value for the key.
Declaration
public bool TryGetNextValue(out TValue item, ref NativeMultiHashMapIterator<TKey> it)
Parameters
Type | Name | Description |
---|---|---|
TValue | item | Output value. |
NativeMultiHashMapIterator<TKey> | it | Iterator. |
Returns
Type | Description |
---|---|
Boolean | Returns true if next value for the key is found. |