Changeset 16252
- Timestamp:
- 10/24/18 10:45:47 (6 years ago)
- 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 91 91 92 92 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(); 95 94 96 95 for (int i = 0; i < reduced.Length; ++i) { … … 117 116 } 118 117 } 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 { 125 122 for (int i = 0; i < nodes.Length; ++i) { 126 123 var node = nodes[i]; … … 155 152 node.CalculatedHashValue = nodes.ComputeHash(i); 156 153 } 154 return nodes; 157 155 } 158 156 … … 160 158 /// Get a function node's child indices from left to right 161 159 /// </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> 165 163 /// <returns>An array containing child indices</returns> 166 164 public static int[] IterateChildren<T>(this HashNode<T>[] nodes, int i) where T : class { … … 177 175 } 178 176 179 public static voidUpdateNodeSizes<T>(this HashNode<T>[] nodes) where T : class {177 public static HashNode<T>[] UpdateNodeSizes<T>(this HashNode<T>[] nodes) where T : class { 180 178 for (int i = 0; i < nodes.Length; ++i) { 181 179 var node = nodes[i]; … … 189 187 } 190 188 } 189 return nodes; 191 190 } 192 191 … … 219 218 220 219 public static HashNode<T>[] Reduce<T>(this HashNode<T>[] nodes) where T : class { 221 nodes.UpdateNodeSizes();222 220 int i = nodes.Length - 1; 223 221 foreach (int c in nodes.IterateChildren(i)) { … … 237 235 if (node.Enabled) { reduced[i++] = node; } 238 236 } 239 reduced.UpdateNodeSizes(); 240 return reduced; 237 return reduced.UpdateNodeSizes(); 241 238 } 242 239 } -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r16218 r16252 22 22 } 23 23 24 // compute node hashes without sorting the arguments 24 25 public static Dictionary<ISymbolicExpressionTreeNode, int> ComputeNodeHashes(this ISymbolicExpressionTree tree) { 25 26 var root = tree.Root.GetSubtree(0).GetSubtree(0); … … 80 81 81 82 public static HashNode<ISymbolicExpressionTreeNode>[] MakeNodes(this ISymbolicExpressionTreeNode node) { 82 return node.IterateNodesPostfix().Select(ToHashNode).ToArray() ;83 return node.IterateNodesPostfix().Select(ToHashNode).ToArray().UpdateNodeSizes(); 83 84 } 84 85
Note: See TracChangeset
for help on using the changeset viewer.