MutableByteGapBuffer

interface MutableByteGapBuffer

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

Copies from the gap buffer into the provided ByteArray.

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

Gets the Byte at the given offset.

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

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

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

Pushes the given ByteArray 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: Byte)

Sets the Byte 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 MutableByteGapBuffer.copyOfRange(from: Int, until: Int): ByteArray

Copies the given range from the MutableByteGapBuffer.

Link copied to clipboard
fun MutableByteGapBuffer.pushAtGap(value: Byte)

Pushes the given Byte at the current gap cursor.

fun MutableByteGapBuffer.pushAtGap(    array: ByteArray,     from: Int = 0,     until: Int = array.size)

Pushes an array of Byte at the current gap cursor.

Link copied to clipboard
fun MutableByteGapBuffer.toByteArray(): ByteArray

Copies the contents of this MutableByteGapBuffer into a new ByteArray.

Link copied to clipboard
fun MutableByteGapBuffer.toTypedArray(): Array<Byte>

Copies the contents of this MutableByteGapBuffer into a new Array of Byte.