News for hackers. Stuff that matters.
Re:Text Showdown: Gap Buffers vs. Ropes by teo_zero on Tuesday October 10, 2023 @04:19AM (#37829681)
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
Re:Text Showdown: Gap Buffers vs. Ropes by teo_zero on Tuesday October 10, 2023 @04:54AM (#37829859)
Replying to myself: it's actually a bad idea because you have to update all indices at each inserted char! Forget about it...