MutableEventIdentifierGapBuffer

interface MutableEventIdentifierGapBuffer

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

Copies from the gap buffer into the provided EventIdentifierArray.

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

Gets the EventIdentifier at the given offset.

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

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

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

Pushes the given EventIdentifierArray 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: EventIdentifier)

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

Searches this MutableEventIdentifierGapBuffer 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 MutableEventIdentifierGapBuffer.binarySearchBySite(    element: SiteIdentifier,     fromIndex: Int = 0,     toIndex: Int = size): Int

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

Link copied to clipboard
fun MutableEventIdentifierGapBuffer.copyOfRange(from: Int, until: Int): EventIdentifierArray

Copies the given range from the MutableEventIdentifierGapBuffer.

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

Returns the insertion index for the given EventIdentifier. 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 MutableEventIdentifierGapBuffer.pushAtGap(value: EventIdentifier)

Pushes the given EventIdentifier at the current gap cursor.

fun MutableEventIdentifierGapBuffer.pushAtGap(    array: EventIdentifierArray,     from: Int = 0,     until: Int = array.size)

Pushes an array of EventIdentifier at the current gap cursor.

Link copied to clipboard
Link copied to clipboard

Copies the contents of this MutableEventIdentifierGapBuffer into a new Array of EventIdentifier.