lua-users home
lua-l archive

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

> Wouldn't it be easy, and very low-overhead, to increment and decrement a
> count for every add/remove? My countpairs() is O(n) :-(

I don't think so. Each assignment to a table can potentially add or
remove an element, depending on whether the old and the new values are
nil or not. Moreover, the counter would increase the basic size of a
table. I mean, it is not a big overhead, but not so insignificant to be
paid by every program that do not use this specific functionality.

(Usually, most single needs have a simple, low-overhead, and quite
efficient way to be implemented directly in Lua. But if we add each one
of them to the language, the final result will be neither simple nor

-- Roberto