I have a lengthy program that basically manages a hash table; adds, deletes, etc. I'm hitting an extremely bizarre bug in my program, though.
Basically I have a delete function that hashes a values, checks a linked list stored in an array given by a hash value for the appropriate object, and, if found, deletes it and exits the function. It looks essentially like this:
template<typename T>
void HashTable<T>::remove(T* t){
LinkedList<T> list= data[(hash(t))];
Node<T>* prev = NULL;
Node<T>* cur = list.head;
bool running = cur != NULL;
while(running){
T key = cur->getKey();
if(t == key){
if(prev == NULL){
cur = cur->getNext();
running = false;
}else{
prev->setNext(cur->getNext());
cout << &key << '\n';
cur = NULL;
running = false;
}
}
prev = cur;
cur = cur->getNext();
}
cout << "Are we getting here?"; //yes
}
I'm calling this function in this way:
Type* b = buildType(); //produces a Type* from CL arguments
hash.remove(b);
cout << "Are we getting to THIS SPOT?"; //no
Basically, the above program outputs "Are we getting here?" but not "Are we getting to THIS SPOT?"
I have no clue what could be the problem in this case, and it took me quite a while to even realize that there could possibly be a problem here. Does anyone know what the issue could possibly be?