I'm building a program. It uses data stored in text files in following format {Index:Value}. Example:
1:10,86;
2:11,65;
3:13,32;
4:13,53;
5:13,93;
...
1500:1565,99;
There is rougly 1490-1500 lines in each file.
I need those files read in a dictionary and access its Index as integer and Value as double both by different functions. Something like:
Data.ByIndex((integer) 3) - returns (double) 13,32
Now getting Index by Value would be little more tricky:
Data.ByClosestValue((double) 12,0) - returns (integer) 2
Data.ByClosestValue((double) 13) - returns (integer) 3
Data.ByClosestLower((double) 13,5) - returns (integer) 3
Data.ByClosestHigher((double) 13,5) - returns (integer) 5
There are few key moments:
- It has to be really fast. There is usually 10-15 data files read in the same time and the dictionary accessed several times for each file.
- No LINQ if possible.
For now I went with following:
- File.ReadAllText() method seems the fastest to me.
- Getting entries by using Split(';') and the Split(':').
Dictionary <string, string>
. The reason I went with string types is that if will be faster to read from text data by using Split() function.
What will be the optimal solution?
Update: most people would suggest storing data in a database and I agree that would be the best solution, but unfortunately I have no control over those data files. These data files are formed in another program and there is a strict requirement it must be editable by human via notepad or whatever.