MutableIntGapBuffer

interface MutableIntGapBuffer

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

Copies from the gap buffer into the provided IntArray.

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

Gets the Int at the given offset.

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

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

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

Pushes the given IntArray 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: Int)

Sets the Int 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 MutableIntGapBuffer.binarySearch(    element: Int,     fromIndex: Int = 0,     toIndex: Int = size): Int

Searches this MutableIntGapBuffer for the provided element using the binary search algorithm. The array is expected to be sorted, otherwise the result is undefined.

Link copied to clipboard
fun MutableIntGapBuffer.copyOfRange(from: Int, until: Int): IntArray

Copies the given range from the MutableIntGapBuffer.

Link copied to clipboard
fun MutableIntGapBuffer.linearSearch(value: Int): Int

Returns the insertion index for the given Int. The insertion index can be seen as the index at which the cursor should be moved when inserting an event with the given sequence number and site identifier that would preserve the sorted behavior of the buffer.

Link copied to clipboard
fun MutableIntGapBuffer.pushAtGap(value: Int)

Pushes the given Int at the current gap cursor.

fun MutableIntGapBuffer.pushAtGap(    array: IntArray,     from: Int = 0,     until: Int = array.size)

Pushes an array of Int at the current gap cursor.

Link copied to clipboard
fun MutableIntGapBuffer.toIntArray(): IntArray

Copies the contents of this MutableIntGapBuffer into a new IntArray.

Link copied to clipboard
fun MutableIntGapBuffer.toTypedArray(): Array<Int>

Copies the contents of this MutableIntGapBuffer into a new Array of Int.