Expand description
Gap buffer implementation for efficient text editing.
This module provides a gap buffer data structure that efficiently handles text insertions and deletions at arbitrary positions. The gap buffer maintains a gap (unused space) at the cursor position, making insertions and deletions at that position O(1) operations.
§Design
The gap buffer uses a single contiguous array with a “gap” of unused space. When text is inserted or deleted, the gap moves to that position first, then the operation is performed by adjusting the gap boundaries.
§Trade-offs
- Insertions/deletions at cursor position: O(1)
- Moving the gap: O(n) where n is the distance moved
- Memory overhead: The gap size (typically grows as needed)
- Line-based operations: Currently O(n) as they require string conversion
Structs§
- GapBuffer
- Gap buffer implementation for efficient text editing.
Traits§
- Text
Buffer - A minimal text buffer trait that supports the features we have so far