MutableScatterSet

class MutableScatterSet<E>(initialCapacity: Int = DefaultScatterCapacity) : ScatterSet<E>

MutableScatterSet is a container with a MutableSet-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 stored, nor does it make guarantees that the order remains constant over time.

This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the set (insertion or removal for instance), the calling code must provide the appropriate synchronization. Concurrent reads are however safe.

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

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

Parameters

initialCapacity

The initial desired capacity for this container. the container will honor this value by guaranteeing its internal structures can hold that many elements without requiring any allocations. The initial capacity can be set to 0.

See also

Constructors

Link copied to clipboard
constructor(initialCapacity: Int = DefaultScatterCapacity)

Creates a new MutableScatterSet

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
fun add(element: E): Boolean

Adds the specified element to the set.

Link copied to clipboard
fun addAll(elements: ScatterSet<E>): Boolean
fun addAll(elements: ObjectList<E>): Boolean

Adds all the elements in the elements set into this set.

fun addAll(elements: Array<out E>): Boolean
fun addAll(elements: Iterable<E>): Boolean
fun addAll(elements: Sequence<E>): Boolean

Adds all the elements into this set.

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

Wraps this ScatterSet with a MutableSet interface. The MutableSet is backed by the ScatterSet, so changes to the ScatterSet are reflected in the MutableSet and vice-versa. If the ScatterSet is modified while an iteration over the MutableSet is in progress (and vice- versa), the results of the iteration are undefined.

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
fun clear()

Removes all elements from this set.

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
operator fun minusAssign(element: E)

Removes the specified element from the set if it is present.

operator fun minusAssign(elements: ScatterSet<E>)
operator fun minusAssign(elements: Array<out E>)
operator fun minusAssign(elements: Iterable<E>)
operator fun minusAssign(elements: ObjectList<E>)
operator fun minusAssign(elements: Sequence<E>)

Removes the specified elements from the set, if present.

Link copied to clipboard
fun none(): Boolean

Returns true if this set has no elements.

Link copied to clipboard
operator fun plusAssign(element: E)

Adds the specified element to the set.

operator fun plusAssign(elements: ScatterSet<E>)
operator fun plusAssign(elements: ObjectList<E>)

Adds all the elements in the elements set into this set.

operator fun plusAssign(elements: Array<out E>)
operator fun plusAssign(elements: Iterable<E>)
operator fun plusAssign(elements: Sequence<E>)

Adds all the elements into this set.

Link copied to clipboard
fun remove(element: E): Boolean

Removes the specified element from the set.

Link copied to clipboard
fun removeAll(elements: ScatterSet<E>): Boolean
fun removeAll(elements: Array<out E>): Boolean
fun removeAll(elements: Iterable<E>): Boolean
fun removeAll(elements: Sequence<E>): Boolean

Removes the specified elements from the set, if present.

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

Removes any values for which the specified predicate returns true.

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 , .

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

Trims this MutableScatterSet's storage so it is sized appropriately to hold the current elements.