I have two huge dictionaries, one named DictHashesSource with 2256001 lines and another dictionary named DictHashesTarget with 2061735 lines.
Dictionary<int, string> DictHashesSource = new Dictionary<int, string>();
Dictionary<int, string> DictHashesTarget = new Dictionary<int, string>();
What I want to do is, for each element of DictHashesSource retrieve all elements in DictHashesTarget that match, and do the exact same thing in the oposite way. To do so, I used LINQ like bellow:
IEnumerable<string> interceptedRowsSource = DictHashesSource.Values.Where(x => DictHashesTarget.Values.Contains(x)).ToList();
IEnumerable<string> interceptedRowsTarget = DictHashesTarget.Values.Where(x => DictHashesSource.Values.Contains(x)).ToList();
The problem is, as the two dictionaries are really big, it takes more than 1 hour to do each operation, is there any way to reduce the complexity of this algorithm?
Note: I really have to use two dictionaries because I will have to use the keys in further operations.
Another note: The same value doesnt have the same key in both dictionaries