Double Hashing

Posted heifengli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Double Hashing相关的知识,希望对你有一定的参考价值。

Data Structure and Algorithm Analysis in C++

5.4.3 Double Hashing

In the beginning of chapter 5.4, the formula  hi(x) = (hash(x) + f(i))  is mentioned and  f(i) is defined as f(i) = i ;

Here f(i) is defined as f(i) = i * hash2(x) and hash2(x) = R - (x mod R) where R is a prime smaller than TableSize. If R = 7 then hash2(x) = 7 - (x mod 7).

The case it uses is as followed.  Figure 5.18 shows the result of inserting keys {89, 18, 49, 58, 69} into a hash table.

技术分享图片

 

Hash(x), or hash1(x) to be precise, is defined as hash1(x) = x % 10  //  TableSize = 10. 

So if there‘s no collision, h(x) = hash1(x);  otherwise hi(x) = { hash1(x) + i * hash2(x) } % TableSize .

The first collision occurs when 49 is inserted. hash2(49) = 7 ? 0 = 7, so 49 is inserted in position 6    // { 49%10 + (7 - 1* 49%7)  } % 10 .

hash2(58) = 7 ? 2 = 5, so 58 is inserted at location 3     // ( 8 + 1*5 )%10 .

Finally, 69 collides and is inserted at a distance hash2(69) = 7?6 = 1 away.

If we tried to insert 60 in position 0, we would have a collision. Since hash2(60) = 7 ? 4 = 3, we would then try positions 3, 6, 9, and then 2 until an empty spot is found.

 

以上是关于Double Hashing的主要内容,如果未能解决你的问题,请参考以下文章

java里double类和double的区分 是否在于一个是大写一个是小写?

未定义模板 'std::__1::function<int (double, double, double, double)>' 的隐式实例化

C#:double[][] 和 double[,] [重复]

允许将 (double *) 转换为 (double **) 吗?

关于double和float的包装类Double和Float代码如下 Double d1 = 1.0;Double d2 = 1.0;

如何在 Scala 中将 Array[(Double, Double)] 转换为 Array[Double]?