8 #include <boost/intrusive/unordered_set.hpp>
13 template<
class Content>
16 template<
class Content>
25 template <
typename ...Args>
40 template<
class Content>
42 return wrapper.
content().key().hash();
45 template<
class Content>
50 template<
class Content>
55 template<
typename Key>
58 return data ==
content.content().key();
66 template<
typename Key>
78 using UnderlyingSet = boost::intrusive::unordered_set<PoolElementWrapper<Content>>;
85 mutable std::recursive_mutex m_mutex;
86 #define DATASTRUCTURES_POOL_LOCK_GUARD std::lock_guard<std::recursive_mutex> lock(m_mutex);
87 #define DATASTRUCTURES_POOL_LOCK m_mutex.lock();
88 #define DATASTRUCTURES_POOL_UNLOCK m_mutex.unlock();
90 #define DATASTRUCTURES_POOL_LOCK_GUARD
91 #define DATASTRUCTURES_POOL_LOCK
92 #define DATASTRUCTURES_POOL_UNLOCK
98 auto new_buckets =
new typename UnderlyingSet::bucket_type[rehash.second];
99 m_pool.rehash(
typename UnderlyingSet::bucket_traits(new_buckets, rehash.second));
106 explicit Pool(std::size_t _capacity = 1000)
117 template<
typename Key>
118 std::shared_ptr<PoolElementWrapper<Content>>
add(Key&& c) {
121 typename UnderlyingSet::insert_commit_data insert_data;
124 return res.first->m_weak_ptr.lock();
126 auto shared = std::make_shared<PoolElementWrapper<Content>>(std::move(c));
128 shared.get()->m_weak_ptr = shared;
129 m_pool.insert_commit(*shared.get(), insert_data);
140 auto it =
m_pool.find(*c);
141 assert(it !=
m_pool.end());
148 template<
class Content>
153 template<
typename Key>
Coeff content(const UnivariatePolynomial< Coeff > &p)
The content of a polynomial is the gcd of the coefficients of the normal part of a polynomial.
std::size_t hash_value(const LocalPoolElementWrapper< Content > &wrapper)
bool operator==(const LocalPoolElementWrapper< Content > &c1, const LocalPoolElementWrapper< Content > &c2)
auto & get(const std::string &name)
std::size_t largestID() const
void free(std::size_t id)
std::unique_ptr< typename UnderlyingSet::bucket_type[]> m_pool_buckets
pool::RehashPolicy m_rehash_policy
std::shared_ptr< PoolElementWrapper< Content > > add(Key &&c)
Pool(std::size_t _capacity=1000)
boost::intrusive::unordered_set< PoolElementWrapper< Content > > UnderlyingSet
UnderlyingSet m_pool
The pool.
void free(const PoolElementWrapper< Content > *c)
const Content & content() const
PoolElementWrapper(Args &&...args)
std::weak_ptr< PoolElementWrapper< Content > > m_weak_ptr
bool operator()(const Key &data, const PoolElementWrapper< Content > &content) const
bool operator()(const PoolElementWrapper< Content > &content, const Key &data) const
std::size_t operator()(const Key &data) const
const Content & operator*() const
std::shared_ptr< PoolElementWrapper< Content > > m_content
const Content * operator->() const
const Content & operator()() const
Mimics stdlibs default rehash policy for hashtables.
std::pair< bool, std::size_t > needRehash(std::size_t numBuckets, std::size_t numElements) const
Base class that implements a singleton.
static Pool< Content > & getInstance()
Returns the single instance of this class by reference.
#define DATASTRUCTURES_POOL_LOCK_GUARD