Original Post
I'm looking for a type of data structure that allows quick lookup on both a key and value. Basically, the problem is as follows: I have an id, name, and dataID. There is a one to many mapping from dataID to (id, name) tuple. Because of what my program is doing, I want to key off of the (id, name) tuple when assigning, but when retrieving I'd like to be able to grab all the (id, name) tuples associated with a single dataID. My current idea, which feels rather icky, follows: I'd have two maps, map[ (id, name), dataID ] forward; map[ dataID, list[ (id, name) ] ] backward; When doing the assignment to forward, I would also push onto the back of backward. When doing the retrieval, I would retrieve the list of a given dataID from backward, iterate over that list performing my operation, and if the (id, name) pair isn't found in forward (because of some change in assignment), remove it from the list instead of acting on it. It feels to me like this is a problem someone else has faced, and that there's probably a more elegant solution, but I haven't been able to think of one. Ideas? (Edit: Note, I'm using C++. The restrictions of the project allow me a subset of STL, but I can't bring in other libraries ala boost). Cheers, --Brian