Struct NativeParallelHashMap<TKey, TValue>
An unordered, expandable associative array.
Implements
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
[NativeContainer]
public struct NativeParallelHashMap<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. |
Constructors
NativeParallelHashMap(int, AllocatorHandle)
Initializes and returns an instance of NativeParallelHashMap.
Declaration
public NativeParallelHashMap(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
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 this hash map is empty or if the map has not been constructed. |
this[TKey]
Gets and sets values by key.
Declaration
public TValue this[TKey key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to look up. |
Property Value
Type | Description |
---|---|
TValue | The value associated with the key. |
Remarks
Getting a key that is not present will throw. Setting a key that is not already present will add the key.
Exceptions
Type | Condition |
---|---|
ArgumentException | For getting, thrown if the key was not present. |
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 the key is already present, this method throws without modifying the hash map.
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the key was already present. |
AsParallelWriter()
Returns a parallel writer for this hash map.
Declaration
public NativeParallelHashMap<TKey, TValue>.ParallelWriter AsParallelWriter()
Returns
Type | Description |
---|---|
NativeParallelHashMap<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. |
Count()
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. |
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 NativeParallelHashMap<TKey, TValue>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
NativeParallelHashMap<TKey, TValue>.Enumerator | An enumerator over the key-value pairs of this hash map. |
GetKeyArray(AllocatorHandle)
Returns an array with a copy of all this hash map's 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 this hash map's keys (in no particular order). |
GetKeyValueArrays(AllocatorHandle)
Returns a NativeKeyValueArrays with a copy of all this hash map's keys and values.
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 this hash map's keys and values. |
Remarks
The key-value pairs are copied in no particular order. For all i
, Values[i]
will be the value associated with Keys[i]
.
GetValueArray(AllocatorHandle)
Returns an array with a copy of all this hash map's 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 this hash map's values (in no particular order). |
Remove(TKey)
Removes a key-value pair.
Declaration
public bool Remove(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to remove. |
Returns
Type | Description |
---|---|
bool | True if a key-value pair was removed. |
TryAdd(TKey, TValue)
Adds a new key-value pair.
Declaration
public bool TryAdd(TKey key, TValue item)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to add. |
TValue | item | The value to add. |
Returns
Type | Description |
---|---|
bool | True if the key-value pair was added. |
Remarks
If the key is already present, this method returns false without modifying the hash map.
TryGetValue(TKey, out TValue)
Returns the value associated with a key.
Declaration
public bool TryGetValue(TKey key, out TValue item)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to look up. |
TValue | item | Outputs the value associated with the key. Outputs default if the key was not present. |
Returns
Type | Description |
---|---|
bool | True if the key was present. |