In C#, I have some static data that could be put in a Dictionary<int, T>
where T
is some reference type. The web app only needs to initialize it once, statically (it doesn't change).
Since I don't have to worried about insert or delete performance, what is the best data structure to use (or should I roll my own)? I'm probably looking at something like ~100,000 entries, fairly evenly spaced.
I am looking for an optimal algorithm for fetching this data. Dictionary<>
isn't bad, but I would imagine there must be something out there optimized for read-only data.
I suspect, but haven't confirmed that the range of these keys might be 0 - 400,000. If that was the case, how would the recommendations change? (I have a thought that I will post as a possible answer).
Maybe I could:
- Scan through the data once and grab the highest key
- Allocate an array with the size of the highest key + 1.
- Take a second pass and store the data in the array.
Would this be better or worse than a HashTable / Dictionary with a reasonable load factor?