Struct UnsafeParallelHashMap<TKey, TValue>.ParallelWriter
A parallel writer for a NativeParallelHashMap.
Namespace: Unity.Collections.LowLevel.Unsafe
Assembly: Unity.Collections.dll
Syntax
public struct UnsafeParallelHashMap<TKey, TValue>.ParallelWriter
Remarks
Use AsParallelWriter() to create a parallel writer for a NativeParallelHashMap.
Properties
Capacity
The number of key-value pairs that fit in the current allocation.
Declaration
public readonly int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int | The number of key-value pairs that fit in the current allocation. |
ThreadIndex
Returns the index of the current thread.
Declaration
public int ThreadIndex { get; }
Property Value
| Type | Description |
|---|---|
| int | The index of the current thread. |
Remarks
In a job, each thread gets its own copy of the ParallelWriter struct, and the job system assigns each copy the index of its thread.
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. |
| InvalidOperationException | If the underlying collection is full (as it cannot be resized within a parallel writer). |
Add(TKey, TValue, int)
Adds a new key-value pair.
Declaration
public void Add(TKey key, TValue item, int threadIndexOverride)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to add. |
| TValue | item | The value to add. |
| int | threadIndexOverride | The thread index which must be set by a field from a job struct with the NativeSetThreadIndexAttribute attribute. |
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. |
| InvalidOperationException | If the underlying collection is full (as it cannot be resized within a parallel writer). |
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.
TryAdd(TKey, TValue, int)
Adds a new key-value pair.
Declaration
public bool TryAdd(TKey key, TValue item, int threadIndexOverride)
Parameters
| Type | Name | Description |
|---|---|---|
| TKey | key | The key to add. |
| TValue | item | The value to add. |
| int | threadIndexOverride | The thread index which must be set by a field from a job struct with the NativeSetThreadIndexAttribute attribute. |
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.