Tree vs Map

T

Travis

I've created a custom Tree template. The tree mimics a menu tree and
has the following properties.
- nodes are identified by a unique name
- any node can have infinite child nodes
- nodes are not sorted so traversal is breadth first looking for the
key
- nodes are inserted by identifying the desired parent

This works out well once the tree is constructed because it actually
resembles the menu tree but as with a lot of things in programming,
that may not always be advantageous. So I'm wondering if it would
really benefit me going to something like the stl map structure?

Thanks.
 
S

Simon Wollwage

Am Mon, 09 Jul 2007 15:37:11 +0000 schrieb Travis:
I've created a custom Tree template. The tree mimics a menu tree and has
the following properties.
- nodes are identified by a unique name - any node can have infinite
child nodes - nodes are not sorted so traversal is breadth first looking
for the key
- nodes are inserted by identifying the desired parent

This works out well once the tree is constructed because it actually
resembles the menu tree but as with a lot of things in programming, that
may not always be advantageous. So I'm wondering if it would really
benefit me going to something like the stl map structure?

Thanks.

something like this would be good if you want to use a map:

struct entry {
string caption;
entry* next;
entry* sub;
};

map<string, entry*> menu;

but i recommend __gnu_cxx::hash_map for this. std::map is slow cause it
uses an AVL-Tree under it's surface.
 
T

Travis

Am Mon, 09 Jul 2007 15:37:11 +0000 schrieb Travis:




something like this would be good if you want to use a map:

struct entry {
string caption;
entry* next;
entry* sub;

};

map<string, entry*> menu;

but i recommend __gnu_cxx::hash_map for this. std::map is slow cause it
uses an AVL-Tree under it's surface.

Then I might just stick with my current custom tree. The nice thing
about it is once it's created, traversal is very efficient. I'm either
going to the children or the too the parent which are already known
and don't require searching. Insertion (only done at initialization of
the program) might be costly though. Hmmmm
 
G

Guest

Am Mon, 09 Jul 2007 15:37:11 +0000 schrieb Travis:


something like this would be good if you want to use a map:

struct entry {
string caption;
entry* next;
entry* sub;
};

map<string, entry*> menu;

but i recommend __gnu_cxx::hash_map for this. std::map is slow cause it
uses an AVL-Tree under it's surface.


No, more likely a red-black tree. An as to the speed, for the usage that
the OP has it would probably not be noticeable even if searches were linear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top