|
-
December 20th, 2003, 04:59 PM
#1
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.
-
December 21st, 2003, 08:49 AM
#2
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
-
December 21st, 2003, 04:32 PM
#3
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.
-
December 22nd, 2003, 06:52 PM
#4
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.
-
December 24th, 2003, 08:22 AM
#5
mikedershowitz: What do you mean?
Please Explain
-
December 25th, 2003, 02:12 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|