Changeset 16261 for trunk/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 10/28/18 21:26:06 (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
r16260 r16261 82 82 var node = nodes[i]; 83 83 var hashes = new int[node.Arity + 1]; 84 int idx = 0; 85 foreach (int c in nodes.IterateChildren(i)) { 86 hashes[idx++] = nodes[c].CalculatedHashValue; 87 } 88 hashes[idx] = node.HashValue; 84 for (int j = i - 1, k = 0; k < node.Arity; j -= 1 + nodes[j].Size, k++) { 85 hashes[k] = nodes[j].CalculatedHashValue; 86 } 87 hashes[node.Arity] = node.HashValue; 89 88 return HashUtil.JSHash(hashes); 90 89 } … … 137 136 } else { // i have some non-terminal children 138 137 var sorted = new HashNode<T>[size]; 139 var indices = nodes.IterateChildren(i); 138 var indices = new int[node.Arity]; 139 for (int j = i - 1, k = 0; k < node.Arity; j -= 1 + nodes[j].Size, ++k) { 140 indices[k] = j; 141 } 140 142 Array.Sort(indices, sort); 141 143 … … 158 160 159 161 /// <summary> 160 /// Get a function node's child indices from left to right162 /// Get a function node's child indicest 161 163 /// </summary> 162 164 /// <typeparam name="T">The data type encapsulated by a hash node</typeparam> … … 184 186 } 185 187 node.Size = node.Arity; 186 foreach (int j in nodes.IterateChildren(i)) { 188 189 for (int j = i - 1, k = 0; k < node.Arity; j -= 1 + nodes[j].Size, ++k) { 187 190 node.Size += nodes[j].Size; 188 191 } … … 199 202 } 200 203 201 foreach (var j in nodes.IterateChildren(i)) { 204 var arity = node.Arity; 205 for (int j = i - 1, k = 0; k < arity; j -= 1 + nodes[j].Size, ++k) { 202 206 if (node.HashValue == nodes[j].HashValue) { 203 207 nodes[j].Enabled = false; -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/HashUtil.cs
r16218 r16261 90 90 91 91 public static byte[] ToByteArray(this int[] input) { 92 const int size = sizeof(int);93 92 var bytes = new byte[input.Length * sizeof(int)]; 94 for (int i = 0; i < input.Length; ++i) { 95 Array.Copy(BitConverter.GetBytes(bytes[i]), 0, bytes, i * size, size); 93 int pos = 0; 94 foreach (var v in input) { 95 var b0 = (byte)((v >> 24) & 0xFF); 96 var b1 = (byte)((v >> 16) & 0xFF); 97 var b2 = (byte)((v >> 8) & 0xFF); 98 var b3 = (byte)(v & 0xFF); 99 bytes[pos++] = b0; 100 bytes[pos++] = b1; 101 bytes[pos++] = b2; 102 bytes[pos++] = b3; 96 103 } 97 104 return bytes;
Note: See TracChangeset
for help on using the changeset viewer.