SafeSet

class SafeSet<T>(c: Collection<T> = emptySet())

A thread-safe set implementation.

This class provides a thread-safe set data structure that allows adding, removing, checking containment, retrieving the size, and checking the emptiness of the set.

Parameters

c

The initial collection to populate the set. Defaults to an empty set if not provided.

T

The type of elements in the set.

Constructors

Link copied to clipboard
constructor(c: Collection<T> = emptySet())

Functions

Link copied to clipboard
suspend fun add(element: T): Boolean

Adds an element to the set.

Link copied to clipboard
suspend fun clear()

Removes all the elements from this set.

Link copied to clipboard
suspend fun contains(element: T): Boolean

Checks if the set contains the specified element.

Link copied to clipboard
suspend fun isEmpty(): Boolean

Checks if the set is empty.

Link copied to clipboard
suspend fun next(): T?

Retrieves the next element in the set infinitely.

Link copied to clipboard
suspend fun remove(element: T): Boolean

Removes an element from the set.

Link copied to clipboard
suspend fun size(): Int

Retrieves the current size of the set.