PrefixSharingList

This is an implementation of an immutable List for which append, the non-destructive append operation, takes constant time. There is also a withoutLast operation for producing a list with its rightmost element removed. Iterating over the entire list takes linear time, and does not use recursion.

The implementation should be thread-safe if the lists that are supplied as prefixes are themselves thread-safe. Do not change any of those lists after constructing PrefixSharingLists from them.

Author

Mark van Gulik

Parameters

E

The type of elements in the list.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val size: Int

The size of this list.

Functions

Link copied to clipboard
open override fun add(element: E): Boolean
open override fun add(index: Int, element: E)
Link copied to clipboard
open override fun addAll(index: Int, elements: Collection<E>): Boolean
open override fun addAll(elements: Collection<E>): Boolean
Link copied to clipboard
fun <E2> List<E2>.append(lastElement: E2): List<E2>

Produce a new immutable list based on the prefix List (which must not be modified after this operation) and the new element to follow them.

Link copied to clipboard

Given a List of Iterables (over some X), execute the action for each combination of X values, one from each Iterable.

Link copied to clipboard
open override fun clear()
Link copied to clipboard
open operator override fun contains(element: @UnsafeVariance E): Boolean
Link copied to clipboard
open override fun containsAll(elements: Collection<E>): Boolean
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open fun forEach(p0: Consumer<in E>)
Link copied to clipboard
open operator override fun get(index: Int): E
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun indexOf(element: E): Int
Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
open operator override fun iterator(): MutableIterator<E>
Link copied to clipboard
open override fun lastIndexOf(element: E): Int
Link copied to clipboard
open override fun listIterator(): MutableListIterator<E>
open override fun listIterator(index: Int): MutableListIterator<E>
Link copied to clipboard
inline fun <T, R> Iterable<T>.mapToSet(destination: MutableSet<R> = mutableSetOf(), transform: (T) -> R): MutableSet<R>

Transform the receiver via the supplied function and collect the results into an optionally provided set. Answer the result set.

Link copied to clipboard
fun <E> Collection<E>.parallelDoThen(action: (E, () -> Unit) -> Unit, then: () -> Unit)

For each element in the collection, execute the action, passing a zero-argument function to run exactly once afterward (in this Thread or another). When the last element's zero-argument function has been invoked, or immediately if the collection is empty, invoke then.

Link copied to clipboard
inline fun <S, T> Collection<S>.parallelMapThen(crossinline action: (S, afterEach: (T) -> Unit) -> Unit, crossinline then: (List<T>) -> Unit)

For each element in the collection, execute the action, passing a zero-argument function to run exactly once afterward (in this Thread or another). When the last element's zero-argument function has been invoked, or immediately if the collection is empty, invoke then.

Link copied to clipboard
open fun parallelStream(): Stream<E>
Link copied to clipboard
fun <E, R> List<E>.partitionedMap(partitions: Int, body: (List<E>, (List<R>) -> Unit) -> Unit, after: (List<R>) -> Unit)

Partition the receiver into partitions approximately equal sublists. Some may be empty if count is larger than the receiver's size. Invoke the supplied body for each sublist. The body must eventually, perhaps in another Thread, invoke a function passed to it, to indicate completion, and to provide a list containing the element-wise transformation of the original sublist. These transformed sublists are then concatenated to form a new list, which is passed to the after function, perhaps in another Thread.

Link copied to clipboard
fun <E, K> List<E>.partitionRunsBy(groupingKey: (E) -> K): List<List<E>>

Given a list and a key-extraction function, produce a list of non-empty lists of elements that have the same key. Note that it only looks for runs of a key, and treats reoccurrences of some key after a gap to be a new key.

Link copied to clipboard
open override fun remove(element: E): Boolean
Link copied to clipboard
open override fun removeAll(elements: Collection<E>): Boolean
Link copied to clipboard
open override fun removeAt(p0: Int): E
Link copied to clipboard
open fun removeIf(p0: Predicate<in E>): Boolean
Link copied to clipboard

Kotlin has one of these in experimental, which forces the Universe to say it's also experimental. So boo.

Link copied to clipboard
open fun replaceAll(p0: UnaryOperator<E>)
Link copied to clipboard
open override fun retainAll(elements: Collection<E>): Boolean
Link copied to clipboard
open operator override fun set(index: Int, element: E): E
Link copied to clipboard
open fun sort(p0: Comparator<in E>)
Link copied to clipboard
open override fun spliterator(): Spliterator<E>
Link copied to clipboard
open fun stream(): Stream<E>
Link copied to clipboard
open override fun subList(fromIndex: Int, toIndex: Int): MutableList<E>
Link copied to clipboard
open fun toArray(): Array<Any>
open fun <T : Any> toArray(p0: Array<T>): Array<T>
open fun <T : Any> toArray(p0: IntFunction<Array<T>>): Array<T>
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

Produce a new immutable list based on the given list, but with the last element excluded. Try to avoid creating new objects if possible.