CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2008
    Posts
    3

    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.

  2. #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.

  3. #3
    Join Date
    Feb 2008
    Posts
    3

    Re: what is the best Data Structure to hold 'grid' information?

    Quote Originally Posted by pm_kirkham View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: what is the best Data Structure to hold 'grid' information?

    Quote Originally Posted by prideaux69 View Post
    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

  6. #6
    Join Date
    Feb 2008
    Posts
    966

    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
  •  





Click Here to Expand Forum to Full Width

Featured