Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

N-Ary tree lengths

800349Aug 9 2009 — edited Aug 9 2009
What is the best way of calculating the length of a specific node?

I'm working on code folding, and am storing each line of text as a node of a tree structure. When the user clicks on a line in the editor, I need to know which node is currently selected so I know what to edit.
I figured that if each node holds its own length(based on how many children and grand-children and so on it has) that I can find where the line of code is within the tree.

However I'm trying to find either the most efficient way of calculating this length, or another way altogether.

I was working on the length as 1(itself) plus each child, which they in turn calculate this. Which to m seems horrible in efficient if done for ever line select in the editor.
Any help?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 6 2009
Added on Aug 9 2009
9 comments
212 views