7 #ifndef SYMENGINE_DICT_H
8 #define SYMENGINE_DICT_H
9 #include <symengine/mp_class.h>
14 #include <unordered_map>
16 #include <unordered_set>
28 struct RCPBasicKeyLess;
29 struct RCPIntegerKeyLess;
31 bool eq(
const Basic &,
const Basic &);
32 typedef uint64_t hash_t;
33 typedef std::unordered_map<RCP<const Basic>, RCP<const Number>, RCPBasicHash,
36 typedef std::unordered_map<short, RCP<const Basic>> umap_short_basic;
37 typedef std::unordered_map<int, RCP<const Basic>> umap_int_basic;
38 typedef std::unordered_map<RCP<const Basic>, RCP<const Basic>, RCPBasicHash,
41 typedef std::unordered_set<RCP<const Basic>, RCPBasicHash, RCPBasicKeyEq>
44 typedef std::vector<int> vec_int;
45 typedef std::vector<RCP<const Basic>> vec_basic;
46 typedef std::vector<RCP<const Integer>> vec_integer;
47 typedef std::vector<unsigned int> vec_uint;
48 typedef std::vector<integer_class> vec_integer_class;
49 typedef std::vector<RCP<const Symbol>> vec_sym;
50 typedef std::set<RCP<const Basic>, RCPBasicKeyLess> set_basic;
51 typedef std::multiset<RCP<const Basic>, RCPBasicKeyLess> multiset_basic;
52 typedef std::map<vec_uint, unsigned long long int> map_vec_uint;
53 typedef std::map<vec_uint, integer_class> map_vec_mpz;
54 typedef std::map<RCP<const Basic>, RCP<const Number>, RCPBasicKeyLess>
56 typedef std::map<RCP<const Basic>, RCP<const Basic>, RCPBasicKeyLess>
58 typedef std::map<RCP<const Integer>, unsigned, RCPIntegerKeyLess>
60 typedef std::map<unsigned, integer_class> map_uint_mpz;
61 typedef std::map<unsigned, rational_class> map_uint_mpq;
62 typedef std::map<int, Expression> map_int_Expr;
63 typedef std::unordered_map<RCP<const Basic>,
unsigned int, RCPBasicHash,
66 typedef std::vector<std::pair<RCP<const Basic>, RCP<const Basic>>> vec_pair;
70 hash_t operator()(
const T &v)
const;
73 typedef std::unordered_map<vec_uint, integer_class, vec_hash<vec_uint>>
75 typedef std::unordered_map<vec_int, integer_class, vec_hash<vec_int>>
77 typedef std::unordered_map<vec_int, Expression, vec_hash<vec_int>>
82 template <
typename T1,
typename T2,
typename T3>
83 inline void insert(T1 &m,
const T2 &first,
const T3 &second)
85 m.insert(std::pair<T2, T3>(first, second));
90 template <
class M,
typename C = std::less<
typename M::key_type>>
91 std::vector<typename M::key_type> sorted_keys(
const M &d)
93 std::vector<typename M::key_type> v;
98 std::sort(v.begin(), v.end(), C());
102 template <
bool B,
class T =
void>
103 using enable_if_t =
typename std::enable_if<B, T>::type;
105 template <
typename T,
typename U>
106 inline bool unified_eq(
const std::pair<T, U> &a,
const std::pair<T, U> &b)
108 return unified_eq(a.first, b.first) and unified_eq(a.second, b.second);
111 template <typename T, typename U>
112 inline
bool unified_eq(const std::set<T, U> &a, const std::set<T, U> &b)
114 return ordered_eq(a, b);
117 template <
typename T,
typename U>
118 inline bool unified_eq(
const std::multiset<T, U> &a,
119 const std::multiset<T, U> &b)
121 return ordered_eq(a, b);
124 template <
typename K,
typename V,
typename C>
125 inline bool unified_eq(
const std::map<K, V, C> &a,
const std::map<K, V, C> &b)
127 return ordered_eq(a, b);
130 template <
typename K,
typename V,
typename H,
typename E>
131 inline bool unified_eq(
const std::unordered_map<K, V, H, E> &a,
132 const std::unordered_map<K, V, H, E> &b)
137 template <
typename T,
typename U,
138 typename = enable_if_t<std::is_base_of<Basic, T>::value
139 and std::is_base_of<Basic, U>::value>>
140 inline bool unified_eq(
const RCP<const T> &a,
const RCP<const U> &b)
145 template <
typename T,
146 typename = enable_if_t<std::is_arithmetic<T>::value
147 or std::is_same<T, integer_class>::value>>
148 inline bool unified_eq(
const T &a,
const T &b)
163 if (a.size() != b.size())
166 for (
const auto &p : a) {
168 auto f = b.find(p.first);
171 if (not unified_eq(p.second, f->second))
178 inline bool ordered_eq(
const T &A,
const T &B)
181 if (A.size() != B.size())
186 for (; a != A.end(); ++a, ++b) {
187 if (not unified_eq(*a, *b))
193 template <
typename T>
194 inline bool unified_eq(
const std::vector<T> &a,
const std::vector<T> &b)
196 return ordered_eq(a, b);
201 template <
typename T,
202 typename = enable_if_t<std::is_arithmetic<T>::value
203 or std::is_same<T, integer_class>::value
204 or std::is_same<T, rational_class>::value>>
209 return a < b ? -1 : 1;
212 template <
typename T,
typename U,
213 typename = enable_if_t<std::is_base_of<Basic, T>::value
214 and std::is_base_of<Basic, U>::value>>
215 inline int unified_compare(
const RCP<const T> &a,
const RCP<const U> &b)
217 return a->__cmp__(*b);
221 inline int ordered_compare(
const T &A,
const T &B);
223 template <
typename T>
224 inline int unified_compare(
const std::vector<T> &a,
const std::vector<T> &b)
226 return ordered_compare(a, b);
229 template <
typename T,
typename U>
230 inline int unified_compare(
const std::set<T, U> &a,
const std::set<T, U> &b)
232 return ordered_compare(a, b);
235 template <
typename T,
typename U>
237 const std::multiset<T, U> &b)
239 return ordered_compare(a, b);
242 template <
typename T,
typename U>
243 inline int unified_compare(
const std::pair<T, U> &a,
const std::pair<T, U> &b)
253 template <
typename K,
typename V,
typename C>
255 const std::map<K, V, C> &b)
257 return ordered_compare(a, b);
260 template <
typename K,
typename V,
typename H,
typename E>
262 const std::unordered_map<K, V, H, E> &b)
264 return unordered_compare(a, b);
268 inline int ordered_compare(
const T &A,
const T &B)
271 if (A.size() != B.size())
272 return A.size() < B.size() ? -1 : 1;
277 for (; a != A.end(); ++a, ++b) {
285 template <
class M,
typename C = std::less<
typename M::key_type>>
286 inline int unordered_compare(
const M &a,
const M &b)
289 if (a.size() != b.size())
290 return a.size() < b.size() ? -1 : 1;
292 std::vector<typename M::key_type> va = sorted_keys<M, C>(a);
293 std::vector<typename M::key_type> vb = sorted_keys<M, C>(b);
295 for (
unsigned int i = 0; i < va.size() && i < vb.size(); i++) {
296 bool s = C()(va[i], vb[i]);
299 s = C()(vb[i], va[i]);
314 std::ostream &
operator<<(std::ostream &out,
const SymEngine::umap_basic_num &d);
315 std::ostream &
operator<<(std::ostream &out,
const SymEngine::map_basic_num &d);
317 const SymEngine::map_basic_basic &d);
319 const SymEngine::umap_basic_basic &d);
320 std::ostream &
operator<<(std::ostream &out,
const SymEngine::vec_basic &d);
321 std::ostream &
operator<<(std::ostream &out,
const SymEngine::set_basic &d);
322 std::ostream &
operator<<(std::ostream &out,
const SymEngine::map_int_Expr &d);
323 std::ostream &
operator<<(std::ostream &out,
const SymEngine::vec_pair &d);
Main namespace for SymEngine package.
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
void insert(T1 &m, const T2 &first, const T3 &second)
bool vec_basic_eq_perm(const vec_basic &a, const vec_basic &b)
misc functions
int unified_compare(const T &a, const T &b)
std::ostream & operator<<(std::ostream &out, const SymEngine::Basic &p)
<< Operator
bool unordered_eq(const T &a, const T &b)