Bảng băm(Hash table) | Cài đặt bảng băm và kỹ thuật xử lý va chạm

 

void

search

(

string

s

)

{

    

//Compute the index using the hash function

    

int

index

=

hashFunc1

(

s

)

;

    

int

indexH

=

hashFunc2

(

s

)

;

    

//Search for an unused slot and if the index exceeds the hashTableSize roll back

    

while

(

hashTable

[

index

]

!

=

s

and

hashTable

[

index

]

!

=

“”

)

        

index

=

(

index

+

indexH

)

%

hashTableSize

;

    

//Is the element present in the hash table

    

if

(

hashTable

[

index

]

==

s

)

        

cout

<

<

s

<

<

” is found!”

<

<

endl

;

    

else

        

cout

<

<

s

<

<

” is not found!”

<

<

endl

;

}