CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2003
    Location
    Slovenia
    Posts
    4

    Question Complicated use of Hash_maps (or something else)

    I'm working on a "Scripting Engine" of my, and i'm having problems with something:

    My engine has object structure like that:

    Code:
              File
                   File.Open()
              Screen
                   Screen.Write()
                   Screen.Draw()
              Error()
              Execute()
              Net
                   Net.Socket
                        Net.Socket.Open
                   Net.HTMLParser
                        Net.HTMLParser.Parse()
                   Net.HTTP
                        Net.HTTP.Download()
                        Net.HTTP.Upload()
    (hasn't yet been implemented)

    Now, I plan to store those identifiers in multiple nested hash_maps. The root (top) hash_map would include Top elements (Screen, File, Error() above) in pair (String, Identifier):
    Code:
         struct  Identifier{
              int Type;                // INT, STRING, BOOL, Object ...
              void *Value;
         }
    Identifier.Value may point to real value (like 100 if INT, 'c' if char, address of a function...),
    but if it's a object (like Screen above), it would point to another hashtable containing it's elements (Write() and Draw() above)

    (Please, if you don't get it, message me and i will try to explain a bit better)

    Is there any faster way to deal with this?
    Anybody knows it?

    Last edited by MTom; December 20th, 2003 at 05:03 PM.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,405
    The hierarchy of hash maps you suggest would be very fast, basically just one hash table access per hierarchy level.

    BUT if users always have to qualify the full identifier, like for example Net.HTTP.Download, then you could store all possible identifiers in one big hash map with the identifiers as keys (strings), like "Net.HTTP.Download". In this way the identifier hierarchy would be coded "in the key" and you'ld have just one hash table access per identifier.

    I don't think this would be very much faster than your suggestion though, but at least it's an alternative

  3. #3
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Would it be possible to use the STL collection classes? If so, then you could do that initially, then optimize that later. If you are concerned that the STL collection classes are not efficient, then you might be surprised. However if you use the STL collection classes initially then you will sure have a good benchmark to compare to when you optimize your program later.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  4. #4
    Join Date
    Oct 2003
    Location
    Philadelphia, PA
    Posts
    167
    You could introduce a nesting-type character to avoid the handling of multiple hash maps/files. We use something like this in an internal data-description format, and the use of nesting is easier to interpet by UI code.
    Mike Dershowitz
    [email protected]
    www.lexientcorp.com

  5. #5
    Join Date
    Dec 2003
    Location
    Slovenia
    Posts
    4
    mikedershowitz: What do you mean?

    Please Explain

  6. #6
    Join Date
    Nov 2003
    Posts
    1,405
    Originally posted by MTom
    mikedershowitz: What do you mean?

    Please Explain
    Let me make a wild guess. He means what I suggested in my post. You move the hierarchy from the hashmaps to the identifier.
    For example the hierarchy "Net" -> "Socket" -> "Open" stored as three hashmaps is coded as "Net.Socket.Open" and stored in just one hashmap.

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