I need an efficient way to look up a user by any 1 of 3 different keys. For example, by id, username or alias.
The basic concept would be a data structure in which you can use any of 3 different types of keys to look up the value:
-
myDataStructure.lookupByName(name) -> User -
myDataStructure.lookupById(id) -> User -
myDataStructure.lookupByAlias(alias) -> User
The only immediate way I can think of doing this would be to have 3 separate dictionaries, and use the one corresponding to the type of key provided.
Is there a more efficient way?
If you know that the keysets (names, ids and aliases) are distinct, you could put them all into a single table. Otherwise, you’d need the three separate tables that you noted.