LongList


Known direct subclasses
MutableLongList

MutableLongList is a MutableList-like collection for Long values.


LongList is a List-like collection for Long values. It allows retrieving the elements without boxing. LongList is always backed by a MutableLongList, its MutableList-like subclass. The purpose of this class is to avoid the performance overhead of auto-boxing due to generics since Collection classes all operate on objects.

This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the list (insertion or removal for instance), the calling code must provide the appropriate synchronization. It is also not safe to mutate during reentrancy -- in the middle of a forEach, for example. However, concurrent reads are safe.

Summary

Protected constructors

LongList(initialCapacity: Int)
Cmn

Public functions

inline Boolean
any()

Returns true if there's at least one element in the collection.

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

Returns true if any of the elements give a true return value for predicate.

Cmn
Int
binarySearch(element: Int, fromIndex: Int, toIndex: Int)

Searches this list the specified element in the range defined by fromIndex and toIndex.

Cmn
operator Boolean
contains(element: Long)

Returns true if the LongList contains element or false otherwise.

Cmn
Boolean
containsAll(elements: LongList)

Returns true if the LongList contains all elements in elements or false if one or more are missing.

Cmn
inline Int

Returns the number of elements in this list.

Cmn
inline Int
count(predicate: (element: Long) -> Boolean)

Counts the number of elements matching predicate.

Cmn
Long
elementAt(index: @IntRange(from = 0) Int)

Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.

Cmn
inline Long
elementAtOrElse(
    index: @IntRange(from = 0) Int,
    defaultValue: (index: Int) -> Long
)

Returns the element at the given index or defaultValue if index is out of bounds of the collection.

Cmn
open operator Boolean
equals(other: Any?)

Returns true if other is a LongList and the contents of this and other are the same.

Cmn
Long

Returns the first element in the LongList or throws a NoSuchElementException if it isEmpty.

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

Returns the first element in the LongList for which predicate returns true or throws NoSuchElementException if nothing matches.

Cmn
inline R
<R : Any?> fold(initial: R, operation: (acc, element: Long) -> R)

Accumulates values, starting with initial, and applying operation to each element in the LongList in order.

Cmn
inline R
<R : Any?> foldIndexed(initial: R, operation: (index: Int, acc, element: Long) -> R)

Accumulates values, starting with initial, and applying operation to each element in the LongList in order.

Cmn
inline R
<R : Any?> foldRight(initial: R, operation: (element: Long, acc) -> R)

Accumulates values, starting with initial, and applying operation to each element in the LongList in reverse order.

Cmn
inline R
<R : Any?> foldRightIndexed(
    initial: R,
    operation: (index: Int, element: Long, acc) -> R
)

Accumulates values, starting with initial, and applying operation to each element in the LongList in reverse order.

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

Calls block for each element in the LongList, in order.

Cmn
inline Unit
forEachIndexed(block: (index: Int, element: Long) -> Unit)

Calls block for each element in the LongList along with its index, in order.

Cmn
inline Unit
forEachReversed(block: (element: Long) -> Unit)

Calls block for each element in the LongList in reverse order.

Cmn
inline Unit
forEachReversedIndexed(block: (index: Int, element: Long) -> Unit)

Calls block for each element in the LongList along with its index, in reverse order.

Cmn
operator Long
get(index: @IntRange(from = 0) Int)

Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.

Cmn
open Int

Returns a hash code based on the contents of the LongList.

Cmn
Int
indexOf(element: Long)

Returns the index of element in the LongList or -1 if element is not there.

Cmn
inline Int
indexOfFirst(predicate: (element: Long) -> Boolean)

Returns the index if the first element in the LongList for which predicate returns true.

Cmn
inline Int
indexOfLast(predicate: (element: Long) -> Boolean)

Returns the index if the last element in the LongList for which predicate returns true.

Cmn
inline Boolean

Returns true if the LongList has no elements in it or false otherwise.

Cmn
inline Boolean

Returns true if there are elements in the LongList or false if it is 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
Long

Returns the last element in the LongList or throws a NoSuchElementException if it isEmpty.

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

Returns the last element in the LongList for which predicate returns true or throws NoSuchElementException if nothing matches.

Cmn
Int
lastIndexOf(element: Long)

Returns the index of the last element in the LongList that is the same as element or -1 if no elements match.

Cmn
inline Boolean

Returns true if the collection has no elements in it.

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

Returns true if any of the elements give a true return value for predicate while iterating in the reverse order.

Cmn
open String

Returns a String representation of the list, surrounded by "[]" and each element separated by ", ".

Cmn

Public properties

IntRange

Returns an IntRange of the valid indices for this LongList.

Cmn
Int

Returns the last valid index in the LongList.

Cmn
Int

The number of elements in the LongList.

Cmn

Protected constructors

LongList

protected LongList(initialCapacity: Int)

Public functions

any

inline fun any(): Boolean

Returns true if there's at least one element in the collection.

any

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

Returns true if any of the elements give a true return value for predicate.

binarySearch

fun binarySearch(element: Int, fromIndex: Int = 0, toIndex: Int = size): Int

Searches this list the specified element in the range defined by fromIndex and toIndex. The list is expected to be sorted into ascending order according to the natural ordering of its elements, otherwise the result is undefined.

fromIndex must be >= 0 and <toIndex, and toIndex must be <= size, otherwise an an IndexOutOfBoundsException will be thrown.

Returns
Int

the index of the element if it is contained in the list within the specified range. otherwise, the inverted insertion point (-insertionPoint - 1). The insertion point is defined as the index at which the element should be inserted, so that the list remains sorted.

contains

operator fun contains(element: Long): Boolean

Returns true if the LongList contains element or false otherwise.

containsAll

fun containsAll(elements: LongList): Boolean

Returns true if the LongList contains all elements in elements or false if one or more are missing.

count

inline fun count(): Int

Returns the number of elements in this list.

count

inline fun count(predicate: (element: Long) -> Boolean): Int

Counts the number of elements matching predicate.

Returns
Int

The number of elements in this list for which predicate returns true.

elementAt

fun elementAt(index: @IntRange(from = 0) Int): Long

Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.

elementAtOrElse

inline fun elementAtOrElse(
    index: @IntRange(from = 0) Int,
    defaultValue: (index: Int) -> Long
): Long

Returns the element at the given index or defaultValue if index is out of bounds of the collection.

Parameters
index: Int

The index of the element whose value should be returned

defaultValue: (index: Int) -> Long

A lambda to call with index as a parameter to return a value at an index not in the list.

equals

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

Returns true if other is a LongList and the contents of this and other are the same.

first

fun first(): Long

Returns the first element in the LongList or throws a NoSuchElementException if it isEmpty.

first

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

Returns the first element in the LongList for which predicate returns true or throws NoSuchElementException if nothing matches.

See also
indexOfFirst

fold

inline fun <R : Any?> fold(initial: R, operation: (acc, element: Long) -> R): R

Accumulates values, starting with initial, and applying operation to each element in the LongList in order.

Parameters
initial: R

The value of acc for the first call to operation or return value if there are no elements in this list.

operation: (acc, element: Long) -> R

function that takes current accumulator value and an element, and calculates the next accumulator value.

foldIndexed

inline fun <R : Any?> foldIndexed(initial: R, operation: (index: Int, acc, element: Long) -> R): R

Accumulates values, starting with initial, and applying operation to each element in the LongList in order.

foldRight

inline fun <R : Any?> foldRight(initial: R, operation: (element: Long, acc) -> R): R

Accumulates values, starting with initial, and applying operation to each element in the LongList in reverse order.

Parameters
initial: R

The value of acc for the first call to operation or return value if there are no elements in this list.

operation: (element: Long, acc) -> R

function that takes an element and the current accumulator value, and calculates the next accumulator value.

foldRightIndexed

inline fun <R : Any?> foldRightIndexed(
    initial: R,
    operation: (index: Int, element: Long, acc) -> R
): R

Accumulates values, starting with initial, and applying operation to each element in the LongList in reverse order.

forEach

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

Calls block for each element in the LongList, in order.

Parameters
block: (element: Long) -> Unit

will be executed for every element in the list, accepting an element from the list

forEachIndexed

inline fun forEachIndexed(block: (index: Int, element: Long) -> Unit): Unit

Calls block for each element in the LongList along with its index, in order.

Parameters
block: (index: Int, element: Long) -> Unit

will be executed for every element in the list, accepting the index and the element at that index.

forEachReversed

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

Calls block for each element in the LongList in reverse order.

Parameters
block: (element: Long) -> Unit

will be executed for every element in the list, accepting an element from the list

forEachReversedIndexed

inline fun forEachReversedIndexed(block: (index: Int, element: Long) -> Unit): Unit

Calls block for each element in the LongList along with its index, in reverse order.

Parameters
block: (index: Int, element: Long) -> Unit

will be executed for every element in the list, accepting the index and the element at that index.

get

operator fun get(index: @IntRange(from = 0) Int): Long

Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.

hashCode

open fun hashCode(): Int

Returns a hash code based on the contents of the LongList.

indexOf

fun indexOf(element: Long): Int

Returns the index of element in the LongList or -1 if element is not there.

indexOfFirst

inline fun indexOfFirst(predicate: (element: Long) -> Boolean): Int

Returns the index if the first element in the LongList for which predicate returns true.

indexOfLast

inline fun indexOfLast(predicate: (element: Long) -> Boolean): Int

Returns the index if the last element in the LongList for which predicate returns true.

isEmpty

inline fun isEmpty(): Boolean

Returns true if the LongList has no elements in it or false otherwise.

isNotEmpty

inline fun isNotEmpty(): Boolean

Returns true if there are elements in the LongList or false if it is 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.

last

fun last(): Long

Returns the last element in the LongList or throws a NoSuchElementException if it isEmpty.

last

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

Returns the last element in the LongList for which predicate returns true or throws NoSuchElementException if nothing matches.

See also
indexOfLast

lastIndexOf

fun lastIndexOf(element: Long): Int

Returns the index of the last element in the LongList that is the same as element or -1 if no elements match.

none

inline fun none(): Boolean

Returns true if the collection has no elements in it.

reversedAny

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

Returns true if any of the elements give a true return value for predicate while iterating in the reverse order.

toString

open fun toString(): String

Returns a String representation of the list, surrounded by "[]" and each element separated by ", ".

Public properties

indices

val indicesIntRange

Returns an IntRange of the valid indices for this LongList.

lastIndex

val lastIndexInt

Returns the last valid index in the LongList. This can be -1 when the list is empty.

size

val sizeInt

The number of elements in the LongList.