carl  24.04
Computer ARithmetic Library
MonomialPool.cpp
Go to the documentation of this file.
1 /**
2  * @file MonomialPool.cpp
3  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
4  */
5 
6 #include "MonomialPool.h"
7 
9 
10 namespace carl {
11 
13  CARL_LOG_TRACE("carl.core.monomial", c << ", " << totalDegree);
14 
16 
17  underlying_set::insert_commit_data insert_data;
18  auto res = mPool.insert_check(c, content_hash(), content_equal(), insert_data);
19  if (!res.second) {
20  return res.first->mWeakPtr.lock();
21  } else {
22  auto shared = std::shared_ptr<Monomial>(new Monomial(c, totalDegree));
23  shared.get()->mId = mIDs.get();
24  shared.get()->mWeakPtr = shared;
25  mPool.insert_commit(*shared.get(), insert_data);
26  check_rehash();
27  return shared;
28  }
29 }
30 
32  CARL_LOG_TRACE("carl.core.monomial", _var << ", " << _exp);
33  return add(Monomial::Content(1, std::make_pair(_var, _exp)), _exp);
34 }
35 
36 Monomial::Arg MonomialPool::create(std::vector<std::pair<Variable, exponent>>&& _exponents, exponent _totalDegree) {
37  CARL_LOG_TRACE("carl.core.monomial", _exponents << ", " << _totalDegree);
38  return add(std::move(_exponents), _totalDegree);
39 }
40 
41 Monomial::Arg MonomialPool::create(const std::initializer_list<std::pair<Variable, exponent>>& _exponents) {
42  auto exp = Monomial::Content(_exponents);
43  CARL_LOG_TRACE("carl.core.monomial", _exponents);
44  std::sort(exp.begin(), exp.end(), [](const auto& p1, const auto& p2) { return p1.first < p2.first; });
45  return add(std::move(exp));
46 }
47 
48 Monomial::Arg MonomialPool::create(std::vector<std::pair<Variable, exponent>>&& _exponents) {
49  CARL_LOG_TRACE("carl.core.monomial", _exponents);
50  return add(std::move(_exponents), 0);
51 }
52 
53 } // end namespace carl
#define MONOMIAL_POOL_LOCK_GUARD
Definition: MonomialPool.h:61
#define CARL_LOG_TRACE(channel, msg)
Definition: carl-logging.h:44
carl is the main namespace for the library.
std::size_t exponent
Type of an exponent.
Definition: Monomial.h:29
Interval< Number > exp(const Interval< Number > &i)
Definition: Exponential.h:10
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
The general-purpose monomials.
Definition: Monomial.h:59
std::shared_ptr< const Monomial > Arg
Definition: Monomial.h:62
std::vector< std::pair< Variable, std::size_t > > Content
Definition: Monomial.h:63
underlying_set mPool
The pool.
Definition: MonomialPool.h:52
Monomial::Arg create(Variable _var, exponent _exp)
Creates a monomial from a variable and an exponent.
IDPool mIDs
id allocator
Definition: MonomialPool.h:46
Monomial::Arg add(Monomial::Content &&c, exponent totalDegree=0)
std::size_t get()
Definition: IDPool.h:30