Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16252


Ignore:
Timestamp:
10/24/18 10:45:47 (6 years ago)
Author:
bburlacu
Message:

#2950: Minor refactor of HashExtensions.cs to allow method chaining. Minor refactor in SymbolicExpressionTreeHash.cs.

Location:
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/HashExtensions.cs

    r16218 r16252  
    9191
    9292    public static HashNode<T>[] Simplify<T>(this HashNode<T>[] nodes) where T : class {
    93       var reduced = nodes.Reduce();
    94       reduced.Sort();
     93      var reduced = nodes.UpdateNodeSizes().Reduce().Sort();
    9594
    9695      for (int i = 0; i < reduced.Length; ++i) {
     
    117116        }
    118117      }
    119       simplified.UpdateNodeSizes();
    120       simplified.Sort();
    121       return simplified;
    122     }
    123 
    124     public static void Sort<T>(this HashNode<T>[] nodes) where T : class {
     118      return simplified.UpdateNodeSizes().Sort();
     119    }
     120
     121    public static HashNode<T>[] Sort<T>(this HashNode<T>[] nodes) where T : class {
    125122      for (int i = 0; i < nodes.Length; ++i) {
    126123        var node = nodes[i];
     
    155152        node.CalculatedHashValue = nodes.ComputeHash(i);
    156153      }
     154      return nodes;
    157155    }
    158156
     
    160158    /// Get a function node's child indices from left to right
    161159    /// </summary>
    162     /// <typeparam name="T"></typeparam>
    163     /// <param name="nodes"></param>
    164     /// <param name="i"></param>
     160    /// <typeparam name="T">The data type encapsulated by a hash node</typeparam>
     161    /// <param name="nodes">An array of hash nodes with up-to-date node sizes</param>
     162    /// <param name="i">The index in the array of hash nodes of the node whose children we want to iterate</param>
    165163    /// <returns>An array containing child indices</returns>
    166164    public static int[] IterateChildren<T>(this HashNode<T>[] nodes, int i) where T : class {
     
    177175    }
    178176
    179     public static void UpdateNodeSizes<T>(this HashNode<T>[] nodes) where T : class {
     177    public static HashNode<T>[] UpdateNodeSizes<T>(this HashNode<T>[] nodes) where T : class {
    180178      for (int i = 0; i < nodes.Length; ++i) {
    181179        var node = nodes[i];
     
    189187        }
    190188      }
     189      return nodes;
    191190    }
    192191
     
    219218
    220219    public static HashNode<T>[] Reduce<T>(this HashNode<T>[] nodes) where T : class {
    221       nodes.UpdateNodeSizes();
    222220      int i = nodes.Length - 1;
    223221      foreach (int c in nodes.IterateChildren(i)) {
     
    237235        if (node.Enabled) { reduced[i++] = node; }
    238236      }
    239       reduced.UpdateNodeSizes();
    240       return reduced;
     237      return reduced.UpdateNodeSizes();
    241238    }
    242239  }
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs

    r16218 r16252  
    2222    }
    2323
     24    // compute node hashes without sorting the arguments
    2425    public static Dictionary<ISymbolicExpressionTreeNode, int> ComputeNodeHashes(this ISymbolicExpressionTree tree) {
    2526      var root = tree.Root.GetSubtree(0).GetSubtree(0);
     
    8081
    8182    public static HashNode<ISymbolicExpressionTreeNode>[] MakeNodes(this ISymbolicExpressionTreeNode node) {
    82       return node.IterateNodesPostfix().Select(ToHashNode).ToArray();
     83      return node.IterateNodesPostfix().Select(ToHashNode).ToArray().UpdateNodeSizes();
    8384    }
    8485
Note: See TracChangeset for help on using the changeset viewer.