"joe"
around?
"joe"
's the same as 2
.
a[2] == "joe"
.
add()
, delete()
, and
find()
.
create()
operator.
h(k) is full, examine (h(k) + 1) % N , then (h(k) + 2)
% N , then ..., (h(k) + N - 1) % N .
|
|
(h(k) + i
2) % N
for 0 ≤ i
< N.
(h
1(k) + u*i) % N
i
< N and u = h
2(k)
.
add()
, delete()
, and find()
.
void add(key k) linked-list chain = table[hash(k)] if not chain.member(k) chain.add(k) void delete(key k) linked-list chain = table[hash(k)] if not chain.member(k) chain.delete(k) bool find(key k) return table[hash(k)].member(k)
|
|
add()
, delete()
, and find()
use the locate()
private operation.
bool locate(key k, int & hi) hi = hash(k) step = 1 or i2 or hash2(k) for i = 1 to B if not in-cluster[hi] return false if occupied[hi] and table[hi] == k return true hi = (hi + step) mod B hi = -1 return false
void add(key k) if not locate(k, hi) if hi > -1 table[hi] = k occupied[hi] = true in-cluster[hi] = true void delete(key k) if locate(k, hi) occupied[hi] = false in-cluster[hi] = in-cluster[hi + 1 mod B] and in-cluster[hi - 1 mod B] bool find(key k) return locate(k, hi)
α = elements stored/total slots
rp[]
, a
random permutation
of the 256 integers 0 to 255 (byte values).
v[]
of n
byte values, hash v
into a
byte value h
with
byte hash(byte v[], unsigned n) byte h = rp[v[0]] for i = 1 to n - 1 h = h xor rp[v[i] return h
hash()
produces multi-byte hash values.
unsigned hash(unsigned k) return k mod B
unsigned hash(unsigned k) return (M*k + a) mod B
unsigned hash(unsigned k) return floor(B*fraction(k*A))
XOR 0 1 0 0 1 1 1 0
(x*101 ^ y*97) % B
.
(round(x*101)*round(y*97))/256 % B
.
(round(x*101)*round(y*97))/2 % B
.
unsigned point::random(double k) return (M*static_cast(k*11) + a) % s unsigned point::hash() return random(x)*random(y); template <typename T> unsigned hash_table(const T & e) return e.hash() % size
M = 25173
, a = 13849
, s = 65536
.