473,699 Members | 2,226 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tree vs Map

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.

Jul 9 '07 #1
3 3220
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.

--
/(bb|[^b]{2})/
"Microsoft - We put the bill in billionaire"
Jul 9 '07 #2
On Jul 9, 8:55 am, Simon Wollwage <wollwagesi...@ yahoo.co.jpwrot e:
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.

--
/(bb|[^b]{2})/
"Microsoft - We put the bill in billionaire"
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

Jul 9 '07 #3
On 2007-07-09 17:55, Simon Wollwage wrote:
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.

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.

--
Erik Wikström
Jul 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7953
by: Jeffrey Silverman | last post by:
Hi, all. I have a linked list. I need an algorithm to create a tree structure from that list. Basically, I want to turn this: $list = array( array( 'id' => 'A', 'parent_id' => null, 'value' => 'aaa') , array( 'id' => 'B', 'parent_id' => 'A', 'value' => 'bbb') , array( 'id' => 'C', 'parent_id' => 'B', 'value' => 'ccc') , array( 'id' => 'D', 'parent_id' => 'A', 'value' => 'ddd')
0
2178
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i am able to check using xpath in asp.net 2.0 till MenuItem node. if i check visible attribute value till SubMenuLevel0 node then in tree it will not display the MenuItem Node at all Note: My tree Menu will start from MenuItem node and it will...
4
9016
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working, even the removal, I just don't know how to keep track of the parent, so that I can set its child to the child of the node to be removed. IE - if I had C / \ B D
2
1634
by: New | last post by:
Why does this code insert a node into a binary search tree correctly? If I only inserting going by first digit it works properly but when I try inserting going by the whole ip and the port number the inserts are totally out of order. where IPAddress is four ints Node is an IPAddress, portNumber, left pointer and right pointer Nodeptr is a pointer to a Node
5
1987
by: Mike | last post by:
Why does this code insert a node into a binary search tree correctly? If I only inserting going by first digit it works properly but when I try inserting going by the whole ip and the port number the inserts are totally out of order. where IPAddress is four ints Node is an IPAddress, portNumber, left pointer and right pointer Nodeptr is a pointer to a Node
2
3478
by: Kiran | last post by:
Hello all, I am using a tree to display stuff, and it is constantly updated, but what I have noticed is in the lowest level, there is clearly noticable cutoff of the text I place there. The cutoff is existent even if I do not update the text inside the tree constantly. It seems that the text is halfway below where it should line up. I tried placing an image to see if that would correct it, but it does not. The image is perfectly lined up,...
1
4826
by: Satish.Talyan | last post by:
hi, i want to create a dynamic tree hierarchy in javascript.there are two parts in tree, group & user.when we click on group then users come under that's tree category will be opened.problem is that i am not able to arrange three things simultaneously,group,users & there functionality simultaneously.dynamic means group & users come from database and groups & users can be increased in number at any time. i am sending code for that tree...
1
2943
by: hn.ft.pris | last post by:
I have the following code: Tree.h defines a simple binary search tree node structure ########## FILE Tree.h ################ #ifndef TREE_H #define TREE_H //using namespace std; template <typename Tclass Tree{ private: Tree<T*left;
4
11010
by: whitehatmiracle | last post by:
Hello I have written a program for a binary tree. On compiling one has to first chose option 1 and then delete or search. Im having some trouble with the balancing function. It seems to be going into an infinite loop, i think im messing up with the pointers. Heres the code. //press 1, first, Do not press it a second time!!!
0
9035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8916
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8885
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.