Slideshow:
|
Parameter i determines the number of logical hash buckets
|
|
|
|
Example:
|
|
$64,000 question:
|
Answer:
|
|
|
|
Answer:
|
|
Parameter: i = # bits used in RandomNumGen Insert( x, recordPtr(x) ) { k = h(x); // Genenral Hash function value j = k % 2i ; // Extensible hash function value Read disk block at bucket[j] (1 block) into memory; if ( bucket[j] block has space for a search key ) { Insert (x, recordPtr(x) ) into the block; Write block back to disk; return; // Done ! } /* ------------------------------------- bucket[j] disk block is full We must allocate a new disk block ------------------------------------- */ /* ======================================================== Check if we need to double the logical hash table size ========================================================= */ Let i' = integer label of physical bucket[j] block; if ( i' == i ) { Double the logical hash table; i = i + 1; // We use 1 more bit to hash Before: After: } /* =========================================================== Here: we KNOW that we can link the new disk block to the logical hash table ============================================================ */ Re-hash all search keys in bucket[j] (physical bucket) into 2 block (physical buckets) using i'+1 bits Update block label in each block (physical buckets) to i'+1 Graphically: /* ========================================================== Link the new (split) blocks) to the correct logical hash buckets ========================================================== */ Let j0 and j1 be the 2 hash values used in the re-hash operation; // In the figure: j0 = 001 and j1 = 101 Let B0 and B1 be the block addresses of the 2 (new) block (physical buckets) Bucket[j0] = B0; // Update logical ⇒ physical mapping Bucket[j1] = B1; Graphically: /* ==================================================================== We made space in buckets, try inserting the new key again.... Note: this can recurse further (if all keys hashed into ONE bucket) ==================================================================== */ Insert( x, recordPtr(x) ); // Try again with an extended hash table size ! } |