{"id":263250,"date":"2023-03-15T09:07:56","date_gmt":"2023-03-15T01:07:56","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=263250"},"modified":"2023-02-20T20:08:13","modified_gmt":"2023-02-20T12:08:13","slug":"learned-what-bron-filter","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/learned-what-bron-filter.html","title":{"rendered":"\u4f60\u5b66\u4f1a\u4ec0\u4e48\u662f\u5e03\u9686\u8fc7\u6ee4\u5668\u4e86\u5417\uff1f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u5bf9\u54cd\u5e94\u65f6\u95f4\u8981\u6c42\u6bd4\u8f83\u4e25\u683c\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u6211\u4eec\u6709\u91cc\u9762\uff0c\u90a3\u4e48\u968f\u7740\u96c6\u5408\u4e2d\u5143\u7d20\u6570\u91cf\u7684\u589e\u52a0\uff0c\u6211\u4eec\u9700\u8981\u7684\u5b58\u50a8\u7a7a\u95f4\u8d8a\u6765\u8d8a\u5927\uff0c\u68c0\u7d22\u65f6\u95f4\u4e5f\u8d8a\u6765\u8d8a\u957f\uff0c\u5bfc\u81f4\u5185\u5b58\u8fc7\u591a\u5f00\u9500\u548c\u65f6\u95f4\u6548\u7387\u53d8\u4f4e\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u524d\u8a00<\/strong><\/div>\n

\u5982\u679c\u8981\u5224\u65ad\u4e00\u4e2a\u5143\u7d20\u662f\u5426\u5728\u96c6\u5408\u4e2d\uff0c\u4e00\u822c\u7684\u601d\u8def\u662f\u4fdd\u5b58\u96c6\u5408\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u7136\u540e\u901a\u8fc7\u6bd4\u8f83\u6765\u786e\u5b9a\u3002\u94fe\u8868\u3001\u6811\u3001\u54c8\u5e0c\u8868\uff08\u4e5f\u53eb\u54c8\u5e0c\u8868\u3001\u54c8\u5e0c\u8868\uff09\u7b49\u6570\u636e\u7ed3\u6784\u90fd\u662f\u8fd9\u79cd\u65b9\u5f0f\uff0c\u5b58\u50a8\u4f4d\u7f6e\u8981\u4e48\u662f\u78c1\u76d8\uff0c\u8981\u4e48\u662f\u5185\u5b58\u3002\u5f88\u591a\u65f6\u5019\uff0c\u8981\u4e48\u65f6\u95f4\u6362\u7a7a\u95f4\uff0c\u8981\u4e48\u7a7a\u95f4\u6362\u65f6\u95f4\u3002<\/p>\n

\u5728\u5bf9\u54cd\u5e94\u65f6\u95f4\u8981\u6c42\u6bd4\u8f83\u4e25\u683c\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u6211\u4eec\u6709\u91cc\u9762\uff0c\u90a3\u4e48\u968f\u7740\u96c6\u5408\u4e2d\u5143\u7d20\u6570\u91cf\u7684\u589e\u52a0\uff0c\u6211\u4eec\u9700\u8981\u7684\u5b58\u50a8\u7a7a\u95f4\u8d8a\u6765\u8d8a\u5927\uff0c\u68c0\u7d22\u65f6\u95f4\u4e5f\u8d8a\u6765\u8d8a\u957f\uff0c\u5bfc\u81f4\u5185\u5b58\u8fc7\u591a\u5f00\u9500\u548c\u65f6\u95f4\u6548\u7387\u53d8\u4f4e\u3002<\/p>\n

\u8fd9\u65f6\u5019\u9700\u8981\u8003\u8651\u7684\u95ee\u9898\u662f\uff0c\u5728\u6570\u636e\u91cf\u6bd4\u8f83\u5927\u7684\u60c5\u51b5\u4e0b\uff0c\u65e2\u80fd\u6ee1\u8db3\u65f6\u95f4\u8981\u6c42\uff0c\u53c8\u80fd\u6ee1\u8db3\u7a7a\u95f4\u8981\u6c42\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4e00\u79cd\u65f6\u95f4\u548c\u7a7a\u95f4\u6d88\u8017\u90fd\u6bd4\u8f83\u5c0f\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u3002\u5e03\u9686\u8fc7\u6ee4\u5668\u662f\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n

\u4ec0\u4e48\u662f\u5e03\u9686\u8fc7\u6ee4\u5668\uff1f<\/strong><\/div>\n

Bloom Filter, \u5e03\u9686\u8fc7\u6ee4\u5668\u7531 Bloom\u4e8e 1970 \u5e74\u63d0\u51fa\u3002\u5b83\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u957f\u4e8c\u8fdb\u5236\u5411\u91cf\u548c\u4e00\u7cfb\u5217\u968f\u673a\u6620\u5c04\u51fd\u6570, \u5e03\u9686\u8fc7\u6ee4\u5668\u53ef\u7528\u4e8e\u68c0\u7d22\u5143\u7d20\u662f\u5426\u5728\u96c6\u5408\u4e2d\u3002\u5176\u4f18\u70b9\u662f\u7a7a\u95f4\u6548\u7387\u548c\u67e5\u8be2\u65f6\u95f4\u8fdc\u8d85\u4e00\u822c\u7b97\u6cd5\uff0c\u7f3a\u70b9\u662f\u5b58\u5728\u4e00\u5b9a\u7684\u8bef\u8bc6\u522b\u7387\u548c\u5220\u9664\u96be\u5ea6\u3002\u6839\u636e\u5b83\u7684\u7279\u6027\uff0c\u5e94\u7528\u573a\u666f\u6709\u5982\u4e0b\uff1a<\/p>\n

  • \u722c\u866b\u8fc7\u6ee4\u3002<\/li>\n
  • \u90ae\u7bb1\u5783\u573e\u90ae\u4ef6\u8fc7\u6ee4\u3002<\/li>\n
  • \u9ed1\u540d\u5355\u8fc7\u6ee4\u3002<\/li>\n
  • \u5927\u6570\u636e\u53bb\u91cd\u3002<\/li>\n
  • \u9632\u6b62\u7f13\u5b58\u7a7f\u900f\u3002<\/li>\n
  • \u5e03\u9686\u8fc7\u6ee4\u5668\u539f\u7406<\/li>\n

    \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u539f\u7406\u662f\u5f53\u4e00\u4e2a\u5143\u7d20\u52a0\u5165\u5230\u96c6\u5408\u4e2d\u65f6\uff0c\u901a\u8fc7K\u4e2a\u54c8\u5e0c\u51fd\u6570\u5c06\u8be5\u5143\u7d20\u6620\u5c04\u5230\u4e00\u4e2a\u4f4d\u6570\u7ec4\u4e2d\u7684K\u4e2a\u70b9\uff0c\u5e76\u5c06\u5b83\u4eec\u7f6e\u4e3a1\u3002\u68c0\u7d22\u65f6\uff0c\u6211\u4eec\u53ea\u9700\u8981\u770b\u8fd9\u4e9b\u70b9\u662f\u5426\u90fd\u4e3a1\uff0c\u5c31\u53ef\u4ee5\uff08\u5927\u6982\uff09\u77e5\u9053\u5b83\u662f\u5426\u5b58\u5728\u4e8e\u96c6\u5408\u4e2d\u3002\u5982\u679c\u8fd9\u4e9b\u70b9\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u67090\uff0c\u5219\u68c0\u67e5\u7684\u5143\u7d20\u4e00\u5b9a\u4e0d\u5b58\u5728\u3002\u5982\u679c\u5b83\u4eec\u90fd\u662f1\uff0c\u5219\u88ab\u9009\u4e2d\u7684\u5143\u7d20\u5f88\u53ef\u80fd\u5728\u90a3\u91cc\u3002<\/p>\n

    Bloom Filter\u4e0e\u5355\u4e00\u54c8\u5e0c\u51fd\u6570Bit-Map\u7684\u533a\u522b\u5728\u4e8e\uff0cBloom Filter\u4f7f\u7528k\u4e2a\u54c8\u5e0c\u51fd\u6570\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u5bf9\u5e94k\u4e2abits\uff0c\u4ece\u800c\u964d\u4f4e\u78b0\u649e\u6982\u7387\u3002<\/p>\n

    \"\"<\/p>\n

    \u7531\u4e8eBloom filter\u53ea\u5b58\u50a80\u548c1\u800c\u4e0d\u5b58\u50a8\u5177\u4f53\u503c\uff0c\u6240\u4ee5\u5728\u4e00\u4e9b\u673a\u5bc6\u573a\u5408\u5177\u6709\u5148\u5929\u4f18\u52bf\u3002\u4f4d\u56fe\u7684\u6bcf\u4e00\u4f4d\u90fd\u662f\u4e00\u4e2a\u4f4d\uff0c\u6240\u4ee5\u901a\u8fc7\u4f4d\u56fe\u670910\u4ebf\u4e2a\u4f4d\u7f6e\uff0c\u4f4d\u56fe\u7684\u5927\u5c0f\u4e3a0.12G\uff0c\u63d2\u5165\u548c\u67e5\u8be2\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(k),k\u662f\u54c8\u5e0c\u51fd\u6570\u7684\u4e2a\u6570\u3002<\/p>\n

    \u5e03\u9686\u8fc7\u6ee4\u5668\u7684\u95ee\u9898<\/strong><\/div>\n

    \u5e03\u9686\u8fc7\u6ee4\u5668\u4e4b\u6240\u4ee5\u80fd\u591f\u5728\u65f6\u95f4\u548c\u7a7a\u95f4\u4e0a\u53d6\u5f97\u6bd4\u8f83\u9ad8\u7684\u6548\u7387\uff0c\u662f\u56e0\u4e3a\u5b83\u727a\u7272\u4e86\u5224\u65ad\u7684\u51c6\u786e\u6027\u548c\u5220\u9664\u7684\u4fbf\u5229\u6027\u3002<\/p>\n

    1.\u5224\u65ad\u9519\u8bef
    \n\u6709\u53ef\u80fd\u8981\u627e\u7684\u5143\u7d20\u4e0d\u5728\u5bb9\u5668\u4e2d\uff0c\u4f46\u662f\u6563\u5217\u540e\u5f97\u5230\u7684k\u4e2a\u4f4d\u7f6e\u90fd\u662f1\u3002\u5982\u679c\u5e03\u9686\u8fc7\u6ee4\u5668\u4e2d\u5b58\u50a8\u4e86\u9ed1\u540d\u5355\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u767d\u540d\u5355\u6765\u5b58\u50a8\u53ef\u80fd\u88ab\u8bef\u5224\u7684\u5143\u7d20\u3002<\/p>\n

    \u5bf9\u4e8e\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0\u4f4d\u56fe\u6570\u7ec4\u7684\u5927\u5c0f\uff08\u4f4d\u56fe\u6570\u7ec4\u8d8a\u5927\uff0c\u5360\u7528\u7684\u5185\u5b58\u8d8a\u5927\uff09\u548c\u51cf\u5c11\u54c8\u5e0c\u51b2\u7a81\u6765\u89e3\u51b3\u3002\u4f46\u7f3a\u70b9\u662f\u4f1a\u589e\u52a0\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u3002<\/p>\n

    \u53e6\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u662f\u589e\u52a0\u6563\u5217\u51fd\u6570\u7684\u6570\u91cf\u5e76\u51cf\u5c11\u6563\u5217\u51b2\u7a81\u3002\u5982\u679c\u540c\u4e00\u4e2a\u952e\u503c\u7b49\u4e8e\u4e00\u4e2a\u51fd\u6570\uff0c\u7ecf\u8fc7\u4e24\u4e2a\u6216\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u5f97\u5230\u76f8\u7b49\u7ed3\u679c\u7684\u6982\u7387\u81ea\u7136\u4f1a\u964d\u4f4e\u3002\u7136\u800c\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u8ba1\u7b97\u6548\u7387\u7684\u964d\u4f4e\uff0c\u56e0\u4e3a\u65f6\u95f4\u590d\u6742\u5ea6\u9000\u5316\u4e3aO(hash times)\u3002<\/p>\n

    2.\u96be\u4ee5\u53bb\u9664
    \n\u653e\u7f6e\u5728\u5bb9\u5668\u4e2d\u7684\u5143\u7d20\u6620\u5c04\u5230\u4f4d\u6570\u7ec4\u7684 k \u4e2a\u4f4d\u7f6e\u4e2d\u7684 1\u3002\u5220\u9664\u7684\u65f6\u5019\u4e0d\u80fd\u7b80\u5355\u7684\u76f4\u63a5\u8bbe\u7f6e\u4e3a0\uff0c\u8fd9\u6837\u53ef\u80fd\u4f1a\u5f71\u54cd\u5176\u4ed6\u5143\u7d20\u7684\u5224\u65ad\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u200b\u200bCounting Bloom Filter\u200b\u200b\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n

    Java\u4e2d\u5982\u4f55\u4f7f\u7528\u5e03\u9686\u8fc7\u6ee4\u5668<\/strong><\/div>\n

    google\u7684guava\u5c31\u63d0\u4f9b\u4e86\u8fd9\u6837\u7684API.
    \n\"\"
    \n\u7f16\u5199\u6d4b\u8bd5\u4ee3\u7801<\/p>\n

    \r\nimport com.google.common.base.Charsets;\r\nimport com.google.common.hash.BloomFilter;\r\nimport com.google.common.hash.Funnels;\r\n \r\npublic class GuavaBloomFilter {\r\n    public static void main(String[] args) {\r\n        int total = 1000000;\r\n        \/\/ default false positive ratefpp0.03\r\n        \/\/ fpp:There will always be a false positive rate in a Bloom filter\r\n        \/\/ Because hash collisions are impossible to avoid 100%.\r\n        \/\/ Bloom filter calls this misjudgment rate false positive probability\uff0cabbreviated as fpp\r\n        BloomFilter bf = BloomFilter.create(Funnels.stringFunnel(Charsets.UTF_8), total);\r\n        \/\/ Initialize the total bar data into the filter\r\n        for (int i = 0; i < total; i++) {\r\n            bf.put(\"\" + i);\r\n        }\r\n        \/\/ Determine whether the value exists in the filter\r\n        int count = 0;\r\n        for (int i = 0; i < total + 10000; i++) {\r\n            if (bf.mightContain(\"\" + i)) {\r\n                count++;\r\n            }\r\n        }\r\n        System.out.println(\"Matched quantity \" + count);\r\n \r\n        \/\/ Specified misjudgment rate: 1\/10,000 to improve matching accuracy\r\n        BloomFilter<\/charsequence> bfWithFpp = BloomFilter.create(Funnels.stringFunnel(Charsets.UTF_8), total, 0.0001);\r\n        for (int i = 0; i < total; i++) {\r\n            bfWithFpp.put(\"\" + i);\r\n        }\r\n        int countFpp = 0;\r\n        for (int i = 0; i < total + 10000; i++) {\r\n            if (bfWithFpp.mightContain(\"\" + i)) {\r\n                countFpp++;\r\n            }\r\n        }\r\n        \/\/The smaller the value of the false positive rate fpp\r\n        \/\/ the higher the matching accuracy.\r\n        \/\/ When the value of the false positive rate fpp is reduced\r\n        \/\/ the storage space required is also larger\r\n        \/\/ Therefore, in actual use, \r\n        \/\/ a trade-off needs to be made between the false positive rate and the storage space.\r\n        System.out.println(\"The specified false positive rate has matched the number \" + countFpp);\/\/ (1000001 - 1000000)\/(1000000 + 10000) * 100 \u2248 0.0001\r\n    }\r\n}<\/charsequence>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

    \u5982\u679c\u8981\u5224\u65ad\u4e00\u4e2a\u5143\u7d20\u662f\u5426\u5728\u96c6\u5408\u4e2d\uff0c\u4e00\u822c\u7684\u601d\u8def\u662f\u4fdd\u5b58\u96c6\u5408\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u7136\u540e\u901a\u8fc7\u6bd4\u8f83\u6765\u786e\u5b9a\u3002\u94fe\u8868\u3001\u6811\u3001\u54c8\u5e0c\u8868\uff08\u4e5f\u53eb\u54c8 […]<\/p>\n","protected":false},"author":1898,"featured_media":264702,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[594],"class_list":["post-263250","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-594"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=263250"}],"version-history":[{"count":8,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263250\/revisions"}],"predecessor-version":[{"id":264703,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263250\/revisions\/264703"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/264702"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=263250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=263250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=263250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}