GINAC_ASSERT(is_of_type(other, spinidx));
const spinidx &o = static_cast<const spinidx &>(other);
+ // Check dottedness first so dummy indices will end up next to each other
+ if (dotted != o.dotted)
+ return dotted ? -1 : 1;
+
int cmpval = inherited::compare_same_type(other);
if (cmpval)
return cmpval;
- // Check variance and dottedness last so dummy indices will end up next to each other
+ return 0;
+}
+
+bool idx::match(const ex & pattern, lst & repl_lst) const
+{
+ if (!is_ex_of_type(pattern, idx))
+ return false;
+ const idx &o = ex_to_idx(pattern);
+ if (!dim.is_equal(o.dim))
+ return false;
+ return value.match(o.value, repl_lst);
+}
+
+bool varidx::match(const ex & pattern, lst & repl_lst) const
+{
+ if (!is_ex_of_type(pattern, varidx))
+ return false;
+ const varidx &o = ex_to_varidx(pattern);
if (covariant != o.covariant)
- return covariant ? -1 : 1;
- if (dotted != o.dotted)
- return dotted ? -1 : 1;
+ return false;
+ return inherited::match(pattern, repl_lst);
+}
- return 0;
+bool spinidx::match(const ex & pattern, lst & repl_lst) const
+{
+ if (!is_ex_of_type(pattern, spinidx))
+ return false;
+ const spinidx &o = ex_to_spinidx(pattern);
+ if (dotted != o.dotted)
+ return false;
+ return inherited::match(pattern, repl_lst);
}
ex idx::subs(const lst & ls, const lst & lr, bool no_pattern) const
return is_dummy_pair(ex_to_idx(e1), ex_to_idx(e2));
}
-// Shaker sort is sufficient for the expected small number of indices
-template <class It, class Cmp>
-inline void shaker_sort(It first, It last, Cmp comp)
-{
- if (first == last)
- return;
- --last;
- if (first == last)
- return;
- It flag = first;
- do {
- It i;
- for (i=last; i>first; --i) {
- if (comp(*i, i[-1])) {
- iter_swap(i-1, i);
- flag = i - 1;
- }
- }
- ++flag;
- first = flag;
- for (i=first; i<last; ++i) {
- if (comp(i[1], *i)) {
- iter_swap(i, i+1);
- flag = i + 1;
- }
- }
- last = flag - 1;
- } while (first <= last);
-}
-
void find_free_and_dummy(exvector::const_iterator it, exvector::const_iterator itend, exvector & out_free, exvector & out_dummy)
{
out_free.clear();