MutableDoubleList

class MutableDoubleList(initialCapacity: Int = 16) : DoubleList(source)

MutableDoubleList is a MutableList-like collection for Double values. It allows storing and retrieving the elements without boxing. Immutable access is available through its base class DoubleList, 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 MutableDoubleList with a capacity of initialCapacity.

Properties

Link copied to clipboard

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

Link copied to clipboard

Returns an IntRange of the valid indices for this DoubleList.

Link copied to clipboard

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

Link copied to clipboard
val size: Int

The number of elements in the DoubleList.

Functions

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

Adds element to the MutableDoubleList and returns true.

fun add(index: Int, element: Double)

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

Link copied to clipboard
inline fun addAll(elements: DoubleArray): Boolean
inline fun addAll(elements: List<Double>): Boolean
inline fun addAll(elements: DoubleList): Boolean

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

fun addAll(index: Int, elements: DoubleArray): Boolean
fun addAll(index: Int, elements: DoubleList): Boolean

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

Link copied to clipboard
inline fun all(predicate: (element: Double) -> 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: Double) -> 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: (Double) -> 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: (Double) -> 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<DoubleList>

Splits this list into chunks of specified size.

Link copied to clipboard

Splits this list into a list of InPlaceDoubleSubList 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 MutableDoubleList. The storage isn't released.

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

Returns true if the DoubleList contains element or false otherwise.

Link copied to clipboard

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

Link copied to clipboard

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

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: (Double) -> Boolean): DoubleList

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

Link copied to clipboard
inline fun dropWhile(predicate: (Double) -> Boolean): DoubleList

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

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

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

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 MutableDoubleList.

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

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

Link copied to clipboard
inline fun filter(predicate: (Double) -> Boolean): DoubleList

Returns a list containing only elements matching the given predicate.

Link copied to clipboard
fun first(): Double

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

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

Returns the first element in the DoubleList 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: Double) -> R): R

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

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

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

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

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

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

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

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

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

Link copied to clipboard
inline fun DoubleList.forEachChunk(chunkSize: Int, action: (InPlaceDoubleSubList) -> 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 DoubleList.forEachChunkIndexed(chunkSize: Int, action: (index: Int, InPlaceDoubleSubList) -> 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: Double) -> Unit)

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

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

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

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

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

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

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

Link copied to clipboard
inline fun DoubleList.forEachWindowIndexed(windowSize: Int, step: Int = 1, partialWindows: Boolean = false, action: (index: Int, InPlaceDoubleSubList) -> 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): Double

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 DoubleList.

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

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

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

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

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

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

Link copied to clipboard
inline fun isEmpty(): Boolean

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

Link copied to clipboard
inline fun isNotEmpty(): Boolean

Returns true if there are elements in the DoubleList 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: (Double) -> 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(): Double

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

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

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

Link copied to clipboard
fun lastIndexOf(element: Double): Int

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

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

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

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

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

inline fun DoubleList.map(transform: (Double) -> Float): FloatList

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

inline fun DoubleList.map(transform: (Double) -> Int): IntList

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

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

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

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

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

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

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

inline fun DoubleList.mapIndexed(transform: (Int, Double) -> Float): FloatList

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

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

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

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

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

Link copied to clipboard
inline operator fun minusAssign(element: Double)
operator fun minusAssign(elements: DoubleArray)
operator fun minusAssign(elements: DoubleList)

Removes all elements from the MutableDoubleList.

Link copied to clipboard
inline fun none(): Boolean

Returns true if the collection has no elements in it.

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

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

Link copied to clipboard

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

Link copied to clipboard
inline operator fun plusAssign(element: Double)
inline operator fun plusAssign(elements: DoubleArray)
inline operator fun plusAssign(elements: DoubleList)

Adds all elements to the end of the MutableDoubleList.

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

Removes element from the MutableDoubleList. If element was in the MutableDoubleList 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: DoubleArray): Boolean
fun removeAll(elements: DoubleList): Boolean

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

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

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: DoubleArray): Boolean
fun retainAll(elements: DoubleList): Boolean

Keeps only elements in the MutableDoubleList 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: Double) -> 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: Double) -> 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: Double): Double

Sets the value at index to element.

Link copied to clipboard
fun sort()

Sorts the MutableDoubleList elements in ascending order.

Link copied to clipboard

Sorts the MutableDoubleList 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(): Double

Returns the sum of all elements in the list.

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

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

Link copied to clipboard

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: (Double) -> Boolean): DoubleList

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

Link copied to clipboard
inline fun takeWhile(predicate: (Double) -> Boolean): DoubleList

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

Link copied to clipboard

Returns a DoubleArray 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<Double>

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 DoubleList.windowedInPlace(windowSize: Int, step: Int = 1, partialWindows: Boolean = false): WindowedDoubleList

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