memgraph/include/data_structures/concurrent/concurrent_set.hpp

55 lines
1.2 KiB
C++
Raw Normal View History

#pragma once
#include "data_structures/concurrent/common.hpp"
#include "data_structures/concurrent/skiplist.hpp"
template <class T>
class ConcurrentSet
{
2016-08-08 16:32:34 +08:00
typedef SkipList<T> list;
typedef typename SkipList<T>::Iterator list_it;
typedef typename SkipList<T>::ConstIterator list_it_con;
2016-08-08 16:32:34 +08:00
public:
ConcurrentSet() {}
2016-08-08 16:32:34 +08:00
class Accessor : public AccessorBase<T>
{
friend class ConcurrentSet;
2016-08-08 16:32:34 +08:00
using AccessorBase<T>::AccessorBase;
2016-08-08 16:32:34 +08:00
private:
using AccessorBase<T>::accessor;
2016-08-08 16:32:34 +08:00
public:
std::pair<list_it, bool> insert(const T &item)
{
return accessor.insert(item);
}
2016-08-08 16:32:34 +08:00
std::pair<list_it, bool> insert(T &&item)
{
return accessor.insert(std::forward<T>(item));
}
2016-08-08 16:32:34 +08:00
list_it_con find(const T &item) const { return accessor.find(item); }
2016-08-08 16:32:34 +08:00
list_it find(const T &item) { return accessor.find(item); }
2016-08-08 16:32:34 +08:00
bool contains(const T &item) const
{
return this->find(item) != this->end();
}
2016-08-08 16:32:34 +08:00
bool remove(const T &item) { return accessor.remove(item); }
};
2016-08-08 16:32:34 +08:00
Accessor access() { return Accessor(&skiplist); }
2016-08-08 16:32:34 +08:00
const Accessor access() const { return Accessor(&skiplist); }
2016-08-08 16:32:34 +08:00
private:
list skiplist;
};