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

ie

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

So I could make a map

map <int, double*> ColorMap;

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

ColorMap[2]

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

double Color = [1 2 3];
ColorMap;

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

Thanks,

Dave

Recommended Answers

All 2 Replies

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?

Dave

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.