Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 public HashTable(BucketArraySize size)
 {
     BucketArray = new BucketArray(size);
 }
Ejemplo n.º 4
0
 public static ushort HashKey(Key key, BucketArraySize size)
 {
     return(Hasher.Hash(key.BinaryValue, size));
 }
Ejemplo n.º 5
0
 public static ushort Hash(string key, BucketArraySize size)
 {
     return(Hash(Encoding.UTF8.GetBytes(key), size));
 }