docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct NativeParallelHashSet<T>.ParallelWriter

    A parallel writer for a NativeParallelHashSet.

    Namespace: Unity.Collections
    Assembly: Unity.Collections.dll
    Syntax
    [NativeContainerIsAtomicWriteOnly]
    public struct NativeParallelHashSet<T>.ParallelWriter
    Remarks

    Use AsParallelWriter() to create a parallel writer for a set.

    Properties

    Capacity

    The number of values that fit in the current allocation.

    Declaration
    public readonly int Capacity { get; }
    Property Value
    Type Description
    int

    The number of values that fit in the current allocation.

    Methods

    Add(T)

    Adds a new item. If the item is already present in the collection, this method should throw, but currently does not! Instead, it returns false without replacing said item.

    Declaration
    public bool Add(T item)
    Parameters
    Type Name Description
    T item

    The value to add.

    Returns
    Type Description
    bool

    True if the value is not already present.

    Remarks

    Prefer TryAdd(T) if your intent is to allow graceful failure, as this API will eventually become more strict (and begin to throw).

    Exceptions
    Type Condition
    InvalidOperationException

    If the underlying collection is full (as it cannot be resized within a parallel writer).

    Add(T, int)

    Adds a new item. If the item is already present in the collection, this method should throw, but currently does not! Instead, it returns false without replacing said item.

    Declaration
    public bool Add(T item, int threadIndexOverride)
    Parameters
    Type Name Description
    T 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 value is not already present.

    Remarks

    Prefer TryAdd(T) if your intent is to allow graceful failure, as this API will eventually become more strict (and begin to throw).

    Exceptions
    Type Condition
    InvalidOperationException

    If the underlying collection is full (as it cannot be resized within a parallel writer).

    TryAdd(T)

    Adds a new value. If the item is already present, this method returns false without replacing said item.

    Declaration
    public bool TryAdd(T item)
    Parameters
    Type Name Description
    T item

    The value to add.

    Returns
    Type Description
    bool

    True if the value is not already present.

    Exceptions
    Type Condition
    InvalidOperationException

    If the underlying collection is full (as it cannot be resized within a parallel writer).

    TryAdd(T, int)

    Adds a new value. If the item is already present, this method returns false without replacing said item.

    Declaration
    public bool TryAdd(T item, int threadIndexOverride)
    Parameters
    Type Name Description
    T 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 value is not already present.

    Exceptions
    Type Condition
    InvalidOperationException

    If the underlying collection is full (as it cannot be resized within a parallel writer).

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)