In C# I have a use case where I have a mapping from ints to collections.
- the
ints are a dense (but not packed) set from 1 to n where n is not known. - The cells will be loaded in random order.
- the marginal cost of each cell should be ideal (as good as a
List<T>orT[]) - I’d like to have the cells default filled on demand
What is the best structure for this?
A List<T> would work well (better in space than a Dictionary<>) and by deriving from it I can get much of what I want, but is there something better? As in the best code is code you don’t write.
A
Dictionary<int, Cell>sounds like a good match to me. Or you could use aList<Cell>quite easily, and just make sure that you expand it where necessary: