lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In message <20100301131708.A27240@lua.tecgraf.puc-rio.br> you wrote:

> Try ropes: http://en.wikipedia.org/wiki/Rope_(computer_science)

A bit expensive for this purpose I think :).
What got me thinking was that "Edit", a texteditor which Acorn
Computers Ltd built into the ROM of the Archimedes back in the 80s,
used the double (before/after cursor) buffer datastructure, together
with a sliding heap. If Lua is to be embedded in such an application
it would be nice to use the memory allocation that comes with Lua.
In that case one might use two lists, one indexing forward from the first
character to the last before the cursor, the other indexing backwards
from the last character of the text to the one immediately following the
cursor. Moving the cursor then means sloshing top elements from one
list to the other. I had thought of trying to avoid reallocating new
lists by adding in a bit of laziness to the sloshing process. Have
lists-with-index, replace removal from the list by decrementing the
index, and allow list-items above the index to be overwritten before
the index is incremented.
Thanks for the references provided. This is all probably a standard
computer science exercise, but then I never did a degree in computer
science; there was no such beast when I was a student.

-- 
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/