2016-08-02 20:23:39 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "data_structures/concurrent/skiplist.hpp"
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class ConcurrentMultiSet
|
|
|
|
{
|
2016-08-25 22:29:45 +08:00
|
|
|
typedef SkipList<T> list;
|
|
|
|
typedef typename SkipList<T>::Iterator list_it;
|
|
|
|
typedef typename SkipList<T>::ConstIterator list_it_con;
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
public:
|
|
|
|
ConcurrentMultiSet() {}
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
class Accessor : public AccessorBase<T>
|
|
|
|
{
|
|
|
|
friend class ConcurrentMultiSet;
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
using AccessorBase<T>::AccessorBase;
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
private:
|
|
|
|
using AccessorBase<T>::accessor;
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
public:
|
|
|
|
list_it insert(const T &item)
|
|
|
|
{
|
|
|
|
return accessor.insert_non_unique(item);
|
|
|
|
}
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
list_it insert(T &&item)
|
|
|
|
{
|
|
|
|
return accessor.insert_non_unique(std::forward<T>(item));
|
|
|
|
}
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
list_it_con find(const T &item) const { return accessor.find(item); }
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
list_it find(const T &item) { return accessor.find(item); }
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
list_it_con find_or_larger(const T &item) const
|
|
|
|
{
|
|
|
|
return accessor.find_or_larger(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
list_it find_or_larger(const T &item)
|
|
|
|
{
|
|
|
|
return accessor.find_or_larger(item);
|
|
|
|
}
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
bool contains(const T &item) const
|
|
|
|
{
|
|
|
|
return this->find(item) != this->end();
|
|
|
|
}
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
bool remove(const T &item) { return accessor.remove(item); }
|
|
|
|
};
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
Accessor access() { return Accessor(&skiplist); }
|
2016-08-02 20:23:39 +08:00
|
|
|
|
2016-08-25 22:29:45 +08:00
|
|
|
const Accessor access() const { return Accessor(&skiplist); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
list skiplist;
|
2016-08-02 20:23:39 +08:00
|
|
|
};
|