> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/api-reference/ks.reactor/ks.reactor.ksatomichashset-1.md).

# Class ksAtomicHashSet\<T>

Namespace: [KS.Reactor](/reactor/api-reference/ks.reactor.md)\
Assembly: KSCommon.dll

Wraps a HashSet to make all read/write operations thread safe.

```csharp
public class ksAtomicHashSet<T>
```

#### Type Parameters

`T`

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← [ksAtomicHashSet\<T>](/reactor/api-reference/ks.reactor/ks.reactor.ksatomichashset-1.md)

#### Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object\)), [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object-system-object\)), [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype), [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone), [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Properties

### Count <a href="#ks_reactor_ksatomichashset_1_count" id="ks_reactor_ksatomichashset_1_count"></a>

Number of values in the hash set.

```csharp
public int Count { get; }
```

#### Property Value

[int](https://learn.microsoft.com/dotnet/api/system.int32)

## Methods

### Add(T) <a href="#ks_reactor_ksatomichashset_1_add__0" id="ks_reactor_ksatomichashset_1_add__0"></a>

Adds a value to the set.

```csharp
public bool Add(T value)
```

#### Parameters

`value` T

Value to add.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

True if the value was not already in the set.

### Clear() <a href="#ks_reactor_ksatomichashset_1_clear" id="ks_reactor_ksatomichashset_1_clear"></a>

Removes all values from the set.

```csharp
public void Clear()
```

### Contains(T) <a href="#ks_reactor_ksatomichashset_1_contains__0" id="ks_reactor_ksatomichashset_1_contains__0"></a>

Checks if a value is in the set.

```csharp
public bool Contains(T value)
```

#### Parameters

`value` T

Value to check for.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

True if the value is in the set.

### ForEach(ForEachCallback) <a href="#ks_reactor_ksatomichashset_1_foreach_ks_reactor_ksatomichashset__0__foreachcallback" id="ks_reactor_ksatomichashset_1_foreach_ks_reactor_ksatomichashset__0__foreachcallback"></a>

Iterate the hash set invoking the callback for each element. If any callback returns false, then iteration stops. A read lock is placed on the hashset while iteration is taking place.

```csharp
public bool ForEach(ksAtomicHashSet<T>.ForEachCallback callback)
```

#### Parameters

`callback` [ksAtomicHashSet](/reactor/api-reference/ks.reactor/ks.reactor.ksatomichashset-1.md)\<T>.[ForEachCallback](/reactor/api-reference/ks.reactor/ks.reactor.ksatomichashset-1/ks.reactor.ksatomichashset-1.foreachcallback.md)

Callback to invoke for each set element.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

True if all callbacks were invoked and returned true.

### Remove(T) <a href="#ks_reactor_ksatomichashset_1_remove__0" id="ks_reactor_ksatomichashset_1_remove__0"></a>

Removes a value from the set.

```csharp
public bool Remove(T value)
```

#### Parameters

`value` T

Value to remove.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

True if the value was in the set.
