how to save this tree like class / data structure?

Discussion in 'Java' started by Kaidi, Jul 1, 2004.

  1. Kaidi

    Kaidi Guest

    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!~
     
    Kaidi, Jul 1, 2004
    #1
    1. Advertising

  2. > 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
     
    Elliott C. Bäck, Jul 1, 2004
    #2
    1. Advertising

  3. Kaidi

    Kaidi Guest

    (Kaidi) wrote in message news:<>...
    > 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?
     
    Kaidi, Jul 1, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. fishfry

    Tree-like data structure?

    fishfry, Mar 1, 2004, in forum: Java
    Replies:
    4
    Views:
    11,750
  2. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,126
  3. sharan
    Replies:
    4
    Views:
    690
    CBFalconer
    Oct 30, 2007
  4. sharan
    Replies:
    2
    Views:
    833
    SM Ryan
    Oct 31, 2007
  5. sharan
    Replies:
    1
    Views:
    691
    CBFalconer
    Oct 30, 2007
Loading...

Share This Page