#pragma once #include "data_structures/concurrent/common.hpp" #include "data_structures/concurrent/skiplist.hpp" using std::pair; template class ConcurrentMap { typedef Item item_t; typedef SkipList list; typedef typename SkipList::Iterator list_it; typedef typename SkipList::ConstIterator list_it_con; public: ConcurrentMap() {} class Accessor : public AccessorBase { friend class ConcurrentMap; using AccessorBase::AccessorBase; private: using AccessorBase::accessor; public: std::pair insert(const K &key, const T &data) { return accessor.insert(item_t(key, data)); } std::pair insert(const K &key, T &&data) { return accessor.insert(item_t(key, std::move(data))); } std::pair insert(K &&key, T &&data) { return accessor.insert( item_t(std::forward(key), std::forward(data))); } template std::pair emplace(const K &key, std::tuple first_args, std::tuple second_args) { return accessor.emplace( key, std::piecewise_construct, std::forward>(first_args), std::forward>(second_args)); } list_it_con find(const K &key) const { return accessor.find(key); } list_it find(const K &key) { return accessor.find(key); } 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); } bool contains(const K &key) const { return this->find(key) != this->end(); } bool remove(const K &key) { return accessor.remove(key); } }; Accessor access() { return Accessor(&skiplist); } const Accessor access() const { return Accessor(&skiplist); } private: list skiplist; };