MutableScatterSet



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.

See also
Set

Summary

Public constructors

<E : Any?> MutableScatterSet(initialCapacity: Int)

Creates a new MutableScatterSet

Cmn
android
N
JS

Public functions

Boolean
add(element: E)

Adds the specified element to the set.

Cmn
android
N
JS
Boolean
N
JS
Boolean
addAll(elements: Array<E>)

Adds all the elements into this set.

Cmn
android
N
JS
Boolean
addAll(elements: Iterable<E>)

Adds all the elements into this set.

Cmn
android
N
JS
Boolean
addAll(elements: ObjectList<E>)

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

Cmn
android
N
JS
Boolean
addAll(elements: OrderedScatterSet<E>)

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

Cmn
android
N
JS
Boolean
addAll(elements: ScatterSet<E>)

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

Cmn
android
N
JS
Boolean
addAll(elements: Sequence<E>)

Adds all the elements into this set.

Cmn
android
MutableSet<E>

Wraps this ScatterSet with a MutableSet interface.

Cmn
android
N
JS
Unit

Removes all elements from this set.

Cmn
android
N
JS
operator Unit
minusAssign(element: E)

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

Cmn
android
N
JS
operator Unit
N
JS
operator Unit
minusAssign(elements: Array<E>)

Removes the specified elements from the set, if present.

Cmn
android
N
JS
operator Unit
minusAssign(elements: Iterable<E>)

Removes the specified elements from the set, if present.

Cmn
android
N
JS
operator Unit
minusAssign(elements: ObjectList<E>)

Removes the specified elements from the set, if present.

Cmn
android
N
JS
operator Unit

Removes the specified elements from the set, if present.

Cmn
android
N
JS
operator Unit
minusAssign(elements: ScatterSet<E>)

Removes the specified elements from the set, if present.

Cmn
android
N
JS
operator Unit
minusAssign(elements: Sequence<E>)

Removes the specified elements from the set, if present.

Cmn
android
operator Unit
plusAssign(element: E)

Adds the specified element to the set.

Cmn
android
N
JS
operator Unit
N
JS
operator Unit
plusAssign(elements: Array<E>)

Adds all the elements into this set.

Cmn
android
N
JS
operator Unit
plusAssign(elements: Iterable<E>)

Adds all the elements into this set.

Cmn
android
N
JS
operator Unit
plusAssign(elements: ObjectList<E>)

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

Cmn
android
N
JS
operator Unit

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

Cmn
android
N
JS
operator Unit
plusAssign(elements: ScatterSet<E>)

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

Cmn
android
N
JS
operator Unit
plusAssign(elements: Sequence<E>)

Adds all the elements into this set.

Cmn
android
Boolean
remove(element: E)

Removes the specified element from the set.

Cmn
android
N
JS
Boolean
N
JS
Boolean
removeAll(elements: Array<E>)

Removes the specified elements from the set, if present.

Cmn
android
N
JS
Boolean
removeAll(elements: Iterable<E>)

Removes the specified elements from the set, if present.

Cmn
android
N
JS
Boolean
removeAll(elements: ObjectList<E>)

Removes the specified elements from the set, if present.

Cmn
android
N
JS
Boolean

Removes the specified elements from the set, if present.

Cmn
android
N
JS
Boolean
removeAll(elements: ScatterSet<E>)

Removes the specified elements from the set, if present.

Cmn
android
N
JS
Boolean
removeAll(elements: Sequence<E>)

Removes the specified elements from the set, if present.

Cmn
android
inline Unit
removeIf(predicate: (E) -> Boolean)

Removes any values for which the specified predicate returns true.

Cmn
android
N
JS
Boolean
retainAll(elements: Collection<E>)

Removes all the entries in this set that are not contained in elements.

Cmn
android
N
JS
Boolean

Removes all the entries in this set that are not contained in elements.

Cmn
android
N
JS
Boolean
retainAll(elements: ScatterSet<E>)

Removes all the entries in this set that are not contained in elements.

Cmn
android
N
JS
inline Boolean
retainAll(predicate: (E) -> Boolean)

Removes all the elements in this set for which the specified predicate is true.

Cmn
android
N
JS
@IntRange(from = 0) Int

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

Cmn
android
N
JS

Inherited functions

From androidx.collection.ScatterSet
inline Boolean
all(predicate: (element) -> Boolean)

Returns true if all elements match the given predicate.

Cmn
android
N
JS
Boolean
any()

Returns true if this set has at least one element.

Cmn
android
N
JS
inline Boolean
any(predicate: (element) -> Boolean)

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

Cmn
android
N
JS
Set<E>

Wraps this ScatterSet with a Set interface.

Cmn
android
N
JS
operator Boolean
contains(element: E)

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

Cmn
android
N
JS
@IntRange(from = 0) Int

Returns the number of elements in this set.

Cmn
android
N
JS
inline @IntRange(from = 0) Int
count(predicate: (element) -> Boolean)

Returns the number of elements matching the given predicate.

Cmn
android
N
JS
open operator Boolean
equals(other: Any?)

Compares the specified object other with this hash set for equality.

Cmn
android
N
JS
E

Returns the first element in the collection.

Cmn
android
N
JS
inline E
first(predicate: (element) -> Boolean)

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

Cmn
android
N
JS
inline E?
firstOrNull(predicate: (element) -> Boolean)

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

Cmn
android
N
JS
inline Unit
forEach(block: (element) -> Unit)

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

Cmn
android
N
JS
open Int

Returns the hash code value for this set.

Cmn
android
N
JS
Boolean

Indicates whether this set is empty.

Cmn
android
N
JS
Boolean

Returns true if this set is not empty.

Cmn
android
N
JS
String
joinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence,
    transform: ((E) -> CharSequence)?
)

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

Cmn
android
N
JS
Boolean

Returns true if this set has no elements.

Cmn
android
N
JS
open String

Returns a string representation of this set.

Cmn
android
N
JS

Inherited properties

From androidx.collection.ScatterSet
Int

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

Cmn
android
N
JS
Int

Returns the number of elements in this set.

Cmn
android
N
JS

Public constructors

MutableScatterSet

<E : Any?> MutableScatterSet(initialCapacity: Int = DefaultScatterCapacity)

Creates a new MutableScatterSet

Parameters
initialCapacity: Int = DefaultScatterCapacity

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.

Public functions

add

fun add(element: E): Boolean

Adds the specified element to the set.

Parameters
element: E

The element to add to the set.

Returns
Boolean

true if the element has been added or false if the element is already contained within the set.

addAll

fun addAll(elements: <Error class: unknown class><E>): Boolean

addAll

fun addAll(elements: Array<E>): Boolean

Adds all the elements into this set.

Parameters
elements: Array<E>

An array of elements to add to the set.

Returns
Boolean

true if any of the specified elements were added to the collection, false if the collection was not modified.

addAll

fun addAll(elements: Iterable<E>): Boolean

Adds all the elements into this set.

Parameters
elements: Iterable<E>

Iterable elements to add to the set.

Returns
Boolean

true if any of the specified elements were added to the collection, false if the collection was not modified.

addAll

fun addAll(elements: ObjectList<E>): Boolean

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

Parameters
elements: ObjectList<E>

An ObjectList whose elements are to be added to the set

Returns
Boolean

true if any of the specified elements were added to the collection, false if the collection was not modified.

addAll

fun addAll(elements: OrderedScatterSet<E>): Boolean

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

Parameters
elements: OrderedScatterSet<E>

A OrderedScatterSet whose elements are to be added to the set

Returns
Boolean

true if any of the specified elements were added to the collection, false if the collection was not modified.

addAll

fun addAll(elements: ScatterSet<E>): Boolean

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

Parameters
elements: ScatterSet<E>

A ScatterSet whose elements are to be added to the set

Returns
Boolean

true if any of the specified elements were added to the collection, false if the collection was not modified.

addAll

fun addAll(elements: Sequence<E>): Boolean

Adds all the elements into this set.

Parameters
elements: Sequence<E>

The sequence of elements to add to the set.

Returns
Boolean

true if any of the specified elements were added to the collection, false if the collection was not modified.

asMutableSet

fun asMutableSet(): MutableSet<E>

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.

Note: while this method is useful to use this MutableScatterSet with APIs accepting MutableSet interfaces, it is less efficient to do so than to use MutableScatterSet's APIs directly. While the MutableSet implementation returned by this method tries to be as efficient as possible, the semantics of MutableSet may require the allocation of temporary objects for access and iteration.

clear

fun clear(): Unit

Removes all elements from this set.

minusAssign

operator fun minusAssign(element: E): Unit

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

Parameters
element: E

The element to be removed from the set.

minusAssign

operator fun minusAssign(elements: <Error class: unknown class><E>): Unit

minusAssign

operator fun minusAssign(elements: Array<E>): Unit

Removes the specified elements from the set, if present.

Parameters
elements: Array<E>

An array of elements to be removed from the set.

minusAssign

operator fun minusAssign(elements: Iterable<E>): Unit

Removes the specified elements from the set, if present.

Parameters
elements: Iterable<E>

A Iterable of elements to be removed from the set.

minusAssign

operator fun minusAssign(elements: ObjectList<E>): Unit

Removes the specified elements from the set, if present.

Parameters
elements: ObjectList<E>

An ObjectList whose elements should be removed from the set.

minusAssign

operator fun minusAssign(elements: OrderedScatterSet<E>): Unit

Removes the specified elements from the set, if present.

Parameters
elements: OrderedScatterSet<E>

A OrderedScatterSet whose elements should be removed from the set.

minusAssign

operator fun minusAssign(elements: ScatterSet<E>): Unit

Removes the specified elements from the set, if present.

Parameters
elements: ScatterSet<E>

A ScatterSet whose elements should be removed from the set.

minusAssign

operator fun minusAssign(elements: Sequence<E>): Unit

Removes the specified elements from the set, if present.

Parameters
elements: Sequence<E>

A sequence of elements to be removed from the set.

plusAssign

operator fun plusAssign(element: E): Unit

Adds the specified element to the set.

Parameters
element: E

The element to add to the set.

plusAssign

operator fun plusAssign(elements: <Error class: unknown class><E>): Unit

plusAssign

operator fun plusAssign(elements: Array<E>): Unit

Adds all the elements into this set.

Parameters
elements: Array<E>

An array of elements to add to the set.

plusAssign

operator fun plusAssign(elements: Iterable<E>): Unit

Adds all the elements into this set.

Parameters
elements: Iterable<E>

Iterable elements to add to the set.

plusAssign

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

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

Parameters
elements: ObjectList<E>

An ObjectList whose elements are to be added to the set

plusAssign

operator fun plusAssign(elements: OrderedScatterSet<E>): Unit

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

Parameters
elements: OrderedScatterSet<E>

A OrderedScatterSet whose elements are to be added to the set

plusAssign

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

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

Parameters
elements: ScatterSet<E>

A ScatterSet whose elements are to be added to the set

plusAssign

operator fun plusAssign(elements: Sequence<E>): Unit

Adds all the elements into this set.

Parameters
elements: Sequence<E>

The sequence of elements to add to the set.

remove

fun remove(element: E): Boolean

Removes the specified element from the set.

Parameters
element: E

The element to be removed from the set.

Returns
Boolean

true if the element was present in the set, or false if it wasn't present before removal.

removeAll

fun removeAll(elements: <Error class: unknown class><E>): Boolean

removeAll

fun removeAll(elements: Array<E>): Boolean

Removes the specified elements from the set, if present.

Parameters
elements: Array<E>

An array of elements to be removed from the set.

Returns
Boolean

true if the set was changed or false if none of the elements were present.

removeAll

fun removeAll(elements: Iterable<E>): Boolean

Removes the specified elements from the set, if present.

Parameters
elements: Iterable<E>

A Iterable of elements to be removed from the set.

Returns
Boolean

true if the set was changed or false if none of the elements were present.

removeAll

fun removeAll(elements: ObjectList<E>): Boolean

Removes the specified elements from the set, if present.

Parameters
elements: ObjectList<E>

An ObjectList whose elements should be removed from the set.

Returns
Boolean

true if the set was changed or false if none of the elements were present.

removeAll

fun removeAll(elements: OrderedScatterSet<E>): Boolean

Removes the specified elements from the set, if present.

Parameters
elements: OrderedScatterSet<E>

A OrderedScatterSet whose elements should be removed from the set.

Returns
Boolean

true if the set was changed or false if none of the elements were present.

removeAll

fun removeAll(elements: ScatterSet<E>): Boolean

Removes the specified elements from the set, if present.

Parameters
elements: ScatterSet<E>

A ScatterSet whose elements should be removed from the set.

Returns
Boolean

true if the set was changed or false if none of the elements were present.

removeAll

fun removeAll(elements: Sequence<E>): Boolean

Removes the specified elements from the set, if present.

Parameters
elements: Sequence<E>

A sequence of elements to be removed from the set.

Returns
Boolean

true if the set was changed or false if none of the elements were present.

removeIf

inline fun removeIf(predicate: (E) -> Boolean): Unit

Removes any values for which the specified predicate returns true.

retainAll

fun retainAll(elements: Collection<E>): Boolean

Removes all the entries in this set that are not contained in elements.

Parameters
elements: Collection<E>

A collection of elements to preserve in this set.

Returns
Boolean

true if this set was modified, false otherwise.

retainAll

fun retainAll(elements: OrderedScatterSet<E>): Boolean

Removes all the entries in this set that are not contained in elements.

elements A set of elements to preserve in this set.

Returns
Boolean

true if this set was modified, false otherwise.

retainAll

fun retainAll(elements: ScatterSet<E>): Boolean

Removes all the entries in this set that are not contained in elements.

elements A set of elements to preserve in this set.

Returns
Boolean

true if this set was modified, false otherwise.

retainAll

inline fun retainAll(predicate: (E) -> Boolean): Boolean

Removes all the elements in this set for which the specified predicate is true. For each element in the set, the predicate is invoked with that element as the sole parameter.

Parameters
predicate: (E) -> Boolean

Predicate invoked for each element in the set. When the predicate returns true, the element is kept in the set, otherwise it is removed.

Returns
Boolean

true if this set was modified, false otherwise.

trim

fun trim(): @IntRange(from = 0) Int

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

Returns the number of empty elements removed from this set's storage. Returns 0 if no trimming is necessary or possible.