Exemple #1
0
 /// <summary>
 /// Create List in each bucket.
 /// </summary>
 /// <param name="hash"></param>
 public Hash(HashFunctionInterface <T> hash)
 {
     for (int i = 0; i < sizeOfHashTable; i++)
     {
         this.buckets[i] = new List <T>();
     }
     this.hash = hash;
 }
Exemple #2
0
 public HashTable(HashFunctionInterface hashFunction)
 {
     for (int i = 0; i < 500; ++i)
     {
         hashElement[i] = new List();
     }
     this.hashFunction = hashFunction;
 }
        public void ChangeTest()
        {
            HashFunctionInterface <int> newMockHash = mocks.NewMock <HashFunctionInterface <int> >();

            Expect.AtLeastOnce.On(newMockHash).Method("HashFunction").Will(Return.Value(1));
            Expect.AtLeastOnce.On(mockHash).Method("HashFunction").Will(Return.Value(0));
            tableInt.InsertElementToHashTable(12);
            tableInt.ChangingHashFunctionWhileUsingHashTable(newMockHash);
            Assert.IsTrue(tableInt.ContainsElement(12));
        }
Exemple #4
0
 /// <summary>
 /// Name of method speaks for itself.
 /// </summary>
 /// <param name="newHashFunction"></param>
 public void ChangingHashFunctionWhileUsingHashTable(HashFunctionInterface <T> newHashFunction)
 {
     hash = newHashFunction;
     for (int i = 0; i < sizeOfHashTable; i++)
     {
         if (buckets[i].SizeOfList() != 0)
         {
             for (int j = 0; j < buckets[i].SizeOfList(); j++)
             {
                 var temp = buckets[i].FindValue(j);
                 buckets[i].Remove(j);
                 InsertElementToHashTable(temp);
             }
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// Function to change hash function without delete elements
 /// </summary>
 /// <param name="func"></param>
 public void ChangeHashFunction(HashFunctionInterface func)
 {
     List[] temp = new List[bucket.Length];
     for (int i = 0; i < bucket.Length; i++)
         temp[i] = new List();
     
     for (int i = 0; i < bucket.Length; i++)
     {
         while (!bucket[i].IsEmpty())
         {
             temp[func.Function(bucket[i].ValueHead()) % temp.Length]
                 .AddElementToHead(bucket[i].ValueHead());
             bucket[i].DeleteElement(bucket[i].ValueHead());
         }
     }
     hashFunction = func;
     bucket = temp;
 }
Exemple #6
0
        /// <summary>
        /// Function to change hash function without delete elements
        /// </summary>
        /// <param name="func"></param>
        public void ChangeHashFunction(HashFunctionInterface func)
        {
            List[] temp = new List[bucket.Length];
            for (int i = 0; i < bucket.Length; i++)
            {
                temp[i] = new List();
            }

            for (int i = 0; i < bucket.Length; i++)
            {
                while (!bucket[i].IsEmpty())
                {
                    temp[func.Function(bucket[i].ValueHead()) % temp.Length]
                    .AddElementToHead(bucket[i].ValueHead());
                    bucket[i].DeleteElement(bucket[i].ValueHead());
                }
            }
            hashFunction = func;
            bucket       = temp;
        }
 public void Initialize()
 {
     hashFunction = new HashNumberTwo();
     hashTable = new HashTable(hashFunction);
 }
Exemple #8
0
 /// <summary>
 /// Constructor with size hash table and number hash function. 
 /// </summary>
 /// <param name="size"></param>
 /// <param name="numberFunction"></param>
 public HashTable(int size, HashFunctionInterface func)
 {
     Init(size);
     hashFunction = func;
 }
Exemple #9
0
 public void ChangeHashFunction(HashFunctionInterface hashFunction)
 {
     this.hashFunction = hashFunction;
 }
Exemple #10
0
 /// <summary>
 /// Constructor with size hash table and number hash function.
 /// </summary>
 /// <param name="size"></param>
 /// <param name="numberFunction"></param>
 public HashTable(int size, HashFunctionInterface func)
 {
     Init(size);
     hashFunction = func;
 }
 public void Initialize()
 {
     mocks = new Mockery();
     mockHash = mocks.NewMock<HashFunctionInterface<int>>();
     tableInt = new Hash<int>((HashFunctionInterface<int>)mockHash);
 }