MutableGapBuffer

interface MutableGapBuffer<T>

An interface representing a mutable gap buffer, containing a sequence of T, which is optimized for chunk insertions and removals.

Gap buffers are data structures which support amortized constant-time consecutive insertions, similarly to an array-based list, but at arbitrary buffer positions. They may be used to store a sequence of items which are known to be inserted group-wise.

In a gap buffer, positions are known as offsets. An offset is semantically identical to an index in an array, except that it jumps over the gap.

Functions

Link copied to clipboard
abstract fun clear()

Removes the whole gap buffer, clearing the current data. This operation takes a constant time and does not require moving the gap.

Link copied to clipboard
abstract fun copyInto(    array: Array<T>,     destinationOffset: Int = 0,     startOffset: Int = 0,     endOffset: Int = size): Array<T>

Copies from the gap buffer into the provided Array.

Link copied to clipboard
abstract operator fun get(offset: Int): T

Gets the T at the given offset.

Link copied to clipboard
abstract fun push(value: T, offset: Int = size)

Pushes the given T at the provided offset (defaults to the end of the buffer).

abstract fun push(    array: Array<T>,     offset: Int = size,     startIndex: Int = 0,     endIndex: Int = array.size)

Pushes the given Array at the provided offset (defaults to the end of the buffer).

Link copied to clipboard
abstract fun remove(offset: Int, size: Int = 1)

Removes the given count of items from the gap buffer at the given offset.

Link copied to clipboard
abstract operator fun set(offset: Int, value: T)

Sets the T at the given offset.

Properties

Link copied to clipboard
abstract val gap: Gap

Some meta-data about the Gap. This may be useful for specific optimizations.

Link copied to clipboard
abstract val size: Int

How many items there are in the gap buffer.

Extensions

Link copied to clipboard
inline fun <T> MutableGapBuffer<T>.copyOfRange(from: Int, until: Int): Array<T>

Copies the given range from the MutableGapBuffer.

Link copied to clipboard
fun <T> MutableGapBuffer<T>.pushAtGap(value: T)

Pushes the given T at the current gap cursor.

fun <T> MutableGapBuffer<T>.pushAtGap(    array: Array<T>,     from: Int = 0,     until: Int = array.size)

Pushes an array of T at the current gap cursor.

Link copied to clipboard
inline fun <T> MutableGapBuffer<T>.toTypedArray(): Array<T>

Copies the contents of this MutableGapBuffer into a new ByteArray.