|
|
|
|
Consequently:
|
n = 2 (2 buckets in use, bucket indexes: 0 .. 1)
i = 1 (1 bit needed to represent a bucket index)
|
|
|
The bucket index consists of the last i bits in the hash function value.
|
|
|
|
Notice that:
|
if ( Avg occupancy of a bucket > τ )
{
n++;
}
|
|
Example:
|
r
if ( -------- > τ )
n × γ
{
n++;
}
|
Parameter: n = current number of buckets in use
i = ⌈ log(n) ⌉
Insert( x , recordPtr(x) )
{
k = h(x); // General hash function value
m = last i bits of k; // Linear hash function value
/* -----------------------------------------------
Insert (x, recordPtr(x)) in "bucket m"
----------------------------------------------- */
if ( m ≤ n−1 )
{
/* =========================================
m is a "real" bucket
========================================= */
Insert (x, recordPtr(x)) into bucket m
if neccessary, use an overflow block;
}
else
{
/* =========================================
m is a "ghost" bucket
Recall: first bit of m is 1
I.e.: m = 1xxxxxxxxx
========================================= */
m' = m with the first bit is changed to 0
// I.e.: m = 1xxxxxxxxxx
// m' = 0xxxxxxxxxx
// Note: m' is for sure a "real" bucket !!!
Insert (x, recordPtr(x)) into bucket m'
if neccessary, use an overflow block;
}
/* =============================================
Check if we need to adjust n
============================================= */
if ( r/(n*γ) > τ )
{
Add bucket n;
Let n = b1b2...; // n = the index of the NEW bucket
// n can be a binary number of i bits OR
// a binary number 100...000 of i+1 bits
// In any case, the first bit of n (b1) = 1 !!!
j = ⌈ log(n) ⌉ ; // Number of binary digits for n
/* --------------------------------------
We need to move some search keys
into this new bucket
-------------------------------------- */
n' = 0b2... ; // n' was the "real" bucket used to
// store search keys that were previously hashed
// into the "ghost" bucket "1b2..."
/* ----------------------------------------------------
Now that this "ghost" bucket is NOW "real", we move
the "ghost"'s search keys into the "real" bucket
---------------------------------------------------- */
for ( every search key k ∈ bucket n' ) do
{
if ( last j bits of k == b1b2... (i.e., = n) )
{
move search key k into the new bucket n;
}
}
}
}
|
Parameter: n = current number of buckets in use
i = ⌈ log(n) ⌉
Lookup( x )
{
k = h(x); // General hash function value
m = last i bits of k; // Linear hash function value
if ( m ≤ n−1 )
{
/* =========================================
m is a "real" bucket
========================================= */
Search (x, recordPtr(x)) in bucket m
(including the overflow block);
}
else
{
/* =========================================
m is a "ghost" bucket
Recall: first bit of m is 1
m = 1xxxxxxxxx
========================================= */
m' = m where the first bit is changed to 0
// I.e.: m = 1xxxxxxxxxx
// m' = 0xxxxxxxxxx
// Note: m' is a "real" bucket !!!
Search (x, recordPtr(x)) in bucket m'
(including the overflow block);
}
}
|
Max # search keys in 1 block (γ) = 2 Threshold avg occupance (τ) = 0.85 |
|
Average occupancy:
r 3
------- = ------- = 0.75
n × γ 2 × 2
|
|
Average occupancy:
r 4
------- = ------- = 1 > τ (0.85)
n × γ 2 × 2
|
|
Average occupancy:
r 4
------- = ------- = 0.6666 ≤ τ (0.85)
n × γ 3 × 2
|
Notice that:
|
|
Average occupancy:
r 5
------- = ------- = 0.833333 ≤ τ (0.85)
n × γ 3 × 2
|
No need too add another bucket.....
|
Average occupancy:
r 6
------- = ------- = 1 > τ (0.85)
n × γ 3 × 2
|
|
Average occupancy:
r 6
------- = ------- = 0.75 ≤ τ (0.85)
n × γ 4 × 2
|
Notice that:
|
Hint:
|