MutableFloatSet


public final class MutableFloatSet extends FloatSet


MutableFloatSet 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

MutableFloatSet(int initialCapacity)

Creates a new MutableFloatSet

Public methods

final boolean
add(float element)

Adds the specified element to the set.

final boolean
addAll(@NonNull float[] elements)

Adds all the elements into this set.

final boolean
addAll(@NonNull FloatSet elements)

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

final void

Removes all elements from this set.

final void
minusAssign(float element)

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

final void
minusAssign(@NonNull float[] elements)

Removes the specified elements from the set, if present.

final void

Removes the specified elements from the set, if present.

final void
plusAssign(float element)

Adds the specified element to the set.

final void
plusAssign(@NonNull float[] elements)

Adds all the elements into this set.

final void

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

final boolean
remove(float element)

Removes the specified element from the set.

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

Inherited methods

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

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

final boolean
contains(float 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 Float, @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 float

Returns the first element in the collection.

final float
first(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

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

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

MutableFloatSet

Added in 1.4.0
public MutableFloatSet(int initialCapacity)

Creates a new MutableFloatSet

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

Adds the specified element to the set.

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

Adds all the elements into this set.

Parameters
@NonNull float[] 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 FloatSet elements)

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

Parameters
@NonNull FloatSet elements

A FloatSet 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(float element)

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

Parameters
float element

The element to remove from the set.

minusAssign

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

Removes the specified elements from the set, if present.

Parameters
@NonNull float[] elements

An array of elements to be removed from the set.

minusAssign

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

Removes the specified elements from the set, if present.

Parameters
@NonNull FloatSet elements

An FloatSet of elements to be removed from the set.

plusAssign

Added in 1.4.0
public final void plusAssign(float element)

Adds the specified element to the set.

Parameters
float element

The element to add to the set.

plusAssign

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

Adds all the elements into this set.

Parameters
@NonNull float[] elements

An array of elements to add to the set.

plusAssign

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

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

Parameters
@NonNull FloatSet elements

A FloatSet of elements to add to this set.

remove

Added in 1.4.0
public final boolean remove(float element)

Removes the specified element from the set.

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

Removes the specified elements from the set, if present.

Parameters
@NonNull float[] 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 FloatSet elements)

Removes the specified elements from the set, if present.

Parameters
@NonNull FloatSet elements

An FloatSet 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 MutableFloatSet'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.