Table of Contents

Class GapBufferWithStacks<T>

Namespace
AlgorithmsSW.GapBuffer
Assembly
AlgorithmsSW.dll

A gap buffer implemented with two stacks.

[ExerciseReference(1, 3, 44)]
public class GapBufferWithStacks<T> : IGapBuffer<T>

Type Parameters

T

The type of elements in the gap buffer.

Inheritance
GapBufferWithStacks<T>
Implements
Inherited Members
Extension Methods

Remarks

A gap buffer is a dynamic array that supports efficient insertions and deletions near a "cursor". Elements can be added or removed before or after the cursor. The cursor can be moved to any position in the buffer.

Constructors

GapBufferWithStacks(Func<IStack<T>>)

public GapBufferWithStacks(Func<IStack<T>> stackFactory)

Parameters

stackFactory Func<IStack<T>>

Properties

Count

Gets the number of elements in the gap buffer.

public int Count { get; }

Property Value

int

CursorIndex

Gets the current position of the cursor within the gap buffer.

public int CursorIndex { get; }

Property Value

int

this[int]

public T this[int index] { get; set; }

Parameters

index int

Property Value

T

this

public IGapBuffer<T> @this { get; }

Property Value

IGapBuffer<T>

Methods

AddAfter(T)

Adds an element after the cursor.

public void AddAfter(T item)

Parameters

item T

The element to add.

AddBefore(T)

Adds an element before the cursor.

public void AddBefore(T item)

Parameters

item T

The element to add.

MoveCursor(int)

Moves the cursor to the specified index.

public void MoveCursor(int newCursorIndex)

Parameters

newCursorIndex int

The new index for the cursor.

MoveCursorBy(int)

Moves the cursor by the specified amount.

public void MoveCursorBy(int offset)

Parameters

offset int

The amount to move the cursor by.

Exceptions

InvalidOperationException

moving the cursor past the begging or end.

RemoveAfter()

Removes an element after the cursor.

public T RemoveAfter()

Returns

T

The removed element.

RemoveBefore()

Removes an element before the cursor.

public T RemoveBefore()

Returns

T

The removed element.