3 ms·
The trick is to decouple the concept of 'position' in the text, that is independent of the gap, from 'pointer' into the buffer. If you keep track of line beginn
by teo_zero 3y ago
The trick is to decouple the concept of 'position' in the text, that is independent of the gap, from 'pointer' into the buffer. If you keep track of line beginnings as positions, you can immediately get the pointers:
ptr = pos if pos<=gapstart else pos + gapsize
- teo_zero 3y agoReplying to myself: it's actually a bad idea because you have to update all indices at each inserted char! Forget about it...