next up previous contents
Next: Open (Pointer) Hashing: ohash Up: 3240 Previous: B-Trees: Indexing to Relational   Contents

Hash Tables: ADT [103]

void insert(element_type key, HASH_TABLE H);
position find(element_type key, HASH_TABLE H);
position delete(element_type key, HASH_TABLE H);

Trees: O( ) or O( )

Hash Tables: O( ) but no find_min, find_max, sorted

Hash Function:

int hash(char *key, unsigned int H_SIZE) {
  unsigned int hash_val = 0;
  while (*key != '\0')
    hash_val += *key++;
  return(hash_val % H_SIZE);
}
hash("john",4) = 3        hash("mary",4) = 1      hash("dave",4) = 0


\begin{picture}(100,80)(60,740)
\thicklines\put( 80,760){\line( 1, 0){ 80}}
\put...
... 95,745){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm john}}}
\end{picture}

But hash("phil",4) = 1: collision

Solution 1: each table entry is beginning of a list (open hashing)

Solution 2: find an unused table entry (closed hashing)



Subsections

Ted Billard 2001-10-25