【发布时间】:2016-03-02 06:46:27
【问题描述】:
我正在学习布隆过滤器,并且正在研究 JavaScript 中的各种哈希函数。
例如,我在另一个 Stack Overflow 答案中找到了这个:
在这里找到https://stackoverflow.com/a/7616484/5217568)
String.prototype.hashCode = function() {
var hash = 0, i, chr, len;
if (this.length == 0) return hash;
for (i = 0, len = this.length; i < len; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
如果我跑:
String.prototype.call(null, "hello")
我得到的数值是:99162322 (另外两个散列函数得到了我:1335831723 和 120092131)。
现在,如果我创建一个具有 3 个哈希函数和 18 个索引(k=3,m=18)的假设布隆过滤器,这些大值如何在索引为 0-17 的数组中编入索引?
【问题讨论】:
-
我认为应该使用哈希函数来确定存储数据的索引
标签: javascript data-structures hash hashtable bloom-filter