internal static List <ulong> ConstructHashedSet(byte P, int N, byte[] key, IEnumerable <byte[]> data) { // N the number of items to be inserted into the set. var dataArrayBytes = data as byte[][] ?? data.ToArray(); // The list of data item hashes. var values = new ConcurrentBag <ulong>(); var modP = 1UL << P; var modNP = ((ulong)N) * modP; var nphi = modNP >> 32; var nplo = (ulong)((uint)modNP); // Process the data items and calculate the 64 bits hash for each of them. Parallel.ForEach(dataArrayBytes, item => { var hash = SipHasher.Hash(key, item); var value = FastReduction(hash, nphi, nplo); values.Add(value); }); var ret = values.ToList(); ret.Sort(); return(ret); }
public static ulong Hash(byte[] key, byte[] data) { var k0 = BitConverter.ToUInt64(key, 0); var k1 = BitConverter.ToUInt64(key, 8); var hasher = new SipHasher(k0, k1); hasher.Write(data); return(hasher.Finalize()); }