Hello,
Here's the problem. I have a 2D text-like buffer (basically List<List<Object>>
), indexed by (row, col) coordinates. Each row can have arbitrary length.
Let pos = (row, col)
. Then an interval is defined by (fromPos, toPos)
.
The text buffer can be modified by inserting and deleting characters:
void addRow(int rowIndex, Row<T> newRow);
void removeRow(int rowIndex);
void insert(int row, int col, Collection<? extends T> els);
void delete(int row, int col, int count);
How do I reflect changes in the text in position of intervals? Intervals are nested, but not strictly.
The main problem is that intervals can be empty and the ordering and nesting of intervals must be preserved.
For example:
0 1 2 3 4 (interval number) [a[bcd[]][][ef]gh] (text) 0 123 45 67 (char index)
after insert of X
in the 3rd interval (absolute position 4) should become
0 1 2 3 4 (interval number) [a[bcd[]][X][ef]ghijk] (text)
What are some ways to store intervals to be able to reflect changes of the text correctly and efficiently?