memgraph/include/data_structures/concurrent/concurrent_bloom_map.hpp
sale 9b03fd1f04 Added Basic BloomFilter and BloomConcurrentMap
Summary: Added Basic BloomFilter and BloomConcurrentMap

Test Plan: manual

Reviewers: buda

Subscribers: buda

Maniphest Tasks: T115

Differential Revision: https://memgraph.phacility.com/D15
2016-12-05 09:03:11 +00:00

37 lines
877 B
C++

#pragma once
#include "data_structures/concurrent/common.hpp"
#include "data_structures/concurrent/skiplist.hpp"
#include "data_structures/concurrent/concurrent_map.hpp"
using std::pair;
template <class Key, class Value, class BloomFilter>
class ConcurrentBloomMap {
using item_t = Item<Key, Value>;
using list_it = typename SkipList<item_t>::Iterator;
private:
ConcurrentMap<Key, Value> map_;
BloomFilter filter_;
public:
ConcurrentBloomMap(BloomFilter filter) : filter_(filter) {}
std::pair<list_it, bool> insert(const Key &key, const Value &data) {
filter_.insert(key);
auto accessor = std::move(map_.access());
return accessor.insert(key, data);
}
bool contains(const Key &key) {
if (!filter_.contains(key)) return false;
auto accessor = map_.access();
return accessor.contains(key);
}
};