I have a 200MiB binary file containing pairs of Int64
and Int32
. The file is already sorted by the values on the Int64
.
I'm reading it like this:
private SortedDictionary<Int64, int> edgeID = new SortedDictionary<Int64, int>();
//Carico il file del mapping arco ID
using (BinaryReader b = new BinaryReader(File.Open(@"file.bin", FileMode.Open)))
{
Int64 keyID;
Int32 grafoID;
int numArchi = b.ReadInt32();
for (int i = 0; i < numArchi; i++)
{
keyID = (b.ReadInt64());
grafoID = b.ReadInt32();
edgeID[keyID] = grafoID;
}
}
But it's super slow. I noticed if I was using a normal Dictionary I could speed up a bit if I pass the dimension of the Dictionary in the costructor but apparently SortedDictionary
doesn't support that. Also I think the bigger problem is the program doesn't know I'm passing data already ordered so it checks the key at every insert.