Click to See Complete Forum and Search --> : what is the best Data Structure to hold 'grid' information?


prideaux69
March 2nd, 2009, 03:11 AM
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.

pm_kirkham
March 3rd, 2009, 11:28 AM
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.

prideaux69
March 4th, 2009, 02:02 AM
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.

laserlight
March 4th, 2009, 02:45 AM
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.

JohnW@Wessex
March 12th, 2009, 11:05 AM
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?

ProgramThis
March 13th, 2009, 12:52 PM
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.