Hash Files

1 / 11
About This Presentation
Title:

Hash Files

Description:

Put more than one record at an address. Hashing Function. Converting a ... Radix Conversion. Mid-square. Handling Collisions. Open Addressing. Linear Probing ... –

Number of Views:40
Avg rating:3.0/5.0
Slides: 12
Provided by: curt3
Category:
Tags: files | hash | radix

less

Transcript and Presenter's Notes

Title: Hash Files


1
Hash Files
  • CIS 402 File Management

2
How It Works
rrn
Key Value
Mapping Function
N-1
3
Collisions - Synonyms
  • Avoid Collisions
  • Reduce the Number of Collisions
  • Spread out records
  • Use extra memory
  • Put more than one record at an address

4
Hashing Function
  • Converting a String to a number
  • Prime Number division remainder
  • Digit extraction
  • Folding
  • Radix Conversion
  • Mid-square

5
Handling Collisions
  • Open Addressing
  • Linear Probing
  • Quadratic Probing
  • Double Hashing
  • Chaining
  • Restructuring the hash file - buckets

6
Bucket Algorithms - Insert
// Creates an entry and places the entry on the
page //If it fits and returns 0. //If it does
not fit, the function returns the addr of the
next //bucket int Insert(string key, int
address) if it doesnt fit return
Next_Bucket else add to next slot in
bucket add to NumEntries return 0 //
success indicator
7
Bucket Algorithms - Find
// Find looks in the bucket for the key. If it
finds it, it assigns //the associated address to
addr and returns 0. If it doesnt find //it, it
returns the address of the next bucket. int
Find(string key, int addr) while iltNumEntries
entry not the one at i increment i if (i
gt NumEntries) // not in bucket return
NextBucket else assign address at position i
to addr return 0
8
Hash File Insert
//Hash the key and call the recursive
insert //Return 1 if success and 0 if failed int
Insert(string key, int address) bucketNo
hash(key) return _Insert(key, address,
bucketNo)
9
Hash File Algorithms - Insert
int _Insert(string key, int address, int
bucketNo) read the bucket at bucket
number Insert the key/address in the bucket if
( Insert succeeded) Write the bucket return
1 if (Insert gave back 1 ) //didnt fit, no
next bucket yet get a new bucket insert the
key/address into the new bucket Write the new
bucket link the new bucket to old
bucket Write the old bucket return 1 return
_Insert(key, address, bucketNo back from insert
to bucket call)
10
Hash File Search
//Hash the key and call the recursive
search //Return the address associated with key
if success //and -1 if failed int Search(string
key) bucketNo hash(key) return _Search(key,
bucketNo)
11
Hash File Algorithms - Search
//Searches at the given bucketNo for key // It
returns associated address if found and 1
otherwise. int _Search(string key, int
bucketNo) read the bucket at address
bucketNo find the value in the bucket if find
succeeded return 1 if find returned
1 return 1 return _Search(key, the return
from find)
Write a Comment
User Comments (0)
About PowerShow.com