lua-users home
lua-l archive

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


Hello,

Some questions on the topic of object identity/address, and hashing:

-1- Is the object identity internally implemented as its actual memory address?

-2- Is there a way to get this value (like python's id() func)
(I wrote
   local adr = tonumber(string.sub(tostring(obj), 8))
waiting for a better solution ;-)

-3- I read somewhere that table key hashes (*) are obtained from key adresses (or identities, as opposed to hashing data itself). Is this correct? If yes, what kind of hash formula/algorithm is then used?

-4- If the above is true, then why isn't this the common way, since it seems to have only advantages:
* The input type is constant, thus permits a specialised func.
* Anyway, it cannot be simpler (integer).
* Hashing the id allows any type of key, as the id is constant by definition. (Constrast: hashing the data only allows data types which are guaranteed to be constant = immutable. see python issues)

-5- The simplest way to hash integers is certainly to get the modulo N, where N is the number of indexes (and of "buckets" in case of collisions). What about this simplissim solution?

-6- By exploring this topic, I discovered (on my computer) a minimal offset of 8 bytes between addresses (I mean they are assigned modulo 8). (Thus, addresses must be divided per 8 before beeing hashed.) Has this something to do with Lua?


Denis

(*) What's the common name for "return value of a hash func" in english?
(In french we commonly say "empreinte", meaning _print_ like in "finger print", but there are other words depending on use case.)
________________________________

la vita e estrany

http://spir.wikidot.com/