- 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/HashUtil.cs
r16263 r16272 21 21 22 22 23 using System; 24 using System.Security.Cryptography; 25 23 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 24 27 public static class HashUtil { … … 26 29 27 30 // A simple hash function from Robert Sedgwicks Algorithms in C book.I've added some simple optimizations to the algorithm in order to speed up its hashing process. 28 public static ulong RSHash( ulong[] input) {31 public static ulong RSHash(byte[] input) { 29 32 const int b = 378551; 30 33 ulong a = 63689; … … 39 42 40 43 // A bitwise hash function written by Justin Sobel 41 public static ulong JSHash( ulong[] input) {44 public static ulong JSHash(byte[] input) { 42 45 ulong hash = 1315423911; 43 46 for (int i = 0; i < input.Length; ++i) … … 47 50 48 51 // This hash function comes from Brian Kernighan and Dennis Ritchie's book "The C Programming Language". It is a simple hash function using a strange set of possible seeds which all constitute a pattern of 31....31...31 etc, it seems to be very similar to the DJB hash function. 49 public static ulong BKDRHash( ulong[] input) {52 public static ulong BKDRHash(byte[] input) { 50 53 ulong seed = 131; 51 54 ulong hash = 0; … … 57 60 58 61 // This is the algorithm of choice which is used in the open source SDBM project. The hash function seems to have a good over-all distribution for many different data sets. It seems to work well in situations where there is a high variance in the MSBs of the elements in a data set. 59 public static ulong SDBMHash( ulong[] input) {62 public static ulong SDBMHash(byte[] input) { 60 63 ulong hash = 0; 61 64 foreach (var v in input) { … … 66 69 67 70 // An algorithm produced by Professor Daniel J. Bernstein and shown first to the world on the usenet newsgroup comp.lang.c. It is one of the most efficient hash functions ever published. 68 public static ulong DJBHash( ulong[] input) {71 public static ulong DJBHash(byte[] input) { 69 72 ulong hash = 5381; 70 73 foreach (var v in input) { … … 75 78 76 79 // An algorithm proposed by Donald E.Knuth in The Art Of Computer Programming Volume 3, under the topic of sorting and search chapter 6.4. 77 public static ulong DEKHash( ulong[] input) {80 public static ulong DEKHash(byte[] input) { 78 81 ulong hash = (ulong)input.Length; 79 82 foreach (var v in input) { … … 83 86 } 84 87 85 //public static ulong CryptoHash(HashAlgorithm ha, ulong[] input) { 86 // return BitConverter.ToInt32(ha.ComputeHash(input.ToByteArray()), 0); 87 //} 88 89 //public static byte[] ToByteArray(this ulong[] input) { 90 // var bytes = new byte[input.Length * sizeof(int)]; 91 // int pos = 0; 92 // foreach (var v in input) { 93 // var b0 = (byte)((v >> 24) & 0xFF); 94 // var b1 = (byte)((v >> 16) & 0xFF); 95 // var b2 = (byte)((v >> 8) & 0xFF); 96 // var b3 = (byte)(v & 0xFF); 97 // bytes[pos++] = b0; 98 // bytes[pos++] = b1; 99 // bytes[pos++] = b2; 100 // bytes[pos++] = b3; 101 // } 102 // return bytes; 103 //} 88 public static ulong CryptoHash(HashAlgorithm ha, byte[] input) { 89 return BitConverter.ToUInt64(ha.ComputeHash(input), 0); 90 } 104 91 } 105 92 }
Note: See TracChangeset
for help on using the changeset viewer.