MutableLongSet


public final class MutableLongSet extends LongSet


MutableLongSet 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

MutableLongSet(int initialCapacity)

Creates a new MutableLongSet

Public methods

final boolean
add(long element)

Adds the specified element to the set.

final boolean
addAll(@NonNull long[] elements)

Adds all the elements into this set.

final boolean
addAll(@NonNull LongSet elements)

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

final void

Removes all elements from this set.

final void
minusAssign(long element)

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

final void
minusAssign(@NonNull long[] elements)

Removes the specified elements from the set, if present.

final void

Removes the specified elements from the set, if present.

final void
plusAssign(long element)

Adds the specified element to the set.

final void
plusAssign(@NonNull long[] elements)

Adds all the elements into this set.

final void

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

final boolean
remove(long element)

Removes the specified element from the set.

final boolean
removeAll(@NonNull long[] 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 MutableLongSet's storage so it is sized appropriately to hold the current elements.

Inherited methods

From androidx.collection.LongSet
final boolean
all(@NonNull Function1<@NonNull Long, @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 Long, @NonNull Boolean> predicate)

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

final boolean
contains(long 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 Long, @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 long

Returns the first element in the collection.

final long
first(@NonNull Function1<@NonNull Long, @NonNull Boolean> predicate)

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

final void
forEach(@NonNull Function1<@NonNull LongUnit> 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 Long, @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

MutableLongSet

Added in 1.4.0
public MutableLongSet(int initialCapacity)

Creates a new MutableLongSet

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(long element)

Adds the specified element to the set.

Parameters
long 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 long[] elements)

Adds all the elements into this set.

Parameters
@NonNull long[] 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 LongSet elements)

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

Parameters
@NonNull LongSet elements

A LongSet 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(long element)

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

Parameters
long element

The element to remove from the set.

minusAssign

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

Removes the specified elements from the set, if present.

Parameters
@NonNull long[] elements

An array of elements to be removed from the set.

minusAssign

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

Removes the specified elements from the set, if present.

Parameters
@NonNull LongSet elements

An LongSet of elements to be removed from the set.

plusAssign

Added in 1.4.0
public final void plusAssign(long element)

Adds the specified element to the set.

Parameters
long element

The element to add to the set.

plusAssign

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

Adds all the elements into this set.

Parameters
@NonNull long[] elements

An array of elements to add to the set.

plusAssign

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

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

Parameters
@NonNull LongSet elements

A LongSet of elements to add to this set.

remove

Added in 1.4.0
public final boolean remove(long element)

Removes the specified element from the set.

Parameters
long 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 long[] elements)

Removes the specified elements from the set, if present.

Parameters
@NonNull long[] 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 LongSet elements)

Removes the specified elements from the set, if present.

Parameters
@NonNull LongSet elements

An LongSet 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 MutableLongSet'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.