what is the best Data Structure to hold 'grid' information?
What is the best memory data structure to hold a grid ? By grid i mean a rectangular table with rows and columns, where the entries are not single values, but can hold any information.
Example: an availability "calendar", where i want to show room types as row headers (variable number), and dates as column headers (fixed, limited to 2 weeks at a time); and the intersection being all information about the particular cell (e.g. booked, available, guest names, etc).
Thanks for any pointers.
Re: what is the best Data Structure to hold 'grid' information?
A 2D array of some structure holding the data for each 'cell' (are you booking a prison?) will probably do. Quite what that structure is, and whether anything different is required to hold the data grid, can't be answered with the info provided.
Re: what is the best Data Structure to hold 'grid' information?
Quote:
Originally Posted by
pm_kirkham
A 2D array of some structure holding the data for each 'cell' (are you booking a prison?) will probably do
Ok. i was trying to avoid arrays if something better was available. For example, similar to a Dictionary in C#, where given a typed-key, return a typed-value; problem is dictionary is 1- dimensional, i wish there was a 'two-dimensional' dictionary. Then i could use roomtype for dimension 1 (instead of meaningless integer), weekday for dimension 2 (instead of meaninless integer) and get the cell-object.
Anyway thanks for your response.
Re: what is the best Data Structure to hold 'grid' information?
Quote:
Originally Posted by prideaux69
For example, similar to a Dictionary in C#, where given a typed-key, return a typed-value; problem is dictionary is 1- dimensional, i wish there was a 'two-dimensional' dictionary. Then i could use roomtype for dimension 1 (instead of meaningless integer), weekday for dimension 2 (instead of meaninless integer) and get the cell-object.
You could use an ordered pair of values for the key.
Re: what is the best Data Structure to hold 'grid' information?
Quote:
Originally Posted by
prideaux69
Then i could use roomtype for dimension 1 (instead of meaningless integer), weekday for dimension 2 (instead of meaninless integer) and get the cell-object.
Sounds just like a database to me. SQLLite?
Re: what is the best Data Structure to hold 'grid' information?
If you want to perform two lookups like that instead of having "meaningless" (you could use an enum so they aren't so "meaningless") int's you can always use a HashMap of HashMaps lol.
The first key value will be the room lookup. This will return a HashMap that holds all of the weekday for the lookup in that HashMap that will return the value for that day.
Just a thought, but if you use an enum, you can use arrays in the same exact way and the "meaningless" ints would be hidden.
enum WEEKDAYS {Sunday, Monday... };
Sunday = 0
Monday = 1
...
And you access your array by using array[WEEKDAYS.Sunday]. It's still an array, easy fast lookup for known indexes, and you don't have "meaningless" ints.