Database Systems · Extendible Hashing with Last-Bits Keys, Overflow and Deletion
The exact algorithm
3.1 Lookup
- Compute .
- Use as the directory index; follow the pointer to the bucket.
- Search the bucket (and its overflow chain, if any) for .
3.2 Insert
- Look up the bucket for .
- If the bucket has room, insert. Done.
- If the bucket is full:
- Case A — (local depth less than global): split the bucket into two. Increment its local depth to . Redistribute its records by the new bit. Update the directory pointers so half point to the old bucket and half to the new one. Directory size unchanged.
- Case B — (local depth equals global): first double the directory (, ; each old entry is copied to two adjacent entries). Then perform the split as in Case A.
- Repeat rule / Case C: after a split, if the new record's bucket is still full (all records fell on one side), repeat Case A or B. Use an overflow bucket only when more than records have the same complete hash value (e.g. duplicates), so no number of extra bits can separate them. Local depth is not increased in that case.
3.3 Delete
- Find and remove the record.
- If the bucket and its buddy (same local depth , suffixes differing only in the -th bit) now hold together at most records, merge them into one bucket with local depth (some texts merge only when a bucket becomes empty; follow the question). A merge can cascade.
- After a merge, if every bucket has local depth , halve the directory (, ), keeping one of each pair of identical pointers.
3.4 Disk accesses (the standard GATE counting rule)
- Directory in main memory: lookup = 1 disk access (read the bucket).
- Directory on disk: lookup = 1 (read directory) + 1 (read bucket) = 2 disk accesses.
- Each overflow bucket read adds 1 more access.