void rehash( ) { vector<HashEntry> oldArray = array; // Create new double-sized,
ID: 3801311 • Letter: V
Question
void rehash( )
{
vector<HashEntry> oldArray = array;
// Create new double-sized, empty table
array.resize( 2 * oldArray.size( ) );
for( auto & entry : array )
entry.info = EMPTY;
// Copy table over
currentSize = 0;
for( auto & entry : oldArray )
if( entry.info == ACTIVE )
insert( std::move( entry.element ) );
}
Explanation / Answer
However, it has many more possible search keys than there are hash elements. It is inevitable that some keys will resolve to the same hash code. This is known as a hash collision, and it must be handled properly.
Hash collisions will always occur, but we can be avoid it by spreading the data evenly across the entire table, on the whole so there is a smaller chance of collisions occuring.
If you faced with a collision situation,then the linear probing table will look onto to subsequent hash elements until the first free space is found. This way of traversal is known as probing the table
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.