Linear Hashing
This document discusses hashing keys into and splitting hash entries under the Linear Hashing
scheme. Although an array may not be an ideal data structure for Linear Hashing, an array is
easier to use for an example, and the basic concepts are identical.
Basic Elements
The basic elements for Linear Hashing implementation are:
•
An array that initially has a number of elements that is some power of 2. This array holds
objects that contain a value, and also a pointer to the next object with a value that is hashed
to the same index, in a linkedlist implementation.
•
A splitindex variable, which is an integer representing the index of your array to be split the
next time a collision occurs.
•
A modulo variable, which is an integer representing what your hash value is mod by to get it’s
array index. The modulo is always a power of 2.
The Idea
You start with your array initially empty, splitindex initialized to 0, and modulo initialized to the
length of your array.
You begin to read in keys, passing them to the base hash function (h
2
). The return from this hash
function is an integer that represents the index into which the key should be placed. You repeat
this until a collision occurs.
When a collision occurs you do the following:
•
Insert the key value into it’s expected index. Since a collision occurred, there already is at
least one other key that hashed to that index, so this means inserting the new key into a
linked list.
•
Add one element at the end of your array.
•
Look at your splitindex value. Find the corresponding index in your array. For every key
stored at that index, rehash by making a call to the extended hash function (h
3
). This will
result in value being hashed back to the same index (key value DIV modulo was even) or
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '11
 Moon
 hash function, splitindex

Click to edit the document details