Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing built-in string hash functions of Lua

Tags:

string

lua

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?

like image 409
decasteljau Avatar asked Dec 21 '09 15:12

decasteljau


1 Answers

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.

like image 139
Norman Ramsey Avatar answered Sep 19 '22 20:09

Norman Ramsey