Linear Hashing - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Linear Hashing

Description:

hi(key) = h(key) mod(2iN); N = initial # buckets. h is some hash function (range is ... Since buckets are split round-robin, long overflow chains don't develop! ... – PowerPoint PPT presentation

Number of Views:1661
Avg rating:3.0/5.0
Slides: 10
Provided by: RaghuRama53
Category:
Tags: chains | hashing | key | linear

less

Transcript and Presenter's Notes

Title: Linear Hashing


1
Linear Hashing
2
Linear Hashing
  • This is another dynamic hashing scheme, an
    alternative to Extendible Hashing.
  • LH handles the problem of long overflow chains
    without using a directory, and handles
    duplicates.
  • Idea Use a family of hash functions h0, h1,
    h2, ...
  • hi(key) h(key) mod(2iN) N initial buckets
  • h is some hash function (range is not 0 to N-1)
  • If N 2d0, for some d0, hi consists of applying
    h and looking at the last di bits, where di d0
    i.
  • hi1 doubles the range of hi (similar to
    directory doubling)

3
Linear Hashing (Contd.)
  • Directory avoided in LH by using overflow pages,
    and choosing bucket to split round-robin.
  • Splitting proceeds in rounds. Round ends when
    all NR initial (for round R) buckets are split.
    Buckets 0 to Next-1 have been split Next to NR
    yet to be split.
  • Current round number is Level.
  • Search To find bucket for data entry r, find
    hLevel(r)
  • If hLevel(r) in range Next to NR , r belongs
    here.
  • Else, r could belong to bucket hLevel(r) or
    bucket hLevel(r) NR must apply hLevel1(r) to
    find out.

4
Overview of LH File
  • In the middle of a round.

Buckets split in this round
Bucket to be split
h
search key value
)
(
If
Level
Next
is in this range, must use
search key value
)
(
h
Level1
Buckets that existed at the
to decide if entry is in
beginning of this round
split image' bucket.
this is the range of
h
Level
split image' buckets
created (through splitting
of other buckets) in this round
5
Linear Hashing (Contd.)
  • Insert Find bucket by applying hLevel /
    hLevel1
  • If bucket to insert into is full
  • Add overflow page and insert data entry.
  • (Maybe) Split Next bucket and increment Next.
  • Can choose any criterion to trigger split.
  • Since buckets are split round-robin, long
    overflow chains dont develop!
  • Doubling of directory in Extendible Hashing is
    similar switching of hash functions is implicit
    in how the of bits examined is increased.

6
Example of Linear Hashing
h0 key mod 4 h1 key mod 8
  • On split, hLevel1 is used to re-distribute
    entries.

hi key mod 2i N
Level0, N4
Level0
PRIMARY
h
h
h
h
OVERFLOW
PRIMARY
0
1
PAGES
0
1
PAGES
PAGES
Next0
32
32
44
36
00
000
00
000
Next1
Data entry r
25
9
5
25
9
5
37
with h(r)5
01
001
01
001
30
30
14
18
10
14
18
10
Primary
10
10
010
010
bucket page
31
35
11
7
31
35
11
7
43
011
011
11
11
(This info is for illustration only!)
(The actual contents of the linear hashed file)
100
44
36
00
7
After inserting 29
h0 key mod 4 h1 key mod 8
Level0
PRIMARY
OVERFLOW
PAGES
h
PAGES
h
0
1
32
00
000
Next2
9
25
001
01
10
14
18
10
30
Now, insert 22, 66, 34
010
43
35
31
7
11
011
11
44
36
100
00
5
37
29
101
01
8
Example End of a Round
Level1
PRIMARY
OVERFLOW
h
h
PAGES
0
1
PAGES
Next0
Level0
00
000
32
PRIMARY
OVERFLOW
PAGES
h
PAGES
h
0
1
001
01
9
25
32
00
000
10
010
10
50
66
18
34
9
25
001
01
011
11
35
11
43
10
66
10
18
34
010
Next3
100
00
44
36
43
35
31
7
11
011
11
101
11
5
29
37
44
36
100
00
14
30
22
10
110
5
37
29
101
01
22
14
30
31
7
111
11
10
110
9
LH Described as a Variant of EH
  • The two schemes are actually quite similar
  • Begin with an EH index where directory has N
    elements.
  • Use overflow pages, split buckets round-robin.
  • First split is at bucket 0. (Imagine directory
    being doubled at this point.) But elements
    lt1,N1gt, lt2,N2gt, ... are the same. So, need
    only create directory element N, which differs
    from 0, now.
  • When bucket 1 splits, create directory element
    N1, etc.
  • So, directory can double gradually. Also, primary
    bucket pages are created in order. If they are
    allocated in sequence too (so that finding ith
    is easy), we actually dont need a directory!
    Voila, LH.
Write a Comment
User Comments (0)
About PowerShow.com