Known direct subclasses
MutableIntSet

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


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

See also
MutableIntSet

Summary

Protected constructors

Cmn

Public functions

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

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

Cmn
operator Boolean
contains(element: Int)

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: Int) -> 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 Int

Returns the first element in the collection.

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

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

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

IntSet

protected IntSet()

Public functions

all

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

Returns true if all elements match the given predicate.

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

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

Parameters
predicate: (element: Int) -> Boolean

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

contains

operator fun contains(element: Int): Boolean

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

Parameters
element: Int

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: Int) -> Boolean): @IntRange(from = 0) Int

Returns the number of elements matching the given predicate.

Parameters
predicate: (element: Int) -> 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 IntSet

  • Has the same size as this set

  • Contains elements equal to this set's elements

first

inline fun first(): Int

Returns the first element in the collection.

Throws
kotlin.NoSuchElementException

if the collection is empty

first

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

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: Int) -> Boolean

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

Returns
Int

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: Int) -> Unit): Unit

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

Parameters
block: (element: Int) -> 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: (Int) -> 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.