public void Delete(HashItem item) { var key = item.Key; //get the hash var hashIndex = Hash(key); //move in array until an empty while (hashArray[hashIndex] != null) { if (hashArray[hashIndex]?.Key == key) { var temp = hashArray[hashIndex]; //assign a dummy item at deleted position hashArray[hashIndex] = null; return; } //go to next cell ++hashIndex; //wrap around the table hashIndex %= size; } }
public void Insert(int key, int data) { var item = new HashItem { Data = data, Key = key }; //get the hash int hashIndex = Hash(key); //move in array until an empty or deleted cell while (hashArray[hashIndex] != null) { //go to next cell ++hashIndex; //wrap around the table hashIndex %= size; } hashArray[hashIndex] = item; }