Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seek through massive data grouped with multiple keys C#

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 : enter image description herehttp://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.

like image 493
Naster Avatar asked Apr 08 '14 20:04

Naster


1 Answers

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));
like image 66
BenVlodgi Avatar answered Oct 05 '22 01:10

BenVlodgi