# UnsafeHashSet<T>

> An unordered, expandable set of unique values.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Collections.LowLevel.Unsafe](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe.md)
* **Assembly:** UnityEngine.ManagedKernelModule
* **Implements:** [INativeDisposable](/engine/6000.7/script-reference/unity/collections/inativedisposable.md), [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable), [IEnumerable\<T>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable)

```csharp
public struct UnsafeHashSet<T> : INativeDisposable, IDisposable, IEnumerable<T>, IEnumerable where T : unmanaged, IEquatable<T>
```

## Static Fields

| Value                                                                                                          | Description                                                     |
| -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| [MaxCapacity](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/maxcapacity.md) | The maximum number of elements this type of container can hold. |

## Constructors

| Constructor                                                                                                                                                                   | Description                                                   |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| [UnsafeHashSet\`1(System.Int32,Unity.Collections.AllocatorManager.AllocatorHandle)](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/ctor.md) | Initializes and returns an instance of NativeParallelHashSet. |

## Properties

| Property                                                                                                   | Description                                                    |
| ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| [Capacity](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/capacity.md)   | The number of values that fit in the current allocation.       |
| [Count](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/count.md)         | Returns the current number of values in this set.              |
| [IsCreated](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/iscreated.md) | Whether this set has been allocated (and not yet deallocated). |
| [IsEmpty](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/isempty.md)     | Whether this set is empty.                                     |

## Methods

| Method                                                                                                             | Description                                                                                                                                                                     |
| ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Add](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/add.md)                     | 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. |
| [AsReadOnly](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/asreadonly.md)       | Returns a readonly version of this UnsafeHashMap instance.                                                                                                                      |
| [Clear](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/clear.md)                 | Removes all values.                                                                                                                                                             |
| [Contains](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/contains.md)           | Returns true if a particular value is present.                                                                                                                                  |
| [Dispose](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/dispose.md)             | Releases all resources (memory and safety handles).                                                                                                                             |
| [GetEnumerator](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/getenumerator.md) | Returns an enumerator over the values of this set.                                                                                                                              |
| [Remove](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/remove.md)               | Removes a particular value.                                                                                                                                                     |
| [ToNativeArray](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/tonativearray.md) | Returns an array with a copy of this set's values (in no particular order).                                                                                                     |
| [TrimExcess](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/trimexcess.md)       | Sets the capacity to match what it would be if it had been originally initialized with all its entries.                                                                         |
| [TryAdd](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/tryadd.md)               | Attempts to add a new item. Only succeeds if the item was not present.                                                                                                          |

## Structs

| Struct                                                                                                                         | Description                                                                                  |
| ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------- |
| [UnsafeHashSet\<T>.Enumerator](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/enumerator.md) | An enumerator over the values of a set.                                                      |
| [UnsafeHashSet\<T>.ReadOnly](/engine/6000.7/script-reference/unity/collections/lowlevel/unsafe/unsafehashset1/readonly.md)     | A read-only alias for the value of a UnsafeHashSet. Does not have its own allocated storage. |
