Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/13/10 20:30:30 (15 years ago)
Author:
gkronber
Message:

Minor efficiency improvements in tree iteration methods. #937

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs

    r3742 r3803  
    121121
    122122    public IEnumerable<SymbolicExpressionTreeNode> IterateNodesPrefix() {
    123       yield return this;
    124       if (SubTrees != null) {
    125         foreach (var subtree in SubTrees) {
    126           foreach (var n in subtree.IterateNodesPrefix())
    127             yield return n;
    128         }
    129       }
     123      return (new SymbolicExpressionTreeNode[] { this })
     124        .Concat(SubTrees.SelectMany(tree => tree.IterateNodesPrefix()));
    130125    }
    131126
    132127    public IEnumerable<SymbolicExpressionTreeNode> IterateNodesPostfix() {
    133       if (SubTrees != null) {
    134         foreach (var subtree in SubTrees) {
    135           foreach (var n in subtree.IterateNodesPrefix())
    136             yield return n;
    137         }
    138       }
    139       yield return this;
     128      return SubTrees.SelectMany(tree => tree.IterateNodesPrefix())
     129        .Concat(new SymbolicExpressionTreeNode[] { this });
    140130    }
    141131    public IEnumerable<Symbol> GetAllowedSymbols(int argumentIndex) {
Note: See TracChangeset for help on using the changeset viewer.