N-Ary tree lengths
800349Aug 9 2009 — edited Aug 9 2009What 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?