MutableLongList

class MutableLongList(initialCapacity: Int = 16) : LongList(source)

MutableLongList is a MutableList-like collection for Long values. It allows storing and retrieving the elements without boxing. Immutable access is available through its base class LongList, which has a List-like interface.

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.

Constructors

Link copied to clipboard
constructor(initialCapacity: Int = 16)

Creates a MutableLongList with a capacity of initialCapacity.

Properties

Link copied to clipboard

Returns the total number of elements that can be held before the MutableLongList must grow.

Link copied to clipboard

Returns an IntRange of the valid indices for this LongList.

Link copied to clipboard

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

Link copied to clipboard
val size: Int

The number of elements in the LongList.

Functions

Link copied to clipboard
fun add(element: Long): Boolean

Adds element to the MutableLongList and returns true.

fun add(index: Int, element: Long)

Adds element to the MutableLongList at the given index, shifting over any elements at index and after, if any.

Link copied to clipboard
inline fun addAll(elements: LongArray): Boolean
inline fun addAll(elements: List<Long>): Boolean
inline fun addAll(elements: LongList): Boolean

Adds all elements to the end of the MutableLongList and returns true if the MutableLongList was changed or false if elements was empty.

fun addAll(index: Int, elements: LongArray): Boolean
fun addAll(index: Int, elements: LongList): Boolean

Adds all elements to the MutableLongList at the given index, shifting over any elements at index and after, if any.

Link copied to clipboard
inline fun all(predicate: (element: Long) -> Boolean): Boolean

Returns true if all elements match the given predicate.

Link copied to clipboard
inline fun any(): Boolean

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

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

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

Link copied to clipboard
inline fun atLeast(n: Int, predicate: (Long) -> Boolean): Boolean

Returns true if at least n elements in the list match the given predicate.

Link copied to clipboard
inline fun atMost(n: Int, predicate: (Long) -> Boolean): Boolean

Returns true if at most n elements in the list match the given predicate.

Link copied to clipboard
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.

Link copied to clipboard
fun chunked(chunkSize: Int): List<LongList>

Splits this list into chunks of specified size.

Link copied to clipboard

Splits this list into a list of InPlaceLongSubList each not exceeding the given chunkSize. The last list may have less elements than the given chunkSize.

Link copied to clipboard
fun clear()

Removes all elements in the MutableLongList. The storage isn't released.

Link copied to clipboard
operator fun contains(element: Long): Boolean

Returns true if the LongList contains element or false otherwise.

Link copied to clipboard
fun containsAll(elements: LongList): Boolean

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

Link copied to clipboard
fun copy(): LongList

Returns a new list that is a copy of the current list.

Link copied to clipboard
inline fun count(): Int

Returns the number of elements in this list.

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

Counts the number of elements matching predicate.

Link copied to clipboard

Returns a new list containing only distinct elements from the current list.

Link copied to clipboard
fun drop(n: Int): LongList

Returns a new list containing all elements except first n elements.

Link copied to clipboard

Returns a new list containing all elements except last n elements.

Link copied to clipboard
inline fun dropLastWhile(predicate: (Long) -> Boolean): LongList

Returns a new LongList containing all elements except the last elements that satisfy the given predicate.

Link copied to clipboard
inline fun dropWhile(predicate: (Long) -> Boolean): LongList

Returns a new list containing all elements except the first elements that satisfy the given predicate.

Link copied to clipboard
fun elementAt(index: Int): Long

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

Link copied to clipboard
inline fun elementAtOrElse(index: Int, defaultValue: (index: Int) -> Long): Long

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

Link copied to clipboard
fun ensureCapacity(capacity: Int)

Ensures that there is enough space to store capacity elements in the MutableLongList.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

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

Link copied to clipboard
inline fun filter(predicate: (Long) -> Boolean): LongList

Returns a list containing only elements matching the given predicate.

Link copied to clipboard
fun first(): Long

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

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.

Link copied to clipboard
inline fun <R> fold(initial: R, operation: (acc: R, element: Long) -> R): R

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

Link copied to clipboard
inline fun <R> foldIndexed(initial: R, operation: (index: Int, acc: R, element: Long) -> R): R

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

Link copied to clipboard
inline fun <R> foldRight(initial: R, operation: (element: Long, acc: R) -> R): R

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

Link copied to clipboard
inline fun <R> foldRightIndexed(initial: R, operation: (index: Int, element: Long, acc: R) -> R): R

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

Link copied to clipboard
inline fun forEach(block: (element: Long) -> Unit)

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

Link copied to clipboard
inline fun LongList.forEachChunk(chunkSize: Int, action: (InPlaceLongSubList) -> Unit)

Iterates through the windowed chunks of this collection with given chunkSize, where window step is equals to chunkSize and calls action on each chunk.

Link copied to clipboard
inline fun LongList.forEachChunkIndexed(chunkSize: Int, action: (index: Int, InPlaceLongSubList) -> Unit)

Iterates through the windowed chunks of this collection with given chunkSize, where window step is equals to chunkSize and calls action on each chunk with its index.

Link copied to clipboard
inline fun forEachIndexed(block: (index: Int, element: Long) -> Unit)

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

Link copied to clipboard
inline fun forEachReversed(block: (element: Long) -> Unit)

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

Link copied to clipboard
inline fun forEachReversedIndexed(block: (index: Int, element: Long) -> Unit)

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

Link copied to clipboard
inline fun LongList.forEachWindow(windowSize: Int, step: Int = 1, partialWindows: Boolean = false, action: (InPlaceLongSubList) -> Unit)

Iterates through the windows of the list and performs the given action on each window.

Link copied to clipboard
inline fun LongList.forEachWindowIndexed(windowSize: Int, step: Int = 1, partialWindows: Boolean = false, action: (index: Int, InPlaceLongSubList) -> Unit)

Iterates through the windows of the list with their indices and performs the given action on each window.

Link copied to clipboard
operator fun get(index: Int): Long

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

Link copied to clipboard
open override fun hashCode(): Int

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

Link copied to clipboard
fun indexOf(element: Long): Int

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

Link copied to clipboard
inline fun indexOfFirst(predicate: (element: Long) -> Boolean): Int

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

Link copied to clipboard
inline fun indexOfLast(predicate: (element: Long) -> Boolean): Int

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

Link copied to clipboard
inline fun isEmpty(): Boolean

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

Link copied to clipboard
inline fun isNotEmpty(): Boolean

Returns true if there are elements in the LongList or false if it is empty.

Link copied to clipboard
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.

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.

Link copied to clipboard
fun last(): Long

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

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.

Link copied to clipboard
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.

Link copied to clipboard
inline fun <R> LongList.map(transform: (Long) -> R): List<R>

Returns an List containing the results of applying the given transform function to each element in the original LongList.

inline fun LongList.map(transform: (Long) -> Double): DoubleList

Returns a DoubleList containing the results of applying the given transform function to each element in the original LongList.

inline fun LongList.map(transform: (Long) -> Float): FloatList

Returns a FloatList containing the results of applying the given transform function to each element in the original LongList.

inline fun LongList.map(transform: (Long) -> Int): IntList

Returns a IntList containing the results of applying the given transform function to each element in the original LongList.

inline fun LongList.map(transform: (Long) -> Long): LongList

Returns a LongList containing the results of applying the given transform function to each element in the original LongList.

Link copied to clipboard
inline fun <R> LongList.mapIndexed(transform: (Int, Long) -> R): List<R>

Returns a List containing the results of applying the given transform function to each element and its index in the original LongList.

inline fun LongList.mapIndexed(transform: (Int, Long) -> Double): DoubleList

Returns a DoubleList containing the results of applying the given transform function to each element and its index in the original LongList.

inline fun LongList.mapIndexed(transform: (Int, Long) -> Float): FloatList

Returns a FloatList containing the results of applying the given transform function to each element and its index in the original LongList.

inline fun LongList.mapIndexed(transform: (Int, Long) -> Int): IntList

Returns a IntList containing the results of applying the given transform function to each element and its index in the original LongList.

inline fun LongList.mapIndexed(transform: (Int, Long) -> Long): LongList

Returns a LongList containing the results of applying the given transform function to each element and its index in the original LongList.

Link copied to clipboard
inline operator fun minusAssign(element: Long)
operator fun minusAssign(elements: LongArray)
operator fun minusAssign(elements: LongList)

Removes all elements from the MutableLongList.

Link copied to clipboard
inline fun none(): Boolean

Returns true if the collection has no elements in it.

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

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

Link copied to clipboard

Returns the LongList itself if it's not null; otherwise returns an empty LongList.

Link copied to clipboard
inline operator fun plusAssign(element: Long)
inline operator fun plusAssign(elements: LongArray)
inline operator fun plusAssign(elements: LongList)

Adds all elements to the end of the MutableLongList.

Link copied to clipboard
fun remove(element: Long): Boolean

Removes element from the MutableLongList. If element was in the MutableLongList and was removed, true will be returned, or false will be returned if the element was not found.

Link copied to clipboard
fun removeAll(elements: LongArray): Boolean
fun removeAll(elements: LongList): Boolean

Removes all elements from the MutableLongList and returns true if anything was removed.

Link copied to clipboard
fun removeAt(index: Int): Long

Removes the element at the given index and returns it.

Link copied to clipboard
fun removeRange(start: Int, end: Int)

Removes items from index start (inclusive) to end (exclusive).

Link copied to clipboard
fun retainAll(elements: LongArray): Boolean
fun retainAll(elements: LongList): Boolean

Keeps only elements in the MutableLongList and removes all other values.

Link copied to clipboard

Returns a new list with all elements in reversed order.

Link copied to clipboard
inline fun reversedAll(predicate: (element: Long) -> Boolean): Boolean

Returns true if all elements match the given predicate while iterating in the reverse order.

Link copied to clipboard
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.

Link copied to clipboard
operator fun set(index: Int, element: Long): Long

Sets the value at index to element.

Link copied to clipboard
fun sort()

Sorts the MutableLongList elements in ascending order.

Link copied to clipboard

Sorts the MutableLongList elements in descending order.

Link copied to clipboard

Returns a new list of all elements sorted according to natural sort order.

Link copied to clipboard

Returns a new list of all elements sorted according to descending natural sort order.

Link copied to clipboard
fun sum(): Long

Returns the sum of all elements in the list.

Link copied to clipboard
inline fun sumOf(element: (Long) -> Long): Long

Returns the sum of all elements in the list after transforming them by the given element function.

Link copied to clipboard
fun take(n: Int): LongList

Returns a new list containing the first n elements of this list.

Link copied to clipboard

Returns a new list containing the last n elements of this list.

Link copied to clipboard
inline fun takeLastWhile(predicate: (Long) -> Boolean): LongList

Returns a new LongList containing the last elements that satisfy the given predicate.

Link copied to clipboard
inline fun takeWhile(predicate: (Long) -> Boolean): LongList

Returns a new LongList containing the first elements that satisfy the given predicate.

Link copied to clipboard

Returns a LongArray containing all elements from this list in the same order.

Link copied to clipboard

Return a MutableSet of all elements. The returned set does NOT guarantee the element iteration order of the list.

Link copied to clipboard
fun toSet(): Set<Long>

Return a Set of all elements. The returned set does NOT guarantee the element iteration order of the list.

Link copied to clipboard
open override fun toString(): String

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

Link copied to clipboard
fun trim(minCapacity: Int = _size)

Reduces the internal storage. If capacity is greater than minCapacity and size, the internal storage is reduced to the maximum of size and minCapacity.

Link copied to clipboard
fun LongList.windowedInPlace(windowSize: Int, step: Int = 1, partialWindows: Boolean = false): WindowedLongList

Returns a WindowedLongList with the given windowSize sliding by step. Each window is a view into the original list.