Insert using Linear Hashing

18
Insert using Linear Hashing h0 0 1 4 H level (n) = level+1 right most bits of n Level = 0, next = 7 Insert 5, h 0 (5) = 1 initial 4 = 100, so h 0 (4) = 0 7 = 111, so h 0 (7) = 1

description

4. 7. Insert using Linear Hashing. H level (n) = level+1 bits of n. Level = 0, next =. h0 0 1. initial. Insert 2, h 0 (2) = 0. 4 2. 7. Insert using Linear Hashing. H level (n) = level+1 bits of n. Level = 0, next =. h0 0 1. Insert 8, h 0 (8) = 0. 4 2. 7. 8. - PowerPoint PPT Presentation

Transcript of Insert using Linear Hashing

Page 1: Insert using Linear Hashing

Insert using Linear Hashing

h001

4

H level (n) = level+1 right most bits of n Level = 0, next =

7

Insert 5, h0(5) = 1

initial

4 = 100, so h0(4) = 07 = 111, so h0(7) = 1

Page 2: Insert using Linear Hashing

Insert using Linear Hashing

h001

4

H level (n) = level+1 bits of n Level = 0, next =

7 5

Insert 9, h0(9) = 1

Page 3: Insert using Linear Hashing

Insert using Linear Hashing

h001

4

H level (n) = level+1 bits of n Level = 0, next =

7 5 9 No room, so create an overflow block, which triggers the splitting process.

Page 4: Insert using Linear Hashing

Insert using Linear Hashing

h001

4

H level (n) = level+1 bits of n Level = 0, next =

7 5 9 No room, so create an overflow block, which triggers the splitting process.

H1(4) = 00

h100011011

Page 5: Insert using Linear Hashing

Insert using Linear Hashing

h001

4

H level (n) = level+1 bits of n Level = 0, next =

7 5

h100

10

Denotes split bucket

No room, so create an overflow block, which triggers the splitting process.

H1(4) = 00

9

Page 6: Insert using Linear Hashing

Insert using Linear Hashing

h001

4

H level (n) = level+1 bits of n Level = 0, next =

7 5

Insert 8, h0(8) = 0

Advance NEXT by one.

h100

10

9

Page 7: Insert using Linear Hashing

Insert using Linear Hashing

h001

4 8

H level (n) = level+1 bits of n Level = 0, next =

7 5

Insert 3, h0(3) = 1

h100

10

9

Page 8: Insert using Linear Hashing

Insert using Linear Hashing

h001

4 8

H level (n) = level+1 bits of n Level = 0, next =

7 5No room, insert into overflow COULD trigger a split.

h100

10

9 3

Page 9: Insert using Linear Hashing

Insert using Linear Hashing

h001

4 8

H level (n) = level+1 bits of n Level = 0, next =

5 9Redistribute 7, 5, 9, 3 using H1

H1(7) = 11H1(5) = 01H1(9) = 01H1(3) = 11

h100011011

7 3

Page 10: Insert using Linear Hashing

Insert using Linear Hashing

h001

4 8

H level (n) = level+1 bits of n Level = 0, next =

5 9Advance Next, but it is at the bottom of the current Level.

h100011011

7 3

Page 11: Insert using Linear Hashing

Insert using Linear Hashing

h001

4 8

H level (n) = level+1 bits of n Level = 1, next =

5 9So reset it to the top and increment Level to 1.

h100011011

7 3

Page 12: Insert using Linear Hashing

Insert using Linear Hashing

4 8

H level (n) = level+1 bits of n Level = 1, next =

5 9Remove split indicators and only use H1

h100011011

7 3

Page 13: Insert using Linear Hashing

Insert using Linear Hashing

4 8

H level (n) = level+1 bits of n Level = 1, next =

5 9

Insert 15, h1(15) = 11

h100011011

7 3

Page 14: Insert using Linear Hashing

Insert using Linear Hashing

4 8

H level (n) = level+1 bits of n Level = 1, next =

5 9

h100011011

7 3 15No room, so create an overflow block, which triggers the splitting process.

Page 15: Insert using Linear Hashing

Insert using Linear Hashing

4 8

H level (n) = level+1 bits of n Level = 1, next =

5 9

h100011011

7 3 15

Split Next using level+1 H functionH2(4) = 100H2(8) = 000

Page 16: Insert using Linear Hashing

Insert using Linear Hashing

8

H level (n) = level+1 bits of n Level = 1, next =

5 9

h100011011

7 3 15

Split Next using level+1 H functionH2(4) = 100H2(8) = 000

h2100 4

h2000

Page 17: Insert using Linear Hashing

Insert using Linear Hashing

8

H level (n) = level+1 bits of n Level = 1, next =

5 9

h100011011

7 3 15

Mark bucket as splitAdvance Next.

4h2100

h2000

Page 18: Insert using Linear Hashing

Insert using Linear Hashing

8

H level (n) = level+1 bits of n Level = 1, next =

5 9

h100011011

7 3 15

Mark bucket as splitAdvance Next.

4

And Insert and Insert and Insert ….

h2100

h2000