473,698 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

data structure

Hello again.

I have a task i need to do and i can't seem to find an elegent
solution.
i need to make a tree like data structure (not necessry a binary tree).
i would like each node to access his sons in a dicionary kind of why,
for example: if ROOT node has the name 'A' and 'AA', 'AB' are his
sons, and 'ABA' is 'AB son etc' (in this name scheme the letters from
left to right shows the route from the root to the node) then
ROOT['AB'] will point to 'AB' node and ROOT['AB'][ABA'] will point to
'ABA' node.

the tree does not have to be symmarical and every node link to
different number of nodes. two nodes can have the same name if they are
in a different location in the tree. so ROOT['factory1]['manager'] and
ROOT['factory2']['manager'] can be in the same tree and point to
different objects.

all up to now i can manage.
---------------------
my problem is this: i would like to find a way to easly construct the
tree by giving some simple template, somthing similer to:
"
ROOT={'factory1 ':FACTORY,'faco ry2':FACTORY,'l inux':OS,'windo ws':OS}
FACTORY={'manag er':EMPLOEY,'wo rker':EMPLOEY,' office':BUILDIN G,'......}
OS={'ver':VERSI ON,'problems':L IST,....}
"
i started bulding the class NODE as an extention of "dict" with the
keys are the childern names and the items are the next node reference.
the proablem was that as you can see from the above example 'factory1'
and 'factory2' point to the same object. i would like to have 2
different objects of FACTORY. making FACTORY a template and not an
object.

i'll appreciate any comment
amit

Sep 3 '06 #1
1 1420
noro wrote:
Hello again.

I have a task i need to do and i can't seem to find an elegent
solution.
i need to make a tree like data structure (not necessry a binary tree).
i would like each node to access his sons in a dicionary kind of why,
for example: if ROOT node has the name 'A' and 'AA', 'AB' are his
sons, and 'ABA' is 'AB son etc' (in this name scheme the letters from
left to right shows the route from the root to the node) then
ROOT['AB'] will point to 'AB' node and ROOT['AB'][ABA'] will point to
'ABA' node.

the tree does not have to be symmarical and every node link to
different number of nodes. two nodes can have the same name if they are
in a different location in the tree. so ROOT['factory1]['manager'] and
ROOT['factory2']['manager'] can be in the same tree and point to
different objects.

all up to now i can manage.
---------------------
my problem is this: i would like to find a way to easly construct the
tree by giving some simple template, somthing similer to:
"
ROOT={'factory1 ':FACTORY,'faco ry2':FACTORY,'l inux':OS,'windo ws':OS}
FACTORY={'manag er':EMPLOEY,'wo rker':EMPLOEY,' office':BUILDIN G,'......}
OS={'ver':VERSI ON,'problems':L IST,....}
"
i started bulding the class NODE as an extention of "dict" with the
keys are the childern names and the items are the next node reference.
the proablem was that as you can see from the above example 'factory1'
and 'factory2' point to the same object. i would like to have 2
different objects of FACTORY. making FACTORY a template and not an
object.

i'll appreciate any comment
amit
You can make a shallow copy of a dictionary using the dictionary's copy
method. To make a completely new copy, use the deepcopy function in
the copy module. Please see the copy module's documentation on the
limits and differences between deep copies and shallow copies.
(http://docs.python.org/lib/module-copy.html)

--Jason

Sep 3 '06 #2

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

Similar topics

1
2105
by: dmb000006 | last post by:
Hello, I have a database style data structure, each record has several fields. I would like to create a nested data structure that would let me 'query' the data on the value of certain fields. I did this by making the following type of data...
3
2373
by: Mike Jones | last post by:
need help with data structures.Looking for ways to start, sample code, anything Program description: Design and implement a Visual C++ .NET program that inserts values into a data structure and then removes them as described below.
2
6456
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_ { char szInput; char szOutput; int iSum;
11
3181
by: theshowmecanuck | last post by:
As a matter of academic interest only, is there a way to programmatically list the 'c' data types? I am not looking for detail, just if it is possible, and what function could be used to accomplish it. For example: int main void() { while there are more data types { print next data type; }
5
4790
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e. "payload") using pointers. Examples of these are binary trees, hash tables etc. Thus, the message itself contains only a pointer to the actual data. When the message is sent to the same processor, these pointers point to the original locations, which...
3
8899
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String End Structure
11
4127
by: Macca | last post by:
Hi, I'm writing an application that will pass a large amount of data between classes/functions. In C++ it was more efficient to send a pointer to the object, e.g structure rather than passing the actual structure itself. Is this true of C# also?
3
2163
by: aurora | last post by:
This is an entry I just added to ASPN. It is a somewhat novel technique I have employed quite successfully in my code. I repost it here for more explosure and discussions. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475158 wy ------------------------------------------------------------------------
29
4253
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
30
3393
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and commits it. How does the other user get the updated view without polling for changes? Is there some sort of callback mechanism that can be set up on the dataset or connection? TIA
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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
8904
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
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
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();...
1
3052
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
3
2007
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.