7 #include <boost/intrusive/unordered_set.hpp>
12 template<
class Content>
15 template<
class Content>
20 std::weak_ptr<LocalPoolElementWrapper<Content>>
m_weak_ptr;
21 std::shared_ptr<LocalPool<Content>>
m_pool;
25 template <
typename ...Args>
40 template<
class Content>
42 return wrapper.
content().key().hash();
45 template<
class Content>
50 template<
class Content>
54 template<
typename Key>
57 return data ==
content.content().key();
65 template<
typename Key>
77 using UnderlyingSet = boost::intrusive::unordered_set<LocalPoolElementWrapper<Content>>;
84 mutable std::recursive_mutex m_mutex;
85 #define DATASTRUCTURES_POOL_LOCK_GUARD std::lock_guard<std::recursive_mutex> lock(m_mutex);
86 #define DATASTRUCTURES_POOL_LOCK m_mutex.lock();
87 #define DATASTRUCTURES_POOL_UNLOCK m_mutex.unlock();
89 #define DATASTRUCTURES_POOL_LOCK_GUARD
90 #define DATASTRUCTURES_POOL_LOCK
91 #define DATASTRUCTURES_POOL_UNLOCK
97 auto new_buckets =
new typename UnderlyingSet::bucket_type[rehash.second];
98 m_pool.rehash(
typename UnderlyingSet::bucket_traits(new_buckets, rehash.second));
113 template<
typename Key>
116 assert(pool.get() ==
this);
118 typename UnderlyingSet::insert_commit_data insert_data;
121 return res.first->m_weak_ptr.lock();
123 auto shared = std::make_shared<LocalPoolElementWrapper<Content>>(pool, std::move(c));
125 shared.get()->m_weak_ptr = shared;
126 m_pool.insert_commit(*shared.get(), insert_data);
137 auto it =
m_pool.find(*c);
138 assert(it !=
m_pool.end());
145 template<
class Content>
147 std::shared_ptr<LocalPoolElementWrapper<Content>>
m_content;
150 template<
typename Key>
#define DATASTRUCTURES_POOL_LOCK_GUARD
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)
pool::RehashPolicy m_rehash_policy
std::shared_ptr< LocalPoolElementWrapper< Content > > add(std::shared_ptr< LocalPool< Content >> pool, Key &&c)
std::unique_ptr< typename UnderlyingSet::bucket_type[]> m_pool_buckets
UnderlyingSet m_pool
The pool.
void free(const LocalPoolElementWrapper< Content > *c)
LocalPool(std::size_t _capacity=1000)
boost::intrusive::unordered_set< LocalPoolElementWrapper< Content > > UnderlyingSet
std::shared_ptr< LocalPool< Content > > m_pool
std::weak_ptr< LocalPoolElementWrapper< Content > > m_weak_ptr
LocalPoolElementWrapper(std::shared_ptr< LocalPool< Content >> pool, Args &&...args)
~LocalPoolElementWrapper()
const Content & content() const
bool operator()(const Key &data, const LocalPoolElementWrapper< Content > &content) const
bool operator()(const LocalPoolElementWrapper< Content > &content, const Key &data) const
std::size_t operator()(const Key &data) const
LocalPoolElement(std::shared_ptr< LocalPool< Content >> &pool, Key &&k)
std::shared_ptr< LocalPoolElementWrapper< Content > > m_content
const Content * operator->() const
bool operator==(const LocalPoolElement &other) const
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