Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to save this tree like class / data structure?

Reply
Thread Tools

how to save this tree like class / data structure?

 
 
Kaidi
Guest
Posts: n/a
 
      07-01-2004
Hello all,
I have a class, which contains "pointers" so that it can construct a
tree like data structure (actually, I use it to store the tag tree I
built from a HTML file).

The problem is: how to save / load this class?

==== The class looks like: ==========

public class TagTreeNode implements Serializable {
//
private
String stringValue;
private
int nodeID;
private
int level;
private
String tagString;
private
TagTreeNode previousSibling;
private
TagTreeNode nextSibling;
private
TagTreeNode firstChild;
private
TagTreeNode parentNode;
//
// other functions etc.
}

========
Currently, I build a tree structure in which each node is of above
class.
I have the root node called rootNode.
And I try to save the whole tree using the following code:
==============
File thefile = new File(filename);
FileOutputStream fout = new FileOutputStream(thefile);
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(rootNode);
oos.close();
fout.close();
=======
This works fine for smaller trees. For biggers trees (actually, not so
big, only about 1000 - 2000 nodes in the tree, built from a HTML file
of 110K size), I always get the java.lang.StackOverflowError error.

PS: I have tried these: -Xss200M -Xmx200M -mx200M -Xms200M, seems no
use.

Any one can tell me either:
how to avoid the error?
or
how can I (in a good manner) save such a tree data structure onto file
? (and load it later)

Thanks a lot and have a great holiday!~
 
Reply With Quote
 
 
 
 
Elliott C. Bäck
Guest
Posts: n/a
 
      07-01-2004
> how can I (in a good manner) save such a tree data structure onto file
> ? (and load it later)


Try writing a method to traverse the tree that passes along your
fileOutputStream, and writes the data out as it goes, rather than traversing
the tree in its entirety, and then writing out the data.
--
Elliott C. Bäck


 
Reply With Quote
 
 
 
 
Kaidi
Guest
Posts: n/a
 
      07-01-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Kaidi) wrote in message news:<(E-Mail Removed). com>...
> Hello all,
> I have a class, which contains "pointers" so that it can construct a
> tree like data structure (actually, I use it to store the tag tree I
> built from a HTML file).
>
> The problem is: how to save / load this class?
>
> ==== The class looks like: ==========
>
> public class TagTreeNode implements Serializable {
> //
> private
> String stringValue;
> private
> int nodeID;
> private
> int level;
> private
> String tagString;
> private
> TagTreeNode previousSibling;
> private
> TagTreeNode nextSibling;
> private
> TagTreeNode firstChild;
> private
> TagTreeNode parentNode;
> //
> // other functions etc.
> }
>
> ========
> Currently, I build a tree structure in which each node is of above
> class.
> I have the root node called rootNode.
> And I try to save the whole tree using the following code:
> ==============
> File thefile = new File(filename);
> FileOutputStream fout = new FileOutputStream(thefile);
> ObjectOutputStream oos = new ObjectOutputStream(fout);
> oos.writeObject(rootNode);
> oos.close();
> fout.close();
> =======
> This works fine for smaller trees. For biggers trees (actually, not so
> big, only about 1000 - 2000 nodes in the tree, built from a HTML file
> of 110K size), I always get the java.lang.StackOverflowError error.
>
> PS: I have tried these: -Xss200M -Xmx200M -mx200M -Xms200M, seems no
> use.
>
> Any one can tell me either:
> how to avoid the error?
> or
> how can I (in a good manner) save such a tree data structure onto file
> ? (and load it later)
>
> Thanks a lot and have a great holiday!~


PS: Surely I can "walk" through the tree, write out each node. But I
just wonder any better way to save it?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi, I want to implement a General Tree Data structure (Not Binary Tree ) which have more than 2 sub nodes? sharan C Programming 2 10-31-2007 02:58 AM
Hi, I want to implement a General Tree Data structure (Not Binary Tree ) which have more than 2 sub nodes? sharan C Programming 1 10-30-2007 11:01 PM
Hi, I want to implement a General Tree Data structure (Not Binary Tree ) which have more than 2 sub nodes? sharan C Programming 4 10-30-2007 08:21 PM
Parse tree like data like XML by Perl? Davy Perl Misc 2 10-09-2006 04:30 AM
B tree, B+ tree and B* tree Stub C Programming 3 11-12-2003 01:51 PM



Advertisments