lua-users home
lua-l archive

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

hi all! :)

> Question: why a re-hash is wrong when assigning a nil?
> We do want the table to shrink when it becomes less populated.
> If you dis-allow this, then tables would only grow...

Egor wrote 'Nothing should be done if nil is assigned to a non-existing key.', and this is not the same as assigning to an existing key, that is what u worry about.

however, what this means, is that one should know the trick and do the check on lua side, which should be slower, and it is either magic or would be nice to be a documented boilerplate if its not done internally. it would be probably cheap and simple, it would avoid magic, but is this really a bad practice? anyone can assume that exchanging a nil with an another should be more cheap than a test on lua side.

Sean said that false is just for this, and thats right, and in this case, i would leave a note around advising false for this very purpose instead of telling that a check is cheaper than a rehash. i think a rehash is more of an implementation detail that shouldnt be exposed (at least not for this purpose) than talking about nils, if any should be exposed at all. i think this is more messy than having a guard at c level, while inserting nils are common enough to be optimized to the limits, as thats the way of deleting things. however i like to make things complicated (lets say flexible X'D ) like use true/false as boolean options besides other possible types with different usages, and if i do so, then i cant use false (maybe `NULL={}` or whatever, that is an another special check for tables, that are very much 1st place citizens of lua), but probably i dont/wont use this in such context where massive amounts of data should be stored, but mostly for making interfaces more flexible, and to cover any possibilities in general tools that operate on tables.

otherwise, for the personal problem, i think Sean is absolutely right, but how this [affects / will affect] lua is still a very interesting question! :)

no conclusion, just some related considerations to make any final decision the best possible, also, no suggestions, just thoughts.

all the bests to all of u! :)

Sent with ProtonMail Secure Email.