MutableCharGapBuffer

interface MutableCharGapBuffer

An interface representing a mutable gap buffer, containing a sequence of Char, 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: CharArray,     destinationOffset: Int = 0,     startOffset: Int = 0,     endOffset: Int = size): CharArray

Copies from the gap buffer into the provided CharArray.

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

Gets the Char at the given offset.

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

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

abstract fun push(    array: CharArray,     offset: Int = size,     startIndex: Int = 0,     endIndex: Int = array.size)

Pushes the given CharArray 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: Char)

Sets the Char 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
fun MutableCharGapBuffer.copyOfRange(from: Int, until: Int): CharArray

Copies the given range from the MutableCharGapBuffer.

Link copied to clipboard
fun MutableCharGapBuffer.pushAtGap(value: Char)

Pushes the given Char at the current gap cursor.

fun MutableCharGapBuffer.pushAtGap(    array: CharArray,     from: Int = 0,     until: Int = array.size)

Pushes an array of Char at the current gap cursor.

Link copied to clipboard
fun MutableCharGapBuffer.toCharArray(): CharArray

Copies the contents of this MutableCharGapBuffer into a new CharArray.

Link copied to clipboard
fun MutableCharGapBuffer.toTypedArray(): Array<Char>

Copies the contents of this MutableCharGapBuffer into a new Array of Char.