Alex Rivera | Logout

How to implement a multi-index dictionary?

Asked 2009-10-01T14:56:33.203
34

Basically I want something like Dictionary<Tkey1, TKey2, TValue>, but not (as I've seen here in other question) with the keys in AND, but in OR. To better explain: I want to be able to find an element in the dictionary providing just one of the keys, not both.

I also think we should consider thread-safety and the ability to easily scale to a Dictionary<Tkey1, TKey2, TKeyN, TValue> solution...

Edit
Report

2 Answers

22

I would implement a data structure with these two dictionaries

Dictionary<TKey1, KeyValuePair<TKey2, TValue>> dict1;
Dictionary<TKey2, KeyValuePair<TKey1, TValue>> dict2;

That way if you are given 1 key you have both the value and the other key as well for easy deletes and updates.

answered 2009-10-01T15:11:45.253
0

What about a Multi Index Container inspired by boost??

Take a look at CodeProject.

answered 2010-03-05T13:28:09.067

Your Answer