FloatSet


public sealed class FloatSet

Known direct subclasses
MutableFloatSet

MutableFloatSet is a container with a MutableSet-like interface based on a flat hash table implementation.


FloatSet is a container with a Set-like interface designed to avoid allocations, including boxing.

This implementation makes no guarantee as to the order of the elements, nor does it make guarantees that the order remains constant over time.

Though FloatSet offers a read-only interface, it is always backed by a MutableFloatSet. Read operations alone are thread-safe. However, any mutations done through the backing MutableFloatSet while reading on another thread are not safe and the developer must protect the set from such changes during read operations.

See also
MutableFloatSet

Summary

Protected constructors

Public methods

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.

Protected constructors

FloatSet

protected FloatSet()

Public methods

all

Added in 1.4.0
public final boolean all(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

Returns true if all elements match the given predicate.

Parameters
@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate

called for elements in the set to determine if it returns return true for all elements.

any

Added in 1.4.0
public final boolean any()

Returns true if this set has at least one element.

any

Added in 1.4.0
public final boolean any(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

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

Parameters
@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate

called for elements in the set to determine if it returns true for any elements.

contains

Added in 1.4.0
public final boolean contains(float element)

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

Parameters
float element

The element to look for in this set

count

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

Returns the number of elements in this set.

count

Added in 1.4.0
public final @IntRange(from = 0) int count(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

Returns the number of elements matching the given predicate.

Parameters
@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate

Called for all elements in the set to count the number for which it returns true.

equals

public boolean equals(Object other)

Compares the specified object other with this set for equality. The two objects are considered equal if other:

  • Is a FloatSet

  • Has the same size as this set

  • Contains elements equal to this set's elements

first

Added in 1.4.0
public final float first()

Returns the first element in the collection.

Throws
kotlin.NoSuchElementException

if the collection is empty

first

Added in 1.4.0
public final float first(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

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

Note There is no mechanism for both determining if there is an element that matches predicate and returning it if it exists. Developers should use forEach to achieve this behavior.

Parameters
@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate

Called on elements of the set, returning true for an element that matches or false if it doesn't

Returns
float

An element in the set for which predicate returns true.

Throws
kotlin.NoSuchElementException

if predicate returns false for all elements or the collection is empty.

forEach

Added in 1.4.0
public final void forEach(@NonNull Function1<@NonNull FloatUnit> block)

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

Parameters
@NonNull Function1<@NonNull FloatUnit> block

called with each element in the set

getCapacity

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

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

getSize

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

Returns the number of elements in this set.

hashCode

public int hashCode()

Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set.

isEmpty

Added in 1.4.0
public final boolean isEmpty()

Indicates whether this set is empty.

isNotEmpty

Added in 1.4.0
public final boolean isNotEmpty()

Returns true if this set is not empty.

joinToString

Added in 1.4.0
public 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.

When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.

joinToString

public 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. transform dictates how each element will be represented.

When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.

none

Added in 1.4.0
public final boolean none()

Returns true if this set has no elements.

toString

public @NonNull String toString()

Returns a string representation of this set. The set is denoted in the string by the {}. Each element is separated by , .