LongSet


Known direct subclasses
MutableLongSet

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


LongSet 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 LongSet offers a read-only interface, it is always backed by a MutableLongSet. Read operations alone are thread-safe. However, any mutations done through the backing MutableLongSet while reading on another thread are not safe and the developer must protect the set from such changes during read operations.

See also
MutableLongSet

Summary

Protected constructors

Cmn

Public functions

inline Boolean
all(predicate: (element: Long) -> 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: Long) -> Boolean)

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

Cmn
operator Boolean
contains(element: Long)

Returns true if the specified element is present in this 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: Long) -> Boolean)

Returns the number of elements matching the given predicate.

Cmn
open operator Boolean
equals(other: Any?)

Compares the specified object other with this set for equality.

Cmn
inline Long

Returns the first element in the collection.

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

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

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

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

Cmn
inline String
joinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence,
    crossinline transform: (Long) -> 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

Public properties

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

Protected constructors

LongSet

protected LongSet()

Public functions

all

inline fun all(predicate: (element: Long) -> Boolean): Boolean

Returns true if all elements match the given predicate.

Parameters
predicate: (element: Long) -> Boolean

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

any

fun any(): Boolean

Returns true if this set has at least one element.

any

inline fun any(predicate: (element: Long) -> Boolean): Boolean

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

Parameters
predicate: (element: Long) -> Boolean

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

contains

operator fun contains(element: Long): Boolean

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

Parameters
element: Long

The element to look for in this set

count

fun count(): @IntRange(from = 0) Int

Returns the number of elements in this set.

count

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

Returns the number of elements matching the given predicate.

Parameters
predicate: (element: Long) -> Boolean

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

equals

open operator fun equals(other: Any?): Boolean

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

  • Is a LongSet

  • Has the same size as this set

  • Contains elements equal to this set's elements

first

inline fun first(): Long

Returns the first element in the collection.

Throws
kotlin.NoSuchElementException

if the collection is empty

first

inline fun first(predicate: (element: Long) -> Boolean): Long

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
predicate: (element: Long) -> Boolean

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

Returns
Long

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

inline fun forEach(block: (element: Long) -> Unit): Unit

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

Parameters
block: (element: Long) -> Unit

called with each element in the set

hashCode

open fun hashCode(): Int

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

fun isEmpty(): Boolean

Indicates whether this set is empty.

isNotEmpty

fun isNotEmpty(): Boolean

Returns true if this set is not empty.

joinToString

fun joinToString(
    separator: CharSequence = ", ",
    prefix: CharSequence = "",
    postfix: CharSequence = "",
    limit: Int = -1,
    truncated: CharSequence = "..."
): String

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

inline fun joinToString(
    separator: CharSequence = ", ",
    prefix: CharSequence = "",
    postfix: CharSequence = "",
    limit: Int = -1,
    truncated: CharSequence = "...",
    crossinline transform: (Long) -> CharSequence
): String

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

fun none(): Boolean

Returns true if this set has no elements.

toString

open fun toString(): String

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

Public properties

capacity

val capacityInt

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

size

val sizeInt

Returns the number of elements in this set.