19 template<
typename Element>
37 #define POOL_LOCK_GUARD std::lock_guard<std::mutex> lock( mMutexPool );
38 #define POOL_LOCK mMutexPool.lock();
39 #define POOL_UNLOCK mMutexPool.unlock();
47 explicit Pool(
unsigned _capacity = 10000) {
48 mPool.reserve(_capacity);
53 while(!
mPool.empty()) {
74 std::cout <<
"Pool contains:" << std::endl;
75 for(
const auto& ele :
mPool) {
76 std::cout <<
"- " << *ele << std::endl;
78 std::cout << std::endl;
89 std::pair<typename FastPointerSet<Element>::iterator,
bool>
insert(
ElementPtr _element,
bool _assertFreshness =
false)
92 auto iterBoolPair =
mPool.insert(_element);
93 assert(iterBoolPair.second || !_assertFreshness);
95 if(iterBoolPair.second) {
115 return *(
insert(_element).first);
carl is the main namespace for the library.
std::unordered_set< const T *, pointerHash< T >, pointerEqual< T > > FastPointerSet
unsigned mIdAllocator
id allocator
std::mutex mMutexPool
Mutex to avoid multiple access to the pool.
virtual void assignId(ElementPtr, std::size_t)
Assigns a unique id to the generated element.
std::pair< typename FastPointerSet< Element >::iterator, bool > insert(ElementPtr _element, bool _assertFreshness=false)
Inserts the given element into the pool, if it does not yet occur in there.
Pool(unsigned _capacity=10000)
Constructor of the pool.
FastPointerSet< Element > mPool
The formula pool.
const Element * ConstElementPtr
ConstElementPtr add(ElementPtr _element)
Adds the given element to the pool, if it does not yet occur in there.