public class MutableVector<T>
@PublishedApi
internal constructor(@PublishedApi @JvmField internal var content: Array<T?>, size: Int) :
RandomAccess
A MutableList-like structure with a simplified interface that offers faster access than ArrayList.
Functions
add
public fun add(element: T): Boolean
Adds element to the MutableVector and returns true.
add
public fun add(index: Int, element: T)
Adds element to the MutableVector at the given index, shifting over any elements that are in the way.
addAll
public fun addAll(index: Int, elements: List<T>): Boolean
Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.
addAll
public fun addAll(index: Int, elements: MutableVector<T>): Boolean
Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.
addAll
public inline fun addAll(elements: List<T>): Boolean
Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.
addAll
public inline fun addAll(elements: MutableVector<T>): Boolean
Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.
addAll
public fun addAll(@Suppress("ArrayReturn") elements: Array<T>): Boolean
Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.
addAll
public fun addAll(index: Int, elements: Collection<T>): Boolean
Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.
addAll
public fun addAll(elements: Collection<T>): Boolean
Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.
any
public inline fun any(predicate: (T) -> Boolean): Boolean
Returns true if any of the elements give a true return value for predicate.
reversedAny
public inline fun reversedAny(predicate: (T) -> Boolean): Boolean
Returns true if any of the elements give a true return value for predicate while iterating in the reverse order.
asMutableList
public fun asMutableList(): MutableList<T>
Returns MutableList interface access to the MutableVector.
clear
public fun clear()
Removes all elements in the MutableVector.
contains
public operator fun contains(element: T): Boolean
Returns true if the MutableVector contains element or false otherwise.
containsAll
public fun containsAll(elements: List<T>): Boolean
Returns true if the MutableVector contains all elements in elements or false if one or more are missing.
containsAll
public fun containsAll(elements: Collection<T>): Boolean
Returns true if the MutableVector contains all elements in elements or false if one or more are missing.
containsAll
public fun containsAll(elements: MutableVector<T>): Boolean
Returns true if the MutableVector contains all elements in elements or false if one or more are missing.
contentEquals
public fun contentEquals(other: MutableVector<T>): Boolean
Returns true if the contents of the MutableVector are the same or false if there is any difference. This uses equality comparisons on each element rather than reference equality.
ensureCapacity
public inline fun ensureCapacity(capacity: Int)
Ensures that there is enough space to store capacity elements in the MutableVector.
first
public fun first(): T
Returns the first element in the MutableVector or throws a NoSuchElementException if it isEmpty.
first
public inline fun first(predicate: (T) -> Boolean): T
Returns the first element in the MutableVector for which predicate returns true or throws NoSuchElementException if nothing matches.
firstOrNull
public inline fun firstOrNull(): T?
Returns the first element in the MutableVector or null if it isEmpty.
firstOrNull
public inline fun firstOrNull(predicate: (T) -> Boolean): T?
Returns the first element in the MutableVector for which predicate returns true or returns null if nothing matches.
fold
public inline fun <R> fold(initial: R, operation: (acc: R, T) -> R): R
Accumulates values, starting with initial, and applying operation to each element in the MutableVector in order.
foldIndexed
public inline fun <R> foldIndexed(initial: R, operation: (index: Int, acc: R, T) -> R): R
Accumulates values, starting with initial, and applying operation to each element in the MutableVector in order.
foldRight
public inline fun <R> foldRight(initial: R, operation: (T, acc: R) -> R): R
Accumulates values, starting with initial, and applying operation to each element in the MutableVector in reverse order.
foldRightIndexed
public inline fun <R> foldRightIndexed(initial: R, operation: (index: Int, T, acc: R) -> R): R
Accumulates values, starting with initial, and applying operation to each element in the MutableVector in reverse order.
forEach
public inline fun forEach(block: (T) -> Unit)
Calls block for each element in the MutableVector, in order.
forEachIndexed
public inline fun forEachIndexed(block: (Int, T) -> Unit)
Calls block for each element in the MutableVector along with its index, in order.
forEachReversed
public inline fun forEachReversed(block: (T) -> Unit)
Calls block for each element in the MutableVector in reverse order.
forEachReversedIndexed
public inline fun forEachReversedIndexed(block: (Int, T) -> Unit)
Calls block for each element in the MutableVector along with its index, in reverse order.
get
public inline operator fun get(index: Int): T
Returns the element at the given index.
indexOf
public fun indexOf(element: T): Int
Returns the index of element in the MutableVector or -1 if element is not there.
indexOfFirst
public inline fun indexOfFirst(predicate: (T) -> Boolean): Int
Returns the index if the first element in the MutableVector for which predicate returns true.
indexOfLast
public inline fun indexOfLast(predicate: (T) -> Boolean): Int
Returns the index if the last element in the MutableVector for which predicate returns true.
isEmpty
public inline fun isEmpty(): Boolean
Returns true if the MutableVector has no elements in it or false otherwise.
isNotEmpty
public inline fun isNotEmpty(): Boolean
Returns true if there are elements in the MutableVector or false if it is empty.
last
public fun last(): T
Returns the last element in the MutableVector or throws a NoSuchElementException if it isEmpty.
last
public inline fun last(predicate: (T) -> Boolean): T
Returns the last element in the MutableVector for which predicate returns true or throws NoSuchElementException if nothing matches.
lastIndexOf
public fun lastIndexOf(element: T): Int
Returns the index of the last element in the MutableVector that is the same as element or -1 if no elements match.
lastOrNull
public inline fun lastOrNull(): T?
Returns the last element in the MutableVector or null if it isEmpty.
lastOrNull
public inline fun lastOrNull(predicate: (T) -> Boolean): T?
Returns the last element in the MutableVector for which predicate returns true or returns null if nothing matches.
map
public inline fun <reified R> map(transform: (T) -> R): Array<R>
Returns an Array of results of transforming each element in the MutableVector. The Array will be the same size as this.
mapIndexed
public inline fun <reified R> mapIndexed(transform: (index: Int, T) -> R): Array<R>
Returns an Array of results of transforming each element in the MutableVector. The Array will be the same size as this.
mapIndexedNotNull
public inline fun <reified R> mapIndexedNotNull(
transform: (index: Int, T) -> R?
): MutableVector<R>
Returns an MutableVector of results of transforming each element in the MutableVector, excluding those transformed values that are null.
mapNotNull
public inline fun <reified R> mapNotNull(transform: (T) -> R?): MutableVector<R>
Returns an MutableVector of results of transforming each element in the MutableVector, excluding those transformed values that are null.
plusAssign
public inline operator fun plusAssign(element: T)
add element to the MutableVector.
minusAssign
public inline operator fun minusAssign(element: T)
remove element from the MutableVector
remove
public fun remove(element: T): Boolean
Removes element from the MutableVector. If element was in the MutableVector and was removed, true will be returned, or false will be returned if the element was not found.
removeAll
public fun removeAll(elements: List<T>): Boolean
Removes all elements from the MutableVector and returns true if anything was removed.
removeAll
public fun removeAll(elements: MutableVector<T>): Boolean
Removes all elements from the MutableVector and returns true if anything was removed.
removeAll
public fun removeAll(elements: Collection<T>): Boolean
Removes all elements from the MutableVector and returns true if anything was removed.
removeAt
public fun removeAt(index: Int): T
Removes the element at the given index and returns it.
removeRange
public fun removeRange(start: Int, end: Int)
Removes items from index start (inclusive) to end (exclusive).
removeIf
public inline fun removeIf(predicate: (T) -> Boolean)
Removes items that satisfy predicate
retainAll
public fun retainAll(elements: Collection<T>): Boolean
Keeps only elements in the MutableVector and removes all other values.
set
public operator fun set(index: Int, element: T): T
Sets the value at index to element.
sortWith
public fun sortWith(comparator: Comparator<T>)
Sorts the MutableVector using comparator to order the items.
sumBy
public inline fun sumBy(selector: (T) -> Int): Int
Returns the sum of all values produced by selector for each element in the MutableVector.