Top Banner
DYNAMIC HASHING TECHNIQUES Presented By: Anila Sahar Butt MSIT-8
22

Hashing Tuto

Jun 02, 2018

Download

Documents

Maryam Jameela
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 1/22

DYNAMIC HASHING

TECHNIQUES

Presented By:Anila Sahar Butt

MSIT-8

Page 2: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 2/22

EXTENSIBLE HASHING

Page 3: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 3/22

Advance Databases Concepts 3

Extensible Hashing

Use i of b bits output by hash functionb

h(K)

usei grows over time….

00110101

Page 4: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 4/22

Advance Databases Concepts 4

Use directory

h(K)[i ] to bucket...

.

.

.

Page 5: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 5/22

Example

• h(k) is 4 bits• 2 keys/bucket

0

1

10001

1

1001

1100

1

Page 6: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 6/22

Example

• Insert

0

1

10001

1

1001

1010 1

1100

11001010

00

01

10

11

2

2

21

Page 7: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 7/22

LINEAR HASHING

Page 8: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 8/22

Linear Hashing• Family of Hash Functions

– h0, h1, h2, …..

During each round only two hash functions are used – At level (round number)• hLevel• hLevel + 1

• Hash Function• h i(value) = h(value) mod (2 iN)• N is “Initial Number of buckets” • i is level (Round number), initialize to 0

Page 9: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 9/22

Linear Hashing

• Next Pointer point the bucket that is to split

• At any given point within the round we have – Buckets that have been split – Buckets that are yet to split – Buckets created by splits in this round

• If Next bucket is split at any Level, Hash function h Level + 1 redistributes entries between this bucket and its split image

Page 10: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 10/22

Example

Level = 0 , N = 4

h1 h0 Primary PagesNext=0

000 00

001 01

010 10

011 11

32 44 36

9 25 5

14 18 10 30

31 35 7 11

Page 11: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 11/22

SIMPLE INSERTION

• Insert 37 – Apply hash Function h0

37mod (2 i N) = 37 mod 4 = 1 (01)

h1 h0 Primary PagesNext=0

000 00

001 01

010 10

011 11

32 44 36

9 25 5

14 18 10 30

31 35 7 11

37

Page 12: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 12/22

Over Flow• Insert 43

– Apply hash Function h043 mod (2 i N) = 43 mod 4 = 3 (11)

– Check bucket (11) capacity• Full Add Over Flow Page , insert value in it

– If Over Flow• Split Bucket pointed by Next Pointer• Add split image at the end of buckets• Redistribute the values of split bucket• Move Next Pointer to Next Bucket

Page 13: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 13/22

Over Flow

Level = 0 , N = 4

h1 h0 Primary Pages Overflow Pages

Next=0 000 00

Next=1

001 01

010 10

011 11

100 00

9 25 5

14 18 10 30

31 35 7 11

32 44 36

44 36

43

32

Page 14: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 14/22

Example

By Inserting 22, 66, 34

Level = 0 , N = 4

h1 h0 Primary Pages Overflow Pages

000 00

001 01

010 10 Next=3

011 11

100 00

101 01

110 10

9 25

66 18 10 34

31 35 7 11 43

32

44 36

5 37 29

14 30 22

Page 15: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 15/22

Insertion in Split Bucket• Insert 13

– Apply hash Function h013 mod (2 i N) = 13 mod 4 = 1 (01)

– Check bucket (01) capacity, and bucket category• Bucket above next pointer Means?• Check newly inserted value proper place by applying second hash

function

– 13 mod (2 i N) = 13 mod 8 = 5 (101)

– Insert new value in Split Image

Page 16: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 16/22

Example

By Inserting 13

Level = 0 , N = 4

h1 h0 Primary Pages Overflow Pages

000 00

001 01

010 10 Next=3

011 11

100 00

101 01

110 10

9 25

66 18 10 34

31 35 7 11 43

32

44 36

5 37 29

14 30 22

13

Page 17: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 17/22

Splitting Last Bucket of a Round(Level)

• Insert 50 – Apply hash Function h0

50 mod (2 i N) = 50 mod 4 = 2 (10)

– Apply hash Function h1

50 mod (2 i N) = 50 mod 8 = 2 (010)

– Check bucket (10) capacity• Full Add Over Flow Page , insert value in it

If Over Flow• Split Bucket pointed by Next Pointer• Add split image at the end of buckets• Redistribute the values of split bucket• As Round is complete now. Move Next to the start of File. Increment Level to 1

Page 18: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 18/22

Example

Insert 50Level = , N = 4

Primary Pages Overflow Pages

9 25

66 18 10 34

43

32

44 36

5 37 29

14 30 22

50

31 35 7 1143 35 11

31 7

Next=3

Next=0

01

h1

000

001

010

011

100

101

110

111

h0

00

01

10

11

00

01

10

11

Page 19: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 19/22

THANKS

Page 20: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 20/22

QUIZ

Page 21: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 21/22

Q1- Insert 51

Page 22: Hashing Tuto

8/10/2019 Hashing Tuto

http://slidepdf.com/reader/full/hashing-tuto 22/22

Q2- Insert 15