I'm working on creating a List which has the following structure
Item 1
Key:Value
Key:Value
Key:Value
... (between 100 to 1000 pairs)
Item 2
Key:Value
Key:Value
Key:Value
... (between 10 to 1000 pairs)
Item 3
... (upto about 300,000 items)
I started by using the following
Dictionary<string, SortedList<string, string>>
The problem was after adding about 10,000 items it started slowing down exponentially.
Then I moved to
List<Tuple<string, SortedList<string, string>>>
This worked upto about 20,000 entries and then started slowing down, by 40,000 items it was exponentially slow
I'm trying to figure out what's the fastest way to add create a list of the items structure I pointed out above.
I'm only want to preserve order insertion, I'm only looking at inserting and reading back the data in FIFO order. No modifications to any data elements once inserted.
Given the simple FIFO needs would be the fastest way to store and retrieve the data?
I can't find any definitive comparisons between List, Dictionary, Sorted List, Tuple etc for FIFO. Or is there some other Class I should be using?
I can change the way the data is accessed, i.e. dictionary not required, the ONLY requirement is sequential insertion and reading back (FIFO) for all items AND KeyValue pairs
UPDATE: Here is the outline of the code
I also tried a Queue<KeyValuePair<string, Dictionary<string, string>>>
but again it slowed down after inserting about 25,000 items.
CREATING THE LIST:
Dictionary<string, Dictionary<string, string>> retVal = new Dictionary<string, Dictionary<string, string>>();
List<string> fileNames = GetNames();
foreach (string filePath in fileNames)
{
Dictionary<string, string> entries = GetKeyValuePairs(filePath);
if (!retVal.ContainsKey(filePath))
retVal.Add(filePath, entries);
}
return retVal
READING BACK:
foreach (string filePath in retVal)
{
Dictionary<string, string> entries = retVal[filePath];
foreach (string key in entries.Keys)
{ ... }
}