Struct UnsafeHashSet<T>
Set of values, without any thread safety check features.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct UnsafeHashSet<T> : IEnumerable<T>, IEnumerable, IDisposable where T : struct, IEquatable<T>
Type Parameters
Name | Description |
---|---|
T | The type of the values in the container. |
Constructors
UnsafeHashSet(Int32, Allocator)
Constructs a new container with the specified initial capacity and type of memory allocation.
Declaration
public UnsafeHashSet(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; }
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.
IsEmpty
Reports whether container is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
Boolean | True if this container empty. |
Methods
Add(T)
Add the specified element into the container. If the specified element already exists in the container it returns false.
Declaration
public bool Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element to add to the container. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the specified element is added into the container, otherwise returns false. |
AsParallelWriter()
Returns parallel writer instance.
Declaration
public UnsafeHashSet<T>.ParallelWriter AsParallelWriter()
Returns
Type | Description |
---|---|
UnsafeHashSet.ParallelWriter<> | Parallel writer instance. |
Clear()
Clears the container.
Declaration
public void Clear()
Remarks
Containers capacity remains unchanged.
Contains(T)
Determines whether an element is in the container.
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element to locate in the container. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the specified element is inside the container, otherwise returns false indicating the specified element wasn't in the container. |
Count()
The current number of items in the container.
Declaration
public int Count()
Returns
Type | Description |
---|---|
Int32 | The item count. |
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 | 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. |
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 UnsafeHashSet<T>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
UnsafeHashSet.Enumerator<> | An IEnumerator interface for the container. |
Remove(T)
Removes the specified element from the container.
Declaration
public bool Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element to remove from the container. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the specified element was removed from the container, otherwise returns false indicating the specified element wasn't in the container. |
ToNativeArray(Allocator)
Returns array populated with elements from the container.
Declaration
public NativeArray<T> ToNativeArray(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Returns
Type | Description |
---|---|
NativeArray<T> | Array of elements of the container. |