-
March 2nd, 2009, 03:11 AM
#1
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.
-
March 3rd, 2009, 11:28 AM
#2
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.
-
March 4th, 2009, 02:02 AM
#3
Re: what is the best Data Structure to hold 'grid' information?
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.
-
March 4th, 2009, 02:45 AM
#4
Re: what is the best Data Structure to hold 'grid' information?
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.
-
March 12th, 2009, 10:05 AM
#5
Re: what is the best Data Structure to hold 'grid' information?
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?
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
March 13th, 2009, 11:52 AM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|