I would like to make a list of colors with an associated color index


1, [1 0 0]
2, [0 1 0]
3, [.4 .4 .4]

So I could make a map

map <int, double*> ColorMap;

Then I could look up the color by its index like this:


However, I would also like to be able to get the index of a particular color, like this

double Color = [1 2 3];

and have it give me back the index. Is there an easy way to make this two-way mapping?



Yes. One easy way is to use two maps, one map<int, double*> and one map<double*, int>. You need to make sure that you only have one index per color, though. If you want to be able to have a color appearing at multiple indices, use a multimap<double*, int> instead of a map<double, int>.

ok, yea i was just trying to prevent having 2 maps because then when I want to update them (modify the contents) I'd have to do it in both maps.

So there is no built in thing to remedy this 2 map problem?


This article has been dead for over six months. Start a new discussion instead.