tags:

views:

225

answers:

2

Lua has built-in string hashing functionality for storage of strings inside its maps. It is possible to access it?

Or is there another string hash function already available in the lua language/libraries?

+2  A: 

There's no API for direct access to the internal hash function in the Lua core. Why can't you use a Lua table instead?

lhf
I don't need the hash to store inside a table. The hash is required for something else.
decasteljau
+2  A: 

The hash function is not exposed. By hiding the hash function, the Lua designers reserve the right to change it out from under you. For example, they may one day try "cuckoo hashing", which may work better with a different hash function.

If you want a hash function for storage into a hash table, you will be better off just using a Lua table as your data structure. If you want a hash function to serialize something to disk, you might consider the Kepler project's implementation of MD5 hashing for Lua.

Norman Ramsey
lhf also has an MD5 library. You can find that and a bunch of other goodies at http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/
uroc