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

Public functions

Boolean
add(element: E)

Adds the specified element to the set.

Cmn
Boolean
addAll(elements: Array<E>)

Adds all the elements into this set.

Cmn
Boolean
addAll(elements: Iterable<E>)

Adds all the elements into this set.

Cmn
Boolean
addAll(elements: ObjectList<E>)

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

Cmn
Boolean
addAll(elements: OrderedScatterSet<E>)

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

Cmn
Boolean
addAll(elements: ScatterSet<E>)

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

Cmn
Boolean
addAll(elements: Sequence<E>)

Adds all the elements into this set.

Cmn
MutableSet<E>

Wraps this ScatterSet with a MutableSet interface.

Cmn
Unit

Removes all elements from this set.

Cmn
operator Unit
minusAssign(element: E)

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

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

Removes the specified elements from the set, if present.

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

Removes the specified elements from the set, if present.

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

Removes the specified elements from the set, if present.

Cmn
operator Unit

Removes the specified elements from the set, if present.

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

Removes the specified elements from the set, if present.

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

Removes the specified elements from the set, if present.

Cmn
operator Unit
plusAssign(element: E)

Adds the specified element to the set.

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

Adds all the elements into this set.

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

Adds all the elements into this set.

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

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

Cmn
operator Unit

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

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

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

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

Adds all the elements into this set.

Cmn
Boolean
remove(element: E)

Removes the specified element from the set.

Cmn
Boolean
removeAll(elements: Array<E>)

Removes the specified elements from the set, if present.

Cmn
Boolean
removeAll(elements: Iterable<E>)

Removes the specified elements from the set, if present.

Cmn
Boolean
removeAll(elements: ObjectList<E>)

Removes the specified elements from the set, if present.

Cmn
Boolean

Removes the specified elements from the set, if present.

Cmn
Boolean
removeAll(elements: ScatterSet<E>)

Removes the specified elements from the set, if present.

Cmn
Boolean
removeAll(elements: Sequence<E>)

Removes the specified elements from the set, if present.

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

Removes any values for which the specified predicate returns true.

Cmn
Boolean
retainAll(elements: Collection<E>)

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

Cmn
Boolean

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

Cmn
Boolean
retainAll(elements: ScatterSet<E>)

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

Cmn
Boolean
retainAll(predicate: (E) -> Boolean)

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

Cmn
@IntRange(from = 0) Int

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

Cmn

Inherited functions

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

Returns true if all elements match the given predicate.

Cmn
Boolean
any()

Returns true if this set has at least one element.

Cmn
inline Boolean
any(predicate: (element) -> Boolean)

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

Cmn
Set<E>

Wraps this ScatterSet with a Set interface.

Cmn
operator Boolean
contains(element: E)

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

Cmn
@IntRange(from = 0) Int

Returns the number of elements in this set.

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

Returns the number of elements matching the given predicate.

Cmn
open operator Boolean
equals(other: Any?)

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

Cmn
E

Returns the first element in the collection.

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

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

Cmn
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
inline Unit
forEach(block: (element) -> Unit)

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

Cmn
open Int

Returns the hash code value for this set.

Cmn
Boolean

Indicates whether this set is empty.

Cmn
Boolean

Returns true if this set is not empty.

Cmn
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
Boolean

Returns true if this set has no elements.

Cmn
open String

Returns a string representation of this set.

Cmn

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
Int

Returns the number of elements in this set.

Cmn

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: 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: 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: 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: 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

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.