Hello, I was wondering if i could get some help to prevent a duplicate entry into my hashtable:
bool hashmap::put(const stock& s, int& usedIndex, int& hashIndex, int& symbolHash)
{
hashIndex = this->hashStr( s.m_symbol ); // Get remainder, Insert at that index.
symbolHash = (int&)s.m_symbol;
usedIndex = hashIndex;
while ( hashTable[hashIndex].m_symbol != NULL ) // collision found
{
++usedIndex %= maxSize; // if necessary wrap index around
if ( hashTable[usedIndex].m_symbol == NULL )
{
hashTable[usedIndex] = s;
return true;
}
}
hashTable[hashIndex] = s; // insert if no collision
return true;
}
The paramater hashIndex uses a java algorithm to generate an appropriate index to insert into the table. The usedIndex paramater is where I insert into the table when a collision is found; symbolHash just gets the address of the name passed in. stock is a class object.
My question is just, how do i prevent a duplicate entry?