lua-users home
lua-l archive

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

> So what I did was borrow from awk, and create a string key...
> ...
> This, however, seems kludgy.  Is there a "lua" way to accomplish this
> task more elegantly?

Warning: shameless plug! :-)

You might want to check out my data structures library ( ), which has a data structure, HashMap,
which allows object keys to define their own hash functions
(basically, when inserting an object, HashMap checks for an obj.__hash
method and uses that to select a bucket in the map/table). So for
example, the Tuple class overrides __hash, so you can use this to have
a multikey map, like so:

> a = HashMap:new()
> a:add(Tuple:make(1,2), 'a'); a:add(Tuple:make(3,4), 'b')
> = a
{(1, 2)="a", (3, 4)="b"}
> = a:get(Tuple:make(1,2))

Here's the documentation page for HashMap, too, if you are interested: