Reputation: 3740
How would you go about making a bidirectional map in Lua? I am new to Lua, and the only way that I can think of is to put every key-value pair in a table, iterate over each pair to add them (key-value swapped) to the original table.
Is there a better way to do this?
Upvotes: 3
Views: 518
Reputation: 26794
I don't think there is a better way (assuming you can handle key/value conflicts). A slightly better way may be to store swapped values when you add a new values to the table (or update/remove an existing value), but the overall idea is the same.
Upvotes: 3