【发布时间】:2016-05-24 07:58:34
【问题描述】:
以下演示取自 Tim Roughgarden 提供的 Coursera 上的算法:设计和分析视频讲座(顺便说一句,现象解释)。据我了解,此哈希函数有效地返回哈希表中 0 到 n 之间的现有索引位置。但是,当a(下图)是一个随机整数时,如何对这种独特的计算进行逆向工程以进行恒定时间查找,这让我感到困惑。
Let U = IP addresses (of the form (x1, x2, x3, x4)
with each subscript of x in {0,1,2,...255})
Let n = a prime number
Define one hash function per 4-tuple a = (a1, a2, a3, a4)
with each subscript of a in {0, 1, 2,...n-1}
Define: h<sub>a : IP addresses ---> buckets *n^4 such functions*
by h<sub>a(x1,x2,x3,x4) = (a1x1 + a2x2 + a3x3 + a4x4)
<sub> = subscript notation
然后使用modulo n 计算上述等式以返回哈希表中的位置,该位置对于U 中的任何不同输入具有 1/n 的重复概率。如何使用原始 IP 地址检索该 IP 地址位置?
【问题讨论】:
标签: algorithm hash hashtable hashcode