linear-hash

linear-hash - Linear Hashing This document discusses...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 linked-list 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, re-hash 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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 4

linear-hash - Linear Hashing This document discusses...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online