Struct NativeHashMap<TKey, TValue>
Namespace: Unity.Collections
Syntax
public struct NativeHashMap<TKey, TValue> : IDisposable where TKey : struct, IEquatable<TKey> where TValue : struct
Type Parameters
Name | Description |
---|---|
TKey | |
TValue |
Constructors
NativeHashMap(Int32, Allocator)
Declaration
public NativeHashMap(int capacity, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Int32 | capacity | |
Allocator | allocator |
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.
Item[TKey]
Declaration
public TValue this[TKey key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
TKey | key |
Property Value
Type | Description |
---|---|
TValue |
Length
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
Int32 |
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 value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to add. |
TValue | value | The value of the element to add. |
AsParallelWriter()
Returns parallel writer instance.
Declaration
public NativeHashMap<TKey, TValue>.ParallelWriter AsParallelWriter()
Returns
Type | Description |
---|---|
NativeHashMap.ParallelWriter<> |
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. |
Dispose()
Disposes of this container 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 |
Returns
Type | Description |
---|---|
JobHandle | A new job handle containing the prior handles as well as the handle for the job that deletes the container. |
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.
GetKeyArray(Allocator)
Declaration
public NativeArray<TKey> GetKeyArray(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator |
Returns
Type | Description |
---|---|
NativeArray<TKey> |
GetKeyValueArrays(Allocator)
Declaration
public NativeKeyValueArrays<TKey, TValue> GetKeyValueArrays(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator |
Returns
Type | Description |
---|---|
NativeKeyValueArrays<TKey, TValue> |
GetValueArray(Allocator)
Declaration
public NativeArray<TValue> GetValueArray(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator |
Returns
Type | Description |
---|---|
NativeArray<TValue> |
Remove(TKey)
Removes the element with the specified key from the container.
Declaration
public bool Remove(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to remove. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the key was removed from the container, otherwise returns false indicating key wasn't in the container. |
TryAdd(TKey, TValue)
Try adding an element with the specified key and value into the container. If the key already exist, the value won't be updated.
Declaration
public bool TryAdd(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to add. |
TValue | value | The value of the element to add. |
Returns
Type | Description |
---|---|
Boolean | Returns true if value is added into the container, otherwise returns false. |
TryGetValue(TKey, out TValue)
Declaration
public bool TryGetValue(TKey key, out TValue item)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
TValue | item |
Returns
Type | Description |
---|---|
Boolean |