- Timestamp:
- 07/05/19 15:44:04 (5 years ago)
- Location:
- stable
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 16218,16252,16255,16258-16261,16263,16267,16270-16273,16284,16290-16291,16302,16305,16382,16478
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/HashUtil.cs
r16218 r17090 20 20 #endregion 21 21 22 22 23 using System; 23 24 using System.Security.Cryptography; … … 28 29 29 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. 30 public static int RSHash(int[] input) {31 public static ulong RSHash(byte[] input) { 31 32 const int b = 378551; 32 inta = 63689;33 inthash = 0;33 ulong a = 63689; 34 ulong hash = 0; 34 35 35 36 foreach (var v in input) { … … 41 42 42 43 // A bitwise hash function written by Justin Sobel 43 public static int JSHash(int[] input) {44 inthash = 1315423911;44 public static ulong JSHash(byte[] input) { 45 ulong hash = 1315423911; 45 46 for (int i = 0; i < input.Length; ++i) 46 47 hash ^= (hash << 5) + input[i] + (hash >> 2); … … 49 50 50 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. 51 public static int BKDRHash(int[] input) {52 const intseed = 131;53 inthash = 0;52 public static ulong BKDRHash(byte[] input) { 53 ulong seed = 131; 54 ulong hash = 0; 54 55 foreach (var v in input) { 55 56 hash = (hash * seed) + v; … … 59 60 60 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. 61 public static int SDBMHash(int[] input) {62 inthash = 0;62 public static ulong SDBMHash(byte[] input) { 63 ulong hash = 0; 63 64 foreach (var v in input) { 64 65 hash = v + (hash << 6) + (hash << 16) - hash; … … 68 69 69 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. 70 public static int DJBHash(int[] input) {71 inthash = 5381;71 public static ulong DJBHash(byte[] input) { 72 ulong hash = 5381; 72 73 foreach (var v in input) { 73 74 hash = (hash << 5) + hash + v; … … 77 78 78 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. 79 public static int DEKHash(int[] input) {80 int hash =input.Length;80 public static ulong DEKHash(byte[] input) { 81 ulong hash = (ulong)input.Length; 81 82 foreach (var v in input) { 82 83 hash = (hash << 5) ^ (hash >> 27) ^ v; … … 85 86 } 86 87 87 public static int CryptoHash(HashAlgorithm ha, int[] input) { 88 return BitConverter.ToInt32(ha.ComputeHash(input.ToByteArray()), 0); 89 } 90 91 public static byte[] ToByteArray(this int[] input) { 92 const int size = sizeof(int); 93 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); 96 } 97 return bytes; 88 public static ulong CryptoHash(HashAlgorithm ha, byte[] input) { 89 return BitConverter.ToUInt64(ha.ComputeHash(input), 0); 98 90 } 99 91 }
Note: See TracChangeset
for help on using the changeset viewer.