lua-users home
lua-l archive

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


On Thu, Jan 2, 2014 at 5:29 AM, Scott Morgan <blumf@blueyonder.co.uk> wrote:
> You might want to look at the 'rope' patten.
>
> http://en.wikipedia.org/wiki/Rope_%28computer_science%29
> http://lua-users.org/wiki/LuaRopes


definitely ropes are the answer for efficiently working with big text
contents, and LuaRopes implement most of the pattern as described on
the paper (a tree with strings at the leaves)

but in many cases, i've found that a simple array of strings works
beautifully as a "poor man's rope".  just pass around the array, and
at the end either output in a loop or call table.append() to create
the string just once.

if doing middle insertions or complex replacements, then go for full
ropes; but if most of the processing is just concatenating at the end,
the clarity of a string array is a big plus.

-- 
Javier