Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not really, it's a commonly used scheme. Read on gap buffers: https://en.wikipedia.org/wiki/Gap_buffer

It's really an array with a gap at the cursor location. Used by emacs and others for decades.



In the article, I listed a rope, gap buffer, and piece table as potential solutions instead of "just an array".


VSCode uses a JS piece tree, which allows it to be faster* at manipulating large files than Sublime’s native code implementation.

https://code.visualstudio.com/blogs/2018/03/23/text-buffer-r...

*or at least competitive with. I’ve measured it to be faster but I’ve heard others have had different experiences


From a quick read it's actually pretty close to exactly what Sublime Text does. Source: Worked on that code at sublime recently.


But that's massively better than just an array. It changes the time complexity from O(char_inserts x file_len) to O(cursur_move x file_len), which is likely a couple orders of magnitude better.


That's not "just an array".


How big can file can a gap buffer be used on until it starts to slow down with current hardware?


That's not a single array though (per the OP's point)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: