MutableIntSet


public final class MutableIntSet extends IntSet


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

Summary

Public constructors

MutableIntSet(int initialCapacity)

Creates a new MutableIntSet

Public methods

final boolean
add(int element)

Adds the specified element to the set.

final boolean
addAll(@NonNull int[] elements)

Adds all the elements into this set.

final boolean
addAll(@NonNull IntSet elements)

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

final void

Removes all elements from this set.

final void
minusAssign(int element)

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

final void
minusAssign(@NonNull int[] elements)

Removes the specified elements from the set, if present.

final void

Removes the specified elements from the set, if present.

final void
plusAssign(int element)

Adds the specified element to the set.

final void
plusAssign(@NonNull int[] elements)

Adds all the elements into this set.

final void

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

final boolean
remove(int element)

Removes the specified element from the set.

final boolean
removeAll(@NonNull int[] elements)

Removes the specified elements from the set, if present.

final boolean

Removes the specified elements from the set, if present.

final @IntRange(from = 0) int

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

Inherited methods

From androidx.collection.IntSet
final boolean
all(@NonNull Function1<@NonNull Integer, @NonNull Boolean> predicate)

Returns true if all elements match the given predicate.

final boolean
any()

Returns true if this set has at least one element.

final boolean
any(@NonNull Function1<@NonNull Integer, @NonNull Boolean> predicate)

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

final boolean
contains(int element)

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

final @IntRange(from = 0) int

Returns the number of elements in this set.

final @IntRange(from = 0) int
count(@NonNull Function1<@NonNull Integer, @NonNull Boolean> predicate)

Returns the number of elements matching the given predicate.

boolean
equals(Object other)

Compares the specified object other with this set for equality.

final int

Returns the first element in the collection.

final int
first(@NonNull Function1<@NonNull Integer, @NonNull Boolean> predicate)

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

final void
forEach(@NonNull Function1<@NonNull IntegerUnit> block)

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

final @IntRange(from = 0) int

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

final @IntRange(from = 0) int

Returns the number of elements in this set.

int

Returns the hash code value for this set.

final boolean

Indicates whether this set is empty.

final boolean

Returns true if this set is not empty.

final @NonNull String
joinToString(
    @NonNull CharSequence separator,
    @NonNull CharSequence prefix,
    @NonNull CharSequence postfix,
    int limit,
    @NonNull CharSequence truncated
)

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

final @NonNull String
joinToString(
    @NonNull CharSequence separator,
    @NonNull CharSequence prefix,
    @NonNull CharSequence postfix,
    int limit,
    @NonNull CharSequence truncated,
    @NonNull Function1<@NonNull Integer, @NonNull CharSequence> transform
)

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

final boolean

Returns true if this set has no elements.

@NonNull String

Returns a string representation of this set.

Public constructors

MutableIntSet

Added in 1.4.0
public MutableIntSet(int initialCapacity)

Creates a new MutableIntSet

Parameters
int 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.

Public methods

add

Added in 1.4.0
public final boolean add(int element)

Adds the specified element to the set.

Parameters
int element

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

Added in 1.4.0
public final boolean addAll(@NonNull int[] elements)

Adds all the elements into this set.

Parameters
@NonNull int[] elements

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

Added in 1.4.0
public final boolean addAll(@NonNull IntSet elements)

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

Parameters
@NonNull IntSet elements

A IntSet of elements to add to this set.

Returns
boolean

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

clear

Added in 1.4.0
public final void clear()

Removes all elements from this set.

minusAssign

Added in 1.4.0
public final void minusAssign(int element)

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

Parameters
int element

The element to remove from the set.

minusAssign

Added in 1.4.0
public final void minusAssign(@NonNull int[] elements)

Removes the specified elements from the set, if present.

Parameters
@NonNull int[] elements

An array of elements to be removed from the set.

minusAssign

Added in 1.4.0
public final void minusAssign(@NonNull IntSet elements)

Removes the specified elements from the set, if present.

Parameters
@NonNull IntSet elements

An IntSet of elements to be removed from the set.

plusAssign

Added in 1.4.0
public final void plusAssign(int element)

Adds the specified element to the set.

Parameters
int element

The element to add to the set.

plusAssign

Added in 1.4.0
public final void plusAssign(@NonNull int[] elements)

Adds all the elements into this set.

Parameters
@NonNull int[] elements

An array of elements to add to the set.

plusAssign

Added in 1.4.0
public final void plusAssign(@NonNull IntSet elements)

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

Parameters
@NonNull IntSet elements

A IntSet of elements to add to this set.

remove

Added in 1.4.0
public final boolean remove(int element)

Removes the specified element from the set.

Parameters
int element

The element to remove from the set.

Returns
boolean

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

removeAll

Added in 1.4.0
public final boolean removeAll(@NonNull int[] elements)

Removes the specified elements from the set, if present.

Parameters
@NonNull int[] elements

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

Added in 1.4.0
public final boolean removeAll(@NonNull IntSet elements)

Removes the specified elements from the set, if present.

Parameters
@NonNull IntSet elements

An IntSet 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.

trim

Added in 1.4.0
public final @IntRange(from = 0) int trim()

Trims this MutableIntSet'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.