public BucketArray(BucketArraySize size) { Size = size; int c = (int)Size; Buckets = new Bucket[c]; for (int i = 0; i < c; i++) { Buckets[i] = new Bucket(i); } }
public static ushort Hash(byte[] key, BucketArraySize size) { // compute the hash value of the key byte[] hash = ComputeSha256(key); // grab the first two bytes of the hash to an unsigned short ushort firstUShort = BitConverter.ToUInt16(hash, 0); // derive the bitmask value from size of bucket array ushort mask = Convert.ToUInt16(((int)size) - 1); // return the required bits return(Convert.ToUInt16(firstUShort & mask)); }
public HashTable(BucketArraySize size) { BucketArray = new BucketArray(size); }
public static ushort HashKey(Key key, BucketArraySize size) { return(Hasher.Hash(key.BinaryValue, size)); }
public static ushort Hash(string key, BucketArraySize size) { return(Hash(Encoding.UTF8.GetBytes(key), size)); }