My current hash table implementation uses Linear Probing, and now I want to move on to Quadratic Probing (and later to chaining and possibly double hashing as well). I read several articles, textbooks, Wikipedia, etc. But I still don’t know exactly what I should do.
Linear sounding basically has step 1 and is easy to do. When searching, inserting or deleting an item from the hash table, I need to calculate the hash, and for this I do this:
index = hash_function(key) % table_size;
Then, when searching, pasting or deleting, I go through the table until I find a free bucket, for example:
do {
if() {
return;
} else {
index = (index + 1) % table_size;
}
while();
, , , , , , . , .
, , - , ( ). - - ?
EDIT:
, , , . http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_hashtable.aspx:
15 for ( step = 1; table->table[h] != EMPTY; step++ ) {
16 if ( compare ( key, table->table[h] ) == 0 )
17 return 1;
18
19
20 h = ( h + ( step * step - step ) / 2 ) % table->size;
21 }
2 , ... , c(i)=i^2. - c(i)=(i^2-i)/2
, :
index = (index + (index^index)) % table_size;
... :
index = (index + (index^index - index)/2) % table_size;
, :
index = (index + (index^index)/2) % table_size;
... , . , ...
1) ?
2) 2?