473,756 Members | 7,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nodes with unlimited children.

Hi All,

I plan on using the following C++ code
to create nodes with unlimited children:

// I would like to declare NodeT like this,
// but it won't compile because Lnk_T is not defined yet.

struct NodeT { Lnk_T Lnk ; };

So I have to declare NodeT like this instead:

struct NodeT {
struct { NodeT * * B, * * E, * * Room ; } Lnk ; };
typedef NodeT * Link ;

typedef Link * Link_P ;

// B is the Beginning of an array of pointers.
// E is the End of an array of pointers that are in use.
// Room the end of an array of all pointers, used or not.

struct Lnk_T { Link_P B, E, Room ; };

Lnk_T Lnk ;

enum { Chunk = 4,
Sz_Ptr = sizeof Link, Sz_Node = sizeof NodeT };

GrowList ( Lnk_T & Lnk ) {
if ( Lnk.E + 1 < Lnk.Room ) return;
int Room = Lnk.Room - Lnk.B + Chunk, E = Lnk.E - Lnk.B ;
Lnk.B = ( Link_P ) realloc( Lnk.B, Room * Sz_Ptr );
Lnk.Room = Lnk.B + Room ; Lnk.E = Lnk.B + E ;
memset( Lnk.E, 0, ( Lnk.Room - Lnk.E ) * Sz_Ptr ); }
// Below is an example of is how the above might be used,
// I know that it works.

__stdcall WinMain( HINSTANCE, HINSTANCE, LPSTR, int ) {

GrowList ( Lnk ); // Lnk is a global, so it's initialized.

Link & P = * Lnk.E ++ ;

P = ( Link ) realloc( P, Sz_Node );

memset ( P, 0, Sz_Node );

GrowList ( ( Lnk_T & ) P->Lnk );

{ Link Passed = P, & P = * Passed->Lnk.E ++ ;

P = ( Link ) realloc( P, Sz_Node );

memset ( P, 0, Sz_Node );

GrowList ( ( Lnk_T & ) P->Lnk );

// etc.
}

But is there any way to declare NodeT so that
I don't have to use that ( Lnk_T & ) cast ?
Jul 22 '05
47 2698
In comp.os.linux.a dvocacy, Jeff Relf
<Jeff_Relf_@_NC Plus.NET.Invali d>
wrote
on 3 Aug 2004 10:22:39 GMT
<_J************ ************@NC Plus.NET>:
Hi Karl Heinz Buchegger,

Re: The Ghost In The Machine and me,

You wrote: <<
_______________ ______
/| /| | |
||__|| | Please do not |
/ O O\__ | feed the |
/ \ | Trolls |
/ \ \|_____________ ________|
/ _ \ \ ||
/ |\____\ \ ||
/ | | | |\____/ ||
/ \|_|_|/ | _||
/ / \ |____| ||
/ | | | --|
| | | |____ --|
* _ | |_|_|_| | \-/
*-- _--\ _ \ | ||
/ _ \\ | / `
* / \_ /- | | |
* ___ c_c_c_C/ \C_c_c_c_______ _____

At least we're talking abut C++, doesn't that count ?

I don't think the Ghost is a troll,
I just think he has a different point of view from me.


Very different. :-)

A lot of people have scored me down too,
but that's fine with me...

I'm not entering anyone's popularity contest.

It's even possible that
The Ghost and I could come to a understanding.
I understand you well enough. Admittedly, there are
those out there who think nothing of putting
no comments at all into swamp muck, codeswill, or
execrable crap, then using it as the documentation
basis for whatever the tool is supposed to do.

(The computer has no problem understanding Obfuscated C.
But mere mortals have to take it apart. Code should
be understandable to both man and machine -- ideally.)

Of course part of my position is self-defense. I write
something, come back to it later, and wonder why the
hell I wrote it that particular way. It behooves me
to be able to read my own code -- and presumably that
means others can at least have a chance of decoding
what I scribbled into the computer at some point.

ObLinux: I can get the source code. That is a plus in itself.

There's so much miscommunicatio n on Usenet...

Why not try to resolve some of it ?

--
#191, ew****@earthlin k.net
It's still legal to go .sigless.
Jul 22 '05 #41
Hi The Ghost In The Machine,

Oops, I showed: <<
FuBar () { int X = -1, Y = -1 ;

Loop ( 6 ) { ++ X ; Loop ( 7 ) ++ Y ; }

// Prints: 5 and 6

printf ( " %d and %d ", X, Y ); }


And you correctly corrected me: <<
The results I get are 5 and 41, before and after conversion.
This is regardless of whether I use 'i' or 'j'
as the inner variable, which shadows the outer one. >>

I meant to write this:

FuBar () { int X = -1, Y = -1 ;

{ Loop ( 6 ) ++ X ; } Loop ( 7 ) ++ Y ;

// Prints: 5 and 6

printf ( " %d and %d ", X, Y ); }
I say that this: { Loop ( 6 ) ++ X ; } Loop ( 7 ) ++ Y ;
is more readable than this:

for(int i = 0; i < 6; i++)
{
x++;
for(int j = 0; j < 7; j++)
y++;
}

You commented: " I'm surprised you can read that gunk. "

That only goes to show that
one man's meat is another man's poison.

I'm into targeting Win XP for personal use,
( I put the personal in personal computer )...

and you're into targeting servers in a large corporation...

As the saying goes:

I'm ok, you're ok,
and Microsoft should give us a 75 billion dollar rebate.
Jul 22 '05 #42
Hi The Ghost In The Machine,

You showed: <<
it = std::binary_sea rch(
collection.begi n(), collection.end( ), "constant") ;

Yea, my original plan was to :

A. qsort() the unthread list of Usenet messages ( Flat ).
( Flat contains one huge array of pointers to nodes,
as described here
news:_J******** *************** *@NCPlus.NET )

B. Then do a binary search on it.

But then I ran the code... No need for the binary search.

It's already instant,

even with a list of two thousand messages.
( Even more so when compared to how long it takes me
to download those messages using a spotty dial-up service )

In fact, it's much much Much faster than 40Tude Dialog,
the newsreader that I was using before I wrote X.
( Actually, I'm still using Dialog for some things,
because X is still so primitive )

Re: Your code:
typedef std::string itemtype; // or whatever you want
typedef std::xxx<itemty pe> collectiontype;
// xxx = set, vector, or list
collectiontype collection;
collectiontype: :const_iterator it;

You said: " ...it should be fairly clear what I'm doing. "

Yes, it is quite clear ( and quite interesting too ).

You showed: <<
Now, after one's assigned a value to 'it',
one can then test 'it':

if ( it != collection.end( ) ) /* found it */


Of course, I do that all the time...

Only I say this: if ( J < LLL ) // found, i.e. broke out.

after: Loop( 5 ) if ( Eq( "Hello", Line_Array[ J ] ) ) break;

where: #define Eq ! strcmp

#define Loop( N ) int J = -1, LLL = N ; while ( ++ J < LLL )

The main difference is that I'm using J, not " it ",
and LLL, not collection.end( ) .

Re: collection.eras e( it );

With my dynamic arrays of pointers to children and/or lines,
( Using B, P, E, and Inc() described recently:
_J************* ***********@NCP lus.NET )...

...I just free one or more pointers and then
use memmove to overwrite them, the I adjust P,
e.g. -- Ln.P, or -- Forest.P .
( I would show you exactly how I do that,
but it's past 6 am now,
and I usually go to bed at 3 am,
and I have to be on campus by 10 am... uuugh ! )

You wrote: <<
Dereferencing a non-end pointer ( '*it' )
will get the item back. >>

Yea, that's similar to my code here:
LoopC ( & Flat )
if ( Eq ( Par, ( * Arr )->Ln [ _MID ] ) ) break ;
You showed:
collection.eras e( collection.begi n(), collection.end( ) );
saying: << If one wants an explicit forest of items
some work will be required to encapsulate them properly. >>

Right, the STL has no " Forest " type,
especially not one with unlimited children...

So your code above wouldn't work...
forests have to be recursively deleted/printed.

You said: " Enjoy your swamp muck... ".

Oh, of that you can be Quite sure...

I'm loving every minute of it.

But I've got to go now...
Jul 22 '05 #43
In message <sr************ *****@newssvr15 .news.prodigy.c om>, Phlip
<ph*******@yaho o.com> writes
Jeff Relf wrote:
Hi Kelsey Bjarnason,

Re:
#define Loop( N ) int J = -1, LLL = N ; while ( ++ J < LLL )

You commented: << Marvellous; symbol clashes,
just because you use this macro twice in the same scope.
Talk about badly-written. >>

You're worried about compilation errors ?

Real programmers are Never concerned about that.


Real programmers don't piss their colleagues off. They write clear, simple,
robust, and easily-changed code. This helps keep their colleagues in the ...
loop.


They don't change the subject line with every reply, either.

--
Richard Herring
Jul 22 '05 #44
In comp.os.linux.a dvocacy, Jeff Relf
<Jeff_Relf_@_NC Plus.NET.Invali d>
wrote
on 4 Aug 2004 13:26:28 GMT
<_J************ ************@NC Plus.NET>:
Hi The Ghost In The Machine,

You showed: <<
it = std::binary_sea rch(
collection.begi n(), collection.end( ), "constant") ;

Yea, my original plan was to :

A. qsort() the unthread list of Usenet messages ( Flat ).
( Flat contains one huge array of pointers to nodes,
as described here
news:_J******** *************** *@NCPlus.NET )

B. Then do a binary search on it.

But then I ran the code... No need for the binary search.

It's already instant,

even with a list of two thousand messages.
( Even more so when compared to how long it takes me
to download those messages using a spotty dial-up service )

In fact, it's much much Much faster than 40Tude Dialog,
the newsreader that I was using before I wrote X.
( Actually, I'm still using Dialog for some things,
because X is still so primitive )

Re: Your code:
typedef std::string itemtype; // or whatever you want
typedef std::xxx<itemty pe> collectiontype;
// xxx = set, vector, or list
collectiontype collection;
collectiontype: :const_iterator it;

You said: " ...it should be fairly clear what I'm doing. "

Yes, it is quite clear ( and quite interesting too ).

You showed: <<
Now, after one's assigned a value to 'it',
one can then test 'it':

if ( it != collection.end( ) ) /* found it */

Of course, I do that all the time...

Only I say this: if ( J < LLL ) // found, i.e. broke out.

after: Loop( 5 ) if ( Eq( "Hello", Line_Array[ J ] ) ) break;

where: #define Eq ! strcmp


*hack* *cough*

Try

if(Eq(1, 2))

and see how far you get. I'll be standing way over here...

#define Loop( N ) int J = -1, LLL = N ; while ( ++ J < LLL )

The main difference is that I'm using J, not " it ",
and LLL, not collection.end( ) .
Right. Now replace your list with a red-black tree.

Re: collection.eras e( it );

With my dynamic arrays of pointers to children and/or lines,
( Using B, P, E, and Inc() described recently:
_J************* ***********@NCP lus.NET )...

...I just free one or more pointers and then
use memmove to overwrite them, the I adjust P,
e.g. -- Ln.P, or -- Forest.P .
( I would show you exactly how I do that,
but it's past 6 am now,
and I usually go to bed at 3 am,
and I have to be on campus by 10 am... uuugh ! )

You wrote: <<
Dereferencing a non-end pointer ( '*it' )
will get the item back. >>

Yea, that's similar to my code here:
LoopC ( & Flat )
if ( Eq ( Par, ( * Arr )->Ln [ _MID ] ) ) break ;
You showed:
collection.eras e( collection.begi n(), collection.end( ) );
saying: << If one wants an explicit forest of items
some work will be required to encapsulate them properly. >>

Right, the STL has no " Forest " type,
especially not one with unlimited children...
Don't be so sure. In fact, std::set<> and std::map<>
use a red-black tree.

You're right in that STL has no "Forest" type. I'm not sure
how much of a limitation that is.

So your code above wouldn't work...
forests have to be recursively deleted/printed.

You said: " Enjoy your swamp muck... ".

Oh, of that you can be Quite sure...

I'm loving every minute of it.

But I've got to go now...



--
#191, ew****@earthlin k.net
It's still legal to go .sigless.
Jul 22 '05 #45
Hi Kelsey Bjarnason,

In news:_J******** *************** *@NCPlus.NET ,
I said to The Ghost: <<
...you and Kelsey Bjarnason were talking about
how much you dislike my AllocN() macro... >>

And you, not remembering what you last wrote, said: <<
Never mentioned it, AFAIK;
although I did make a mention or two about your
Loop and loop macros and your Zero macro. >>

To refresh your memory, see:
news:pa******** *************** *****@xxnospamy y.lightspeed.bc .ca
( Shit, what a verbose Message-ID )

You quoted AllocN() and then commented: <<
Good god. If you're going to do that much work,
use a frippin' function, not a macro. >>

And I said that it was so I could do: { ... continue; }
thus creating fewer ( ugly ) braces in my code.

At any rate, I'm very glad you quoted AllocN(),
as that gave me an excuse to update it...
and to explain to you and the Ghost
how it creates a forest of bushy trees
( i.e. where the number of direct-children per node
is not limited ).

Re: memmove( Dest = malloc( Sz ), Source, Size )

You commented: << If malloc fails, you're hooped. >>

That wasn't my concern ( of course ),
I noticed that that code didn't work in certain places...

So I had to separate out the two calls, like this:
Dest = malloc( Sz ); memmove( Dest , Source, Size )

As I said... I have no idea why.

You quoted: P = ( Lnk_T ) malloc( sizeof NodeT );

And commented: << Okay, look, if you're coding in C,
lose the cast; it is extremely bad practice and hides bugs.
If you're coding in C++,
why are you using malloc at all, when there's new ? >>

I'm obviously coding in C++ ( only without the STL ),

You should've known that by all the binding I was doing,
eg: Line & Inc ( Ln_T & Ln );

So either you don't know C or you aren't reading my code...
Probably both. ( No big deal )

You asked why I use realloc() when there's new...

Compare new and realloc()... ( I'll wait )

Which is better ? ( No cheating )
Jul 22 '05 #46
Richard Herring,

Re: How I use appropriate titles, in compliance with RFC 1036.

RFC documents employ exact definitions of
these two all-uppercase words: SHOULD and MUST.

Because the title of a message SHOULD describe the message,
RFC 1036 says that when the topic changes:

A. One SHOULD Not use "Re: " at the start of a title.

B. One SHOULD Not delete the References line.

From http://www.usenet-fr.net/fr-chartes/...rfc1036.2.html
<< If the poster determines that
the topic of the followup differs significantly
from what is described in the subject,
a new, more descriptive, subject SHOULD be substituted
( With No Back Reference ). >>
^^^^ ^^ ^^^^ ^^^^^^^^^

The term, " back reference " here is defined as
the " Re: " tag at the start of a title,
( Not the References: line in the headers ).

Google violates RFC 1036 by mandating something more like this:

Because the title of a message MUST define the thread,
One MUST use "Re: " at the start of a title...
Otherwise we MUST delete the References line.

If you were to not side with Google's violation of RFC 1036...

You could " Sort by Thread " ( i.e. the references line ),
( rather than by titles ).

You also might consider unchecking the box that says:
" Start a new thread when the title changes ".

If you simply don't like RFC 1036,
and you choose to violate it...

Please don't complain to me
about the problems it is causing _ You _ .
Jul 22 '05 #47
On 31 Jul 2004 08:32:10 GMT, Jeff Relf
<Jeff_Relf_@_NC Plus.NET.Invali d> wrote:
You will never ever catch me telling someone that
his code is hard to maintain ( at least if I'm honest ).
You haven't been around much, have you.
I might well refuse to maintain someone's old code,
as I always prefer total rewrites.
You obviously have never spent a single minute in a commercial
software company, have you. Total rewrites... bwhaahaaaa.
I actually own a 450 dollar copy of MS Fortran for Win98.
( From when I converted some Fortran code to C )
But I never used it, thank God... I refused to.
So you converted from a language you never read about... okay, there's
a clue.
So I know what Fortran code ( and Fortran programmers )
look like ( with their big iron, IBM, and all that ).
But you said you never looked at the book?
I've seen those huge hard disk platters.
Did this excite you in some way?
Hmm... Where they the forerunner to floppies ?
( Not counting tape, of course )


"Never try to teach a pig to sing, it wastes time and annoys the pig."

Jul 22 '05 #48

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

Similar topics

0
2784
by: Dinesh | last post by:
Hi, I have two tables 'master' and 'child', the master is the master table for all nodes in all trees. To get children of any node, we need to go to the 'child' table to get the nodeid of the children. The master has about 40,000 such trees with about 400 nodes in each tree. The input to me is the 'Root Node'/'First Node' of a tree. I need to traverse thru all the child nodes starting from 'Root Node' ( and process it ) and then...
8
1546
by: Xamle Eng | last post by:
One of the things I find most unnatural about most XML APIs is that they try to abstract both elements and text into some kind of "node" object when they have virtually nothing in common. The reason these APIs do it is to make it possible for both text and elements to be children of elements. But there is another way. The XPath/XQuery data model does not allow two consecutive text nodes. As far as I can tell, most XML processing...
12
1838
by: Ole Noerskov | last post by:
The function below is supposed to remove all childnodes with a name that starts with "keywords" in "myform" in the window.opener. It works fine if there's one keyword node. But you have to run the function several times if there are many keyword nodes. Why? function removeKeywords() { var form_obj = window.opener.document.getElementById('myform');
19
6785
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has one, and only one parent. The depth should not exceed 6 or 7 levels. The initial import will have about 6 million leaves, and 3 million branches. I would expect the leaves to grow significantly, in number easily tripling. However, the branches will...
6
3520
by: Nikhil Patel | last post by:
Hi all, Following is a portion of an XML document. I need to remove all nodes that belong to ns0 without deleting their child nodes. So in the following example , I want to delete "ns0:Proposal" and "ns0:Company" but I do not want to delete their child nodes("w:p","w:r","w:t"). How can I do this? <ns0:Proposal> <ns0:Company> <w:p> <w:r>
4
12841
by: J.B. | last post by:
Hi Can anybody show me how to loop all treeview nodes ini vb.net. I've been working on this for days but still no result. I got a sample code in vb 6.0, this one works. Private Sub SaveNested( Dim TNode As Node Set TNode = TreeView1.Nodes(1).Roo While Not TNode Is Nothin
2
2260
by: Kristopher Wragg | last post by:
I'm having some serious problems with the TreeView control. I've got a control that inherits TreeView and has some methods that firstly create a TreeNode then does some recursive procedure to add all the children from a database of a sort. Then once this is complete I clear the nodes, then add the TreeNode so it should be the only root node. The only problem is that for some very VERY strange reason there are two root nodes, with...
4
3027
by: reflex | last post by:
I have to get every node within range or selection? Is it possible? Sry for my engrish :] Ref
1
1804
by: Sasi Kumar | last post by:
I have a xml file. I want to display the nodes and childnodes in my datagrid, i used xmldatasource, but i can read a specific path only. The problem is i should not use dataset and xmldocument. Give me some suggestions <?xml version="1.0" encoding="utf-8"?> <newbookingrs> <bookingid>187250</bookingid> <bookingstatus>We have received your request. As you did not submit the required payment details, no booking will be held for you. If...
0
9456
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
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9713
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
8713
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...
0
6534
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
5142
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...
1
3806
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
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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.