I have two dictionaries that I am trying to join and save the matching indices in a separate dictionary like so:
public class MatchedPairs
{
public List<int> index1;
public List<int> index2;
public MatchedPairs()
{
this.index1 = new List<int>();
this.index2 = new List<int>();
}
}
Dictionary<int, string> file1Dictionary = new Dictionary<int, string>();
Dictionary<int, string> file2Dictionary = new Dictionary<int, string>();
//Fill dictionaries with data from flat files
//...
var matchedKeys = file1Dictionary.Join(file2Dictionary, x => x.Value, y => y.Value, (x, y) => new { k1 = x.Key, k2 = y.Key });
Dictionary<int, MatchedPairs> matches = new Dictionary<int, MatchedPairs>();
foreach (var match in matchedKeys)
{
matches.index1.Add(match.k1);
matches.index2.Add(match.k2);
}
I receive an
Out of Memory exception
when executing this code because file1Dictionary
and file2Dictionary
objects have millions of entries in them.
Is there anything I can do to be able to match these large objects in memory/in C#. My alternative is to load the data into a SQL database and do the joining there. Thanks.