I want to seek through massive data, grouped with multiple keys, in the fastest way possible. I have a file with this information but I want to load it in-memory. Memory capacitance is not a problem.
key1 | key2 | key3 | key4 | value1 | value2
-----|------|------|------|--------|--------
1 | 1 | 1 | 1 | str | 20
1 | 1 | 1 | 2 | str | 20
1 | 1 | 1 | 3 | str | 20
1 | 1 | 2 | 1 | str | 20
2 | 1 | 1 | 1 | str | 20
I have looked at some collections but I'm still uncertain : http://blog.bodurov.com/Performance-SortedList-SortedDictionary-Dictionary-Hashtable
Maybe a multikey dictionary will be better because it avoid a lots of redundancy in the keys.
public class MultiKeyDictionary<T1, T2, T3> : Dictionary<T1, Dictionary<T2, T3>>
key1 | key2 | key3 | key4 | value1 | value2
-----|------|------|------|--------|--------
1 | 1 | 1 | 1 | str | 20
| | | 2 | str | 20
| | | 3 | str | 20
| | 2 | 1 | str | 20
2 | 1 | 1 | 1 | str | 20
I will not seek every keys but maybe 50% of them. I'm open to even insane suggestions.
You could simply use a Tuple
of your keys for the dictionary key and for the value.
var bank = new Dictionary<Tuple<int, int, int, int, int>, Tuple<string, int>>();
bank.Add(Tuple.Create(k1, k2, k3, k4), Tuple.Create("str", 20));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With