3 ms·
How does an editor handle loading from disk and updating when someones inserts to the head of a file? Everything needs to be shifted.
by pkaye 8y ago
How does an editor handle loading from disk and updating when someones inserts to the head of a file? Everything needs to be shifted.
- ars 8y agoYou use a https://en.wikipedia.org/wiki/Rope_(data_structure) https://en.wikipedia.org/wiki/Rope_(data_structure) and not a flat string. You only flatten the string when it's time to write to disk. For autosave files make sure to store the changes to the rope, not the full text.
- lighttower 8y agoThere is a comment somewhere on HN from the guy that wrote the mapping trick that Word (or WordPerfect) invented way back. They were saving changes to the file rather than flattening. I wish I could find it now.