int bloom_filter_t::insert(const void* key, uint32_t key_len) { if(0 >= key_len || NULL == key) { return -1; } uint64_t byte_idx = 0; uint32_t bit_idx = 0; for(size_t i = 0; i < _seeds.size(); ++i) { _calc_bit_idx(murmur_hash_64A(key, key_len, _seeds[i]), byte_idx, bit_idx); _byte_arr[byte_idx] |= (1 << bit_idx); } return 0; }
bool bloom_filter_t::may_contain(const void* key, uint32_t key_len) { uint64_t byte_idx = 0; uint32_t bit_idx = 0; for(size_t i = 0; i < _seeds.size(); ++i) { _calc_bit_idx(murmur_hash_64A(key, key_len, _seeds[i]), byte_idx, bit_idx); if((_byte_arr[byte_idx] & (1 << bit_idx)) != (1 << bit_idx)) { return false; } } return true; }
int64_t f_hphp_murmurhash(CStrRef key, int len, int seed) { len = std::max(std::min(len, key.size()), 0); return murmur_hash_64A(key, len, seed); }
int64_t HHVM_FUNCTION(hphp_murmurhash, const String& key, int64_t len, int64_t seed) { len = std::max<int64_t>(std::min<int64_t>(len, key.size()), 0); return murmur_hash_64A(key.data(), len, seed); }