public bool deleteTask(Task x) { /**** * This function will delete a Task from the hash table ****/ if(!Contains(x)) { return false; } //If the task is not in the hash table is cannot be deleted int hash_val = 0; hash_val = x.getHashCode(); for(int i = 0; i < hashtable[hash_val].Count; i++){ hashtable[hash_val][i] = null; count--; //Decrement the size of the hash table } return true; }
public bool Contains(Task x) { /**** * This function will check the hashtable by indexing to the bucket based off of the hash code for the task being * inserted and checking all the tasks that reside in that bucket. ****/ int hash_val = 0; hash_val = x.getHashCode(); for(int i = 0; i < hashtable[hash_val].Count; i++){ //loop through the bucket to check for x if(x == hashtable[hash_val][i]) return true; //The task is already in the hash table } return false; }
public bool insert(Task x) { /**** * This function will check to make sure the task you are trying to add to the hash table is not already in the * table by calling the contains function. If it is not already in the hash table then this function will * insert the new task into your calendar. ****/ if(Contains(x) == true) return false; int hash_val = 0; hash_val = x.getHashCode(); for(int i = 0; i < hashtable[hash_val].Count; i++) hashtable[hash_val][i] = x; count++; //Increment the size of the hash table return true; }