Recursion schmecursion!
-
I found a novel (or at least weird and wonderful) way to avoid recursion when traversing the nodes in a TreeView. :jig: Here's a teaser:
System.Windows.Forms.TreeNode nod = this.tvMain.SelectedNode as System.Windows.Forms.TreeNode ;
System.Collections.Generic.Stack<System.Collections.IEnumerator> sub =
new System.Collections.Generic.Stack<System.Collections.IEnumerator>() ;sub.Push ( nod.Nodes.GetEnumerator() ) ;
Stay tuned for an article. :badger:
-
I found a novel (or at least weird and wonderful) way to avoid recursion when traversing the nodes in a TreeView. :jig: Here's a teaser:
System.Windows.Forms.TreeNode nod = this.tvMain.SelectedNode as System.Windows.Forms.TreeNode ;
System.Collections.Generic.Stack<System.Collections.IEnumerator> sub =
new System.Collections.Generic.Stack<System.Collections.IEnumerator>() ;sub.Push ( nod.Nodes.GetEnumerator() ) ;
Stay tuned for an article. :badger:
I see where this is coming! One can say it's inspired by the way way assembly works! :P But the important question: does it blend? Err... I mean.. is it fast?
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
I found a novel (or at least weird and wonderful) way to avoid recursion when traversing the nodes in a TreeView. :jig: Here's a teaser:
System.Windows.Forms.TreeNode nod = this.tvMain.SelectedNode as System.Windows.Forms.TreeNode ;
System.Collections.Generic.Stack<System.Collections.IEnumerator> sub =
new System.Collections.Generic.Stack<System.Collections.IEnumerator>() ;sub.Push ( nod.Nodes.GetEnumerator() ) ;
Stay tuned for an article. :badger:
Is it anything like this extension method[^]?
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
-
Is it anything like this extension method[^]?
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
Only in how it works; not in what it does. I don't think that will work with TreeNodes because TreeNodes are not themselves IEnumerable and the Nodes property is a non-generic IEnumerable. I can't even add that
finally
because IEnumerator (the non-generic one) is not IDisposable. The Nodes Property also has the benefit of never being null, and the TreeNodeCollection has a Count Property. What I'm doing also needs to know the stack depth for each Node. There are other things that are unique to what I'm doing that a general method like that is unlikely to support. And mine uses only onewhile
loop and one Peek. Why are they so wasteful? :-D And, yes, I made an Extension Method for TreeNodes -- it's an alternative toToString()
. Thanks for showing me that. :thumbsup: Interesting to see that I'm not the only one to think of this technique. Hey, that one doesn'tyield
the root object? I think it needs work. -
Only in how it works; not in what it does. I don't think that will work with TreeNodes because TreeNodes are not themselves IEnumerable and the Nodes property is a non-generic IEnumerable. I can't even add that
finally
because IEnumerator (the non-generic one) is not IDisposable. The Nodes Property also has the benefit of never being null, and the TreeNodeCollection has a Count Property. What I'm doing also needs to know the stack depth for each Node. There are other things that are unique to what I'm doing that a general method like that is unlikely to support. And mine uses only onewhile
loop and one Peek. Why are they so wasteful? :-D And, yes, I made an Extension Method for TreeNodes -- it's an alternative toToString()
. Thanks for showing me that. :thumbsup: Interesting to see that I'm not the only one to think of this technique. Hey, that one doesn'tyield
the root object? I think it needs work.A quick manual trace and it adds the root IEnumerator and then enumerates it, yielding the objects. Then is goes on to get more enumerators. It is used here[^] to flatten a directory tree to a list of files and folders.
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
-
A quick manual trace and it adds the root IEnumerator and then enumerates it, yielding the objects. Then is goes on to get more enumerators. It is used here[^] to flatten a directory tree to a list of files and folders.
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
Yes, the enumerator of the root, but not the root itself.
-
I found a novel (or at least weird and wonderful) way to avoid recursion when traversing the nodes in a TreeView. :jig: Here's a teaser:
System.Windows.Forms.TreeNode nod = this.tvMain.SelectedNode as System.Windows.Forms.TreeNode ;
System.Collections.Generic.Stack<System.Collections.IEnumerator> sub =
new System.Collections.Generic.Stack<System.Collections.IEnumerator>() ;sub.Push ( nod.Nodes.GetEnumerator() ) ;
Stay tuned for an article. :badger:
PIEBALDconsult wrote:
System.Windows.Forms.TreeNode nod = this.tvMain.SelectedNode as System.Windows.Forms.TreeNode ;
Why do you complain? That cast is really safe, isn't it? :-D And I am
nod
ding my head for his great capabilities in naming of variables. -
PIEBALDconsult wrote:
System.Windows.Forms.TreeNode nod = this.tvMain.SelectedNode as System.Windows.Forms.TreeNode ;
Why do you complain? That cast is really safe, isn't it? :-D And I am
nod
ding my head for his great capabilities in naming of variables.Yes, that cast is very safe. However, originally I was casting to a custom derived TreeNode type, I could probably remove it now.