ScatterSet

sealed class ScatterSet<E>

ScatterSet is a container with a Set-like interface based on a flat hash table implementation. The underlying implementation is designed to avoid all allocations on insertion, removal, retrieval, and iteration. Allocations may still happen on insertion when the underlying storage needs to grow to accommodate newly added elements to the set.

This implementation makes no guarantee as to the order of the elements, nor does it make guarantees that the order remains constant over time.

Though ScatterSet offers a read-only interface, it is always backed by a MutableScatterSet. Read operations alone are thread-safe. However, any mutations done through the backing MutableScatterSet while reading on another thread are not safe and the developer must protect the set from such changes during read operations.

Note: when a Set is absolutely necessary, you can use the method asSet to create a thin wrapper around a ScatterSet. Please refer to asSet for more details and caveats.

See also

Inheritors

Properties

Link copied to clipboard
@get:IntRange(from = 0)
val capacity: Int

Returns the number of elements that can be stored in this set without requiring internal storage reallocation.

Link copied to clipboard
@get:IntRange(from = 0)
val size: Int

Returns the number of elements in this set.

Functions

Link copied to clipboard
inline fun all(predicate: (element: E) -> Boolean): Boolean

Returns true if all elements match the given predicate. If there are no elements in the set, true is returned.

Link copied to clipboard
fun any(): Boolean

Returns true if this set has at least one element.

inline fun any(predicate: (element: E) -> Boolean): Boolean

Returns true if at least one element matches the given predicate.

Link copied to clipboard
fun asSet(): Set<E>

Wraps this ScatterSet with a Set interface. The Set is backed by the ScatterSet, so changes to the ScatterSet are reflected in the Set. If the ScatterSet is modified while an iteration over the Set is in progress, the results of the iteration are undefined.

Link copied to clipboard
operator fun contains(element: E): Boolean

Returns true if the specified element is present in this hash set, false otherwise.

Link copied to clipboard
@IntRange(from = 0)
fun count(): Int

Returns the number of elements in this set.

@IntRange(from = 0)
inline fun count(predicate: (element: E) -> Boolean): Int

Returns the number of elements matching the given predicate.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Compares the specified object other with this hash set for equality. The two objects are considered equal if other:

Link copied to clipboard
inline fun first(): E

Returns the first element in the collection.

inline fun first(predicate: (element: E) -> Boolean): E

Returns the first element in the collection for which predicate returns true

Link copied to clipboard
inline fun firstOrNull(predicate: (element: E) -> Boolean): E?

Returns the first element in the collection for which predicate returns true or null if there are no elements that match predicate.

Link copied to clipboard
inline fun forEach(block: (element: E) -> Unit)

Iterates over every element stored in this set by invoking the specified block lambda.

Link copied to clipboard
open override fun hashCode(): Int

Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hash code of a null element is defined to be zero

Link copied to clipboard

Indicates whether this set is empty.

Link copied to clipboard

Returns true if this set is not empty.

Link copied to clipboard
fun joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: (E) -> CharSequence? = null): String

Creates a String from the elements separated by separator and using prefix before and postfix after, if supplied.

Link copied to clipboard
fun none(): Boolean

Returns true if this set has no elements.

Link copied to clipboard
open override fun toString(): String

Returns a string representation of this set. The set is denoted in the string by the []. Each element is separated by , .