X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fexpairseq.cpp;h=ec88239471a393ee20f6cb239b72d1939812e308;hp=f74be45e84da27a15e273ea8a14df0ee70d044a9;hb=b0265215a51a081d20fe68475e080716afc2d45a;hpb=9eab44408b9213d8909b7a9e525f404ad06064dd diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index f74be45e..ec882394 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -27,8 +27,11 @@ #include "expairseq.h" #include "lst.h" #include "debugmsg.h" +#include "utils.h" +#ifndef NO_GINAC_NAMESPACE namespace GiNaC { +#endif // ndef NO_GINAC_NAMESPACE #ifdef EXPAIRSEQ_USE_HASHTAB #error "FIXME: expair_needs_further_processing not yet implemented for hashtabs, sorry. A.F." @@ -104,14 +107,14 @@ expairseq::expairseq(ex const & lh, ex const & rh) : basic(TINFO_expairseq) { debugmsg("expairseq constructor from ex,ex",LOGLEVEL_CONSTRUCT); construct_from_2_ex(lh,rh); - ASSERT(is_canonical()); + GINAC_ASSERT(is_canonical()); } expairseq::expairseq(exvector const & v) : basic(TINFO_expairseq) { debugmsg("expairseq constructor from exvector",LOGLEVEL_CONSTRUCT); construct_from_exvector(v); - ASSERT(is_canonical()); + GINAC_ASSERT(is_canonical()); } /* @@ -127,7 +130,7 @@ expairseq::expairseq(epvector const & v, bool do_not_canonicalize) : } else { construct_from_epvector(v); } - ASSERT(is_canonical()); + GINAC_ASSERT(is_canonical()); } */ @@ -136,17 +139,17 @@ expairseq::expairseq(epvector const & v, ex const & oc) : { debugmsg("expairseq constructor from epvector,ex",LOGLEVEL_CONSTRUCT); construct_from_epvector(v); - ASSERT(is_canonical()); + GINAC_ASSERT(is_canonical()); } expairseq::expairseq(epvector * vp, ex const & oc) : basic(TINFO_expairseq), overall_coeff(oc) { debugmsg("expairseq constructor from epvector *,ex",LOGLEVEL_CONSTRUCT); - ASSERT(vp!=0); + GINAC_ASSERT(vp!=0); construct_from_epvector(*vp); delete vp; - ASSERT(is_canonical()); + GINAC_ASSERT(is_canonical()); } ////////// @@ -179,7 +182,7 @@ ex expairseq::op(int const i) const if (unsigned(i)(const_cast(other)); int cmpval; @@ -245,7 +248,7 @@ int expairseq::compare_same_type(basic const & other) const //if (seq.size()==0) return 0; // empty expairseq's are equal #ifdef EXPAIRSEQ_USE_HASHTAB - ASSERT(hashtabsize==o.hashtabsize); + GINAC_ASSERT(hashtabsize==o.hashtabsize); if (hashtabsize==0) { #endif // def EXPAIRSEQ_USE_HASHTAB epvector::const_iterator cit1=seq.begin(); @@ -258,8 +261,8 @@ int expairseq::compare_same_type(basic const & other) const if (cmpval!=0) return cmpval; } - ASSERT(cit1==last1); - ASSERT(cit2==last2); + GINAC_ASSERT(cit1==last1); + GINAC_ASSERT(cit2==last2); return 0; #ifdef EXPAIRSEQ_USE_HASHTAB @@ -313,7 +316,7 @@ bool expairseq::is_equal_same_type(basic const & other) const other.printtree(cout,0); } - ASSERT(hashtabsize==o.hashtabsize); + GINAC_ASSERT(hashtabsize==o.hashtabsize); if (hashtabsize==0) { #endif // def EXPAIRSEQ_USE_HASHTAB @@ -416,7 +419,7 @@ expair expairseq::split_ex_to_pair(ex const & e) const expair expairseq::combine_ex_with_coeff_to_pair(ex const & e, ex const & c) const { - ASSERT(is_ex_exactly_of_type(c,numeric)); + GINAC_ASSERT(is_ex_exactly_of_type(c,numeric)); return expair(e,c); } @@ -424,8 +427,8 @@ expair expairseq::combine_ex_with_coeff_to_pair(ex const & e, expair expairseq::combine_pair_with_coeff_to_pair(expair const & p, ex const & c) const { - ASSERT(is_ex_exactly_of_type(p.coeff,numeric)); - ASSERT(is_ex_exactly_of_type(c,numeric)); + GINAC_ASSERT(is_ex_exactly_of_type(p.coeff,numeric)); + GINAC_ASSERT(is_ex_exactly_of_type(c,numeric)); return expair(p.rest,ex_to_numeric(p.coeff).mul_dyn(ex_to_numeric(c))); } @@ -447,16 +450,16 @@ ex expairseq::default_overall_coeff(void) const void expairseq::combine_overall_coeff(ex const & c) { - ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); - ASSERT(is_ex_exactly_of_type(c,numeric)); + GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); + GINAC_ASSERT(is_ex_exactly_of_type(c,numeric)); overall_coeff = ex_to_numeric(overall_coeff).add_dyn(ex_to_numeric(c)); } void expairseq::combine_overall_coeff(ex const & c1, ex const & c2) { - ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); - ASSERT(is_ex_exactly_of_type(c1,numeric)); - ASSERT(is_ex_exactly_of_type(c2,numeric)); + GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric)); + GINAC_ASSERT(is_ex_exactly_of_type(c1,numeric)); + GINAC_ASSERT(is_ex_exactly_of_type(c2,numeric)); overall_coeff = ex_to_numeric(overall_coeff). add_dyn(ex_to_numeric(c1).mul(ex_to_numeric(c2))); } @@ -479,8 +482,8 @@ void expairseq::construct_from_2_ex_via_exvector(ex const & lh, ex const & rh) v.push_back(rh); construct_from_exvector(v); #ifdef EXPAIRSEQ_USE_HASHTAB - ASSERT((hashtabsize==0)||(hashtabsize>=minhashtabsize)); - ASSERT(hashtabsize==calc_hashtabsize(seq.size())); + GINAC_ASSERT((hashtabsize==0)||(hashtabsize>=minhashtabsize)); + GINAC_ASSERT(hashtabsize==calc_hashtabsize(seq.size())); #endif // def EXPAIRSEQ_USE_HASHTAB } @@ -1007,9 +1010,9 @@ unsigned expairseq::calc_hashtabsize(unsigned sz) const // size=nearest_power_of_2*hashtabfactor; size=nearest_power_of_2/hashtabfactor; if (size=0); - ASSERT((hashindex=0); + GINAC_ASSERT((hashindexreserve(seq.size()); - + // copy parts of seq which are known not to have changed epvector::const_iterator cit2=seq.begin(); while (cit2!=cit) { @@ -1527,7 +1531,7 @@ epvector * expairseq::subschildren(lst const & ls, lst const & lr) const s->push_back(combine_ex_with_coeff_to_pair((*cit2).rest.subs(ls,lr), (*cit2).coeff)); ++cit2; - } + } return s; } ++cit; @@ -1536,75 +1540,6 @@ epvector * expairseq::subschildren(lst const & ls, lst const & lr) const return 0; // nothing has changed } -/* -epvector expairseq::subschildren(lst const & ls, lst const & lr) const -{ - epvector s; - s.reserve(seq.size()); - - for (epvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) { - s.push_back(split_ex_to_pair((*it).rest.subs(ls,lr),(*it).coeff)); - } - return s; -} -*/ - -/* -void expairseq::sort(epviter first, epviter last, expair_is_less comp) -{ - if (first != last) { - introsort_loop(first, last, lg(last - first) * 2, comp); - __final_insertion_sort(first, last, comp); - } -} - -ptrdiff_t expairseq::lg(ptrdiff_t n) -{ - ptrdiff_t k; - for (k = 0; n > 1; n >>= 1) ++k; - return k; -} - -void expairseq::introsort_loop(epviter first, epviter last, - ptrdiff_t depth_limit, expair_is_less comp) -{ - while (last - first > stl_threshold) { - if (depth_limit == 0) { - partial_sort(first, last, last, comp); - return; - } - --depth_limit; - epviter cut = unguarded_partition(first, last, - expair(__median(*first, *(first + (last - first)/2), - *(last - 1), comp)), comp); - introsort_loop(cut, last, depth_limit, comp); - last = cut; - } -} - -epviter expairseq::unguarded_partition(epviter first, epviter last, - expair pivot, expair_is_less comp) -{ - while (1) { - while (comp(*first, pivot)) ++first; - --last; - while (comp(pivot, *last)) --last; - if (!(first < last)) return first; - iter_swap(first, last); - ++first; - } -} - -void expairseq::partial_sort(epviter first, epviter middle, epviter last, - expair_is_less comp) { - make_heap(first, middle, comp); - for (RandomAccessIterator i = middle; i < last; ++i) - if (comp(*i, *first)) - __pop_heap(first, middle, i, T(*i), comp, distance_type(first)); - sort_heap(first, middle, comp); -} -*/ - ////////// // static member variables ////////// @@ -1626,4 +1561,6 @@ unsigned expairseq::hashtabfactor=1; const expairseq some_expairseq; type_info const & typeid_expairseq=typeid(some_expairseq); +#ifndef NO_GINAC_NAMESPACE } // namespace GiNaC +#endif // ndef NO_GINAC_NAMESPACE