2016-12-05 16:59:07 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "data_structures/concurrent/common.hpp"
|
|
|
|
#include "data_structures/concurrent/concurrent_map.hpp"
|
2017-02-18 18:54:37 +08:00
|
|
|
#include "data_structures/concurrent/skiplist.hpp"
|
2016-12-05 16:59:07 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
private:
|
|
|
|
ConcurrentMap<Key, Value> map_;
|
|
|
|
BloomFilter filter_;
|
2016-12-05 16:59:07 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
public:
|
|
|
|
ConcurrentBloomMap(BloomFilter filter) : filter_(filter) {}
|
2016-12-05 16:59:07 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
std::pair<list_it, bool> insert(const Key &key, const Value &data) {
|
|
|
|
filter_.insert(key);
|
2016-12-05 16:59:07 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
auto accessor = std::move(map_.access());
|
2016-12-05 16:59:07 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
return accessor.insert(key, data);
|
|
|
|
}
|
2016-12-05 16:59:07 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
bool contains(const Key &key) {
|
|
|
|
if (!filter_.contains(key)) return false;
|
2016-12-05 16:59:07 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
auto accessor = map_.access();
|
|
|
|
return accessor.contains(key);
|
|
|
|
}
|
2016-12-05 16:59:07 +08:00
|
|
|
};
|