Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Parsing a  TreeModel structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing a  TreeModel structure" Watch "Parsing a  TreeModel structure" New topic
Author

Parsing a TreeModel structure

Trevor Price
Greenhorn

Joined: May 19, 2006
Posts: 16
Say I have a very large tree structure (7000+ nodes) and I need to parse it. What's the fastest way to accomplish this? I've been toying with the code below, but it's just too slow.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I'm going to assume that "fastest" refers to how fast you can get the code written:I'm just guessing at what "parse" means in this context, by the way. I'm guessing it means you want to list out all of the nodes in some order. There are several other enumerations you can choose from if you don't like post order.
Trevor Price
Greenhorn

Joined: May 19, 2006
Posts: 16
Sorry, should have been more clear. By "fast", I mean "optimized", i.e., parsing 7000 nodes is hitting my server hard for about 6 seconds. Ultimately, I'm going to need to be able to manipulate the data in multiple ways. Maybe Enumeration isn't the most optimized code for this.

For example:

-----OR-----
Jaap Vermeer
Greenhorn

Joined: Apr 04, 2006
Posts: 16
Well... Paul Clapham's code is definitely the way to go if you want any sort of maintainability. Then to make it faster, you'll have to profile the code and see what it is doing in thos 6 seconds.
Although 1000 iterations a second does not sound absurd, you might be able to make it faster.

The direction you are going, given your example, sounds bad. The order in which the nodes are processed will (likely) not have a major effect on performance, you still need to go through 7000 nodes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing a TreeModel structure
 
Similar Threads
JTable Horizontal Scrolling Probs
Timing complexity of this string reverse
poll(),peek() in PriorityQueue class
Print contents of PriorityQueue not working
Converting Number to Word