]> www.ginac.de Git - ginac.git/blobdiff - ginac/expairseq.cpp
* Macro deobfuscation.
[ginac.git] / ginac / expairseq.cpp
index 1f7fcf4184cd76c41206d9be52bc4d12f541c0c9..246424f7559ff394651c5c7ee0564993fc8380ea 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of sequences of expression pairs. */
 
 /*
- *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -23,7 +23,6 @@
 #include <algorithm>
 #include <string>
 #include <stdexcept>
-#include <cmath>
 
 #include "expairseq.h"
 #include "lst.h"
@@ -39,7 +38,7 @@ namespace GiNaC {
 #error "FIXME: expair_needs_further_processing not yet implemented for hashtabs, sorry. A.F."
 #endif // def EXPAIRSEQ_USE_HASHTAB
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(expairseq, basic)
+GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(expairseq, basic)
 
 //////////
 // helper classes
@@ -192,7 +191,7 @@ void expairseq::archive(archive_node &n) const
        while (i != iend) {
                n.add_ex("rest", i->rest);
                n.add_ex("coeff", i->coeff);
-               i++;
+               ++i;
        }
        n.add_ex("overall_coeff", overall_coeff);
 }
@@ -272,7 +271,7 @@ void expairseq::printtree(std::ostream & os, unsigned indent) const
                        for (epplist::const_iterator it=hashtab[i].begin();
                                 it!=hashtab[i].end(); ++it) {
                                os << *it-seq.begin() << " ";
-                               this_bin_fill++;
+                               ++this_bin_fill;
                        }
                        os << std::endl;
                        cum_fill += this_bin_fill;
@@ -915,7 +914,7 @@ void expairseq::make_flat(const exvector & v)
        cit=v.begin();
        while (cit!=citend) {
                if (cit->bp->tinfo()==tinfo()) {
-                       nexpairseqs++;
+                       ++nexpairseqs;
                        noperands+=ex_to_expairseq(*cit).seq.size();
                }
                ++cit;
@@ -966,7 +965,7 @@ void expairseq::make_flat(const epvector & v)
        cit = v.begin();
        while (cit!=citend) {
                if (cit->rest.bp->tinfo()==tinfo()) {
-                       nexpairseqs++;
+                       ++nexpairseqs;
                        noperands += ex_to_expairseq((*cit).rest).seq.size();
                }
                ++cit;
@@ -1091,7 +1090,7 @@ void expairseq::canonicalize(void)
                        do {
                                last_numeric--;
                        } while (is_ex_exactly_of_type((*last_numeric).rest,numeric));
-                       last_numeric++;
+                       ++last_numeric;
                        sort(last_numeric,seq.end(),expair_is_less());
                }
        }
@@ -1198,11 +1197,11 @@ unsigned expairseq::calc_hashindex(const ex & e) const
        unsigned hash=e.gethash();
        unsigned hashindex;
        if (is_a_numeric_hash(hash)) {
-               hashindex=hashmask;
+               hashindex = hashmask;
        } else {
-               hashindex=hash & hashmask;
+               hashindex = hash & hashmask;
                // last hashtab entry is reserved for numerics
-               if (hashindex==hashmask) hashindex=0;
+               if (hashindex==hashmask) hashindex = 0;
        }
        GINAC_ASSERT(hashindex>=0);
        GINAC_ASSERT((hashindex<hashtabsize)||(hashtabsize==0));
@@ -1216,22 +1215,21 @@ void expairseq::shrink_hashtab(void)
                GINAC_ASSERT(new_hashtabsize<hashtabsize);
                if (new_hashtabsize==0) {
                        hashtab.clear();
-                       hashtabsize=0;
+                       hashtabsize = 0;
                        canonicalize();
                        return;
                }
                
                // shrink by a factor of 2
                unsigned half_hashtabsize=hashtabsize/2;
-               for (unsigned i=0; i<half_hashtabsize-1; ++i) {
+               for (unsigned i=0; i<half_hashtabsize-1; ++i)
                        hashtab[i].merge(hashtab[i+half_hashtabsize],epp_is_less());
-               }
                // special treatment for numeric hashes
                hashtab[0].merge(hashtab[half_hashtabsize-1],epp_is_less());
-               hashtab[half_hashtabsize-1]=hashtab[hashtabsize-1];
+               hashtab[half_hashtabsize-1] = hashtab[hashtabsize-1];
                hashtab.resize(half_hashtabsize);
-               hashtabsize=half_hashtabsize;
-               hashmask=hashtabsize-1;
+               hashtabsize = half_hashtabsize;
+               hashmask = hashtabsize-1;
        }
 }
 
@@ -1240,16 +1238,16 @@ void expairseq::remove_hashtab_entry(epvector::const_iterator element)
        if (hashtabsize==0) return; // nothing to do
        
        // calculate hashindex of element to be deleted
-       unsigned hashindex=calc_hashindex((*element).rest);
+       unsigned hashindex = calc_hashindex((*element).rest);
 
        // find it in hashtab and remove it
-       epplist & eppl=hashtab[hashindex];
-       epplist::iterator epplit=eppl.begin();
-       bool erased=false;
+       epplist & eppl = hashtab[hashindex];
+       epplist::iterator epplit = eppl.begin();
+       bool erased = false;
        while (epplit!=eppl.end()) {
                if (*epplit == element) {
                        eppl.erase(epplit);
-                       erased=true;
+                       erased = true;
                        break;
                }
                ++epplit;
@@ -1259,14 +1257,14 @@ void expairseq::remove_hashtab_entry(epvector::const_iterator element)
                cout << "tried to erase " << element-seq.begin() << std::endl;
                cout << "size " << seq.end()-seq.begin() << std::endl;
 
-               unsigned hashindex=calc_hashindex((*element).rest);
-               epplist & eppl=hashtab[hashindex];
+               unsigned hashindex = calc_hashindex((*element).rest);
+               epplist & eppl = hashtab[hashindex];
                epplist::iterator epplit=eppl.begin();
                bool erased=false;
                while (epplit!=eppl.end()) {
                        if (*epplit == element) {
                                eppl.erase(epplit);
-                               erased=true;
+                               erased = true;
                                break;
                        }
                        ++epplit;
@@ -1285,7 +1283,7 @@ void expairseq::move_hashtab_entry(epvector::const_iterator oldpos,
        unsigned hashindex=calc_hashindex((*newpos).rest);
 
        // find it in hashtab and modify it
-       epplist & eppl=hashtab[hashindex];
+       epplist & eppl = hashtab[hashindex];
        epplist::iterator epplit=eppl.begin();
        while (epplit!=eppl.end()) {
                if (*epplit == oldpos) {
@@ -1299,7 +1297,7 @@ void expairseq::move_hashtab_entry(epvector::const_iterator oldpos,
 
 void expairseq::sorted_insert(epplist & eppl, epp elem)
 {
-       epplist::iterator current=eppl.begin();
+       epplist::iterator current = eppl.begin();
        while ((current!=eppl.end())&&((*(*current)).is_less(*elem))) {
                ++current;
        }
@@ -1431,10 +1429,10 @@ void expairseq::combine_same_terms(void)
        // combine same terms, drop term with coeff 0, move numerics to end
        
        // calculate size of hashtab
-       hashtabsize=calc_hashtabsize(seq.size());
+       hashtabsize = calc_hashtabsize(seq.size());
 
        // hashtabsize is a power of 2
-       hashmask=hashtabsize-1;
+       hashmask = hashtabsize-1;
 
        // allocate hashtab
        hashtab.clear();
@@ -1456,7 +1454,7 @@ void expairseq::combine_same_terms(void)
        touched.reserve(seq.size());
        for (unsigned i=0; i<seq.size(); ++i) touched[i]=false;
 
-       unsigned number_of_zeroes=0;
+       unsigned number_of_zeroes = 0;
 
        GINAC_ASSERT(!has_coeff_0());
        build_hashtab_and_combine(first_numeric,last_non_zero,touched,number_of_zeroes);
@@ -1523,16 +1521,16 @@ bool expairseq::is_canonical() const
                                // double test makes it easier to set a breakpoint...
                                if (!is_ex_exactly_of_type((*it_last).rest,numeric)||
                                        !is_ex_exactly_of_type((*it).rest,numeric)) {
-                                       printpair(cout,*it_last,0);
-                                       cout << ">";
-                                       printpair(cout,*it,0);
-                                       cout << "\n";
-                                       cout << "pair1:" << std::endl;
-                                       (*it_last).rest.printtree(cout);
-                                       (*it_last).coeff.printtree(cout);
-                                       cout << "pair2:" << std::endl;
-                                       (*it).rest.printtree(cout);
-                                       (*it).coeff.printtree(cout);
+                                       printpair(std::clog,*it_last,0);
+                                       std::clog << ">";
+                                       printpair(std::clog,*it,0);
+                                       std::clog << "\n";
+                                       std::clog << "pair1:" << std::endl;
+                                       (*it_last).rest.printtree(std::clog);
+                                       (*it_last).coeff.printtree(std::clog);
+                                       std::clog << "pair2:" << std::endl;
+                                       (*it).rest.printtree(std::clog);
+                                       (*it).coeff.printtree(std::clog);
                                        return 0;
                                }
                        }
@@ -1689,7 +1687,7 @@ epvector * expairseq::subschildren(const lst & ls, const lst & lr) const
                if (!are_ex_trivially_equal((*cit).rest,subsed_ex)) {
                        
                        // something changed, copy seq, subs and return it
-                       epvector *s=new epvector;
+                       epvector *s = new epvector;
                        s->reserve(seq.size());
                        
                        // copy parts of seq which are known not to have changed
@@ -1730,13 +1728,6 @@ unsigned expairseq::minhashtabsize=0x1000U;
 unsigned expairseq::hashtabfactor=1;
 #endif // def EXPAIRSEQ_USE_HASHTAB
 
-//////////
-// global constants
-//////////
-
-const expairseq some_expairseq;
-const type_info & typeid_expairseq=typeid(some_expairseq);
-
 #ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
 #endif // ndef NO_NAMESPACE_GINAC