Changeset 16272 for trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
- Timestamp:
- 11/02/18 16:20:33 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r16267 r16272 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using System.Linq; 24 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 43 42 } 44 43 45 // compute node hashes without sorting the arguments46 public static Dictionary<ISymbolicExpressionTreeNode, ulong> ComputeNodeHashes(this ISymbolicExpressionTree tree) {47 var root = tree.Root.GetSubtree(0).GetSubtree(0);48 var nodes = root.MakeNodes();49 nodes.UpdateNodeSizes();50 51 for (int i = 0; i < nodes.Length; ++i) {52 if (nodes[i].IsLeaf)53 continue;54 nodes[i].CalculatedHashValue = nodes.ComputeHash(i);55 }56 return nodes.ToDictionary(x => x.Data, x => x.CalculatedHashValue);57 }58 59 44 public static ulong ComputeHash(this ISymbolicExpressionTreeNode treeNode) { 45 ulong hashFunction(byte[] input) => HashUtil.JSHash(input); 60 46 var hashNodes = treeNode.MakeNodes(); 61 var simplified = hashNodes.Simplify(); 62 //return ComputeHash(simplified); 47 var simplified = hashNodes.Simplify(hashFunction); 63 48 return simplified.Last().CalculatedHashValue; 64 49 } 65 66 //public static int ComputeHash(this HashNode<ISymbolicExpressionTreeNode>[] nodes) {67 // int hash = 1315423911;68 // foreach (var node in nodes)69 // hash ^= (hash << 5) + node.CalculatedHashValue + (hash >> 2);70 // return hash;71 //}72 50 73 51 public static HashNode<ISymbolicExpressionTreeNode> ToHashNode(this ISymbolicExpressionTreeNode node) { … … 152 130 // (in other words simplification should be applied in a bottom-up fashion) 153 131 public static ISymbolicExpressionTree Simplify(ISymbolicExpressionTree tree) { 132 ulong hashFunction(byte[] bytes) => HashUtil.JSHash(bytes); 154 133 var root = tree.Root.GetSubtree(0).GetSubtree(0); 155 134 var nodes = root.MakeNodes(); 156 var simplified = nodes.Simplify( );135 var simplified = nodes.Simplify(hashFunction); 157 136 return simplified.ToTree(); 158 137 }
Note: See TracChangeset
for help on using the changeset viewer.