Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Bloom filters: implementation cod

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

#pragma once#include #include "BitMap.h"struct HashFunc1{ size_t BKDRHash(const char *str) { register size_t hash = 0; while (size_t ch = (size_t)*str++) { hash = hash * 131 + ch; // 也可以乘以31、131 return hash; } } size_t operator()(const string& s) { return BKDRHash(s.c_str()); }};struct HashFunc2{ size_t SDBMHash(const char *str) { register size_t hash = 0; while (size_t ch = (size_t)*str++) { hash = 65599 * hash + ch; } return hash; } size_t operator()(const string& s) { return SDBMHash(s.c_str()); }};struct HashFunc3{ size_t RSHash(const char *str) { register size_t hash = 0; size_t magic = 63689; while (size_t ch = (size_t)*str++) { hash = hash * magic + ch; magic *= 378551; } return hash; } size_t operator()(const string& s) { return RSHash(s.c_str()); }};struct HashFunc4{ size_t APHash(const char *str) { register size_t hash = 0; size_t ch; for (long i = 0; ch = (size_t)*str++; i++) { if ((i & 1) == 0) { hash ^= ((hash > 3)); } else { hash ^= (~((hash > 5))); } } return hash; } size_t operator()(const string& s) { return APHash(s.c_str()); }};struct HashFunc5{ size_t JSHash(const char *str) { if(!*str) return 0; register size_t hash = 1315423911; while (size_t ch = (size_t)*str++) { hash ^= ((hash > 2)); } return hash; } size_t operator()(const string& s) { return JSHash(s.c_str()); }};templateclass BloomFilter{public: BloomFilter(size_t size) :_bitMap(size) ,_capacity(size) {} void Set(const K& key) { size_t index1 = __HashFunc1()(key); size_t index2 = __HashFunc2()(key); size_t index3 = __HashFunc3()(key); size_t index4 = __HashFunc4()(key); size_t index5 = __HashFunc5()(key); cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report