- // combine same terms, drop term with coeff 0, move numerics to end
-
- // calculate size of hashtab
- hashtabsize=calc_hashtabsize(seq.size());
-
- // hashtabsize is a power of 2
- hashmask=hashtabsize-1;
-
- // allocate hashtab
- hashtab.clear();
- hashtab.resize(hashtabsize);
-
- if (hashtabsize==0) {
- canonicalize();
- combine_same_terms_sorted_seq();
- GINAC_ASSERT(!has_coeff_0());
- return;
- }
-
- // iterate through seq, move numerics to end,
- // fill hashtab and combine same terms
- epvector::iterator first_numeric=seq.end();
- epvector::iterator last_non_zero=seq.end()-1;
-
- vector<bool> touched;
- touched.reserve(seq.size());
- for (unsigned i=0; i<seq.size(); ++i) touched[i]=false;
-
- unsigned number_of_zeroes=0;
-
- GINAC_ASSERT(!has_coeff_0());
- build_hashtab_and_combine(first_numeric,last_non_zero,touched,number_of_zeroes);
- /*
- cout << "in combine:" << endl;
- printtree(cout,0);
- cout << "size=" << seq.end() - seq.begin() << endl;
- cout << "first_numeric=" << first_numeric - seq.begin() << endl;
- cout << "last_non_zero=" << last_non_zero - seq.begin() << endl;
- for (unsigned i=0; i<seq.size(); ++i) {
- if (touched[i]) cout << i << " is touched" << endl;
- }
- cout << "end in combine" << endl;
- */
-
- // there should not be any terms with coeff 0 from the beginning,
- // so it should be safe to skip this step
- if (number_of_zeroes!=0) {
- drop_coeff_0_terms(first_numeric,last_non_zero,touched,number_of_zeroes);
- /*
- cout << "in combine after drop:" << endl;
- printtree(cout,0);
- cout << "size=" << seq.end() - seq.begin() << endl;
- cout << "first_numeric=" << first_numeric - seq.begin() << endl;
- cout << "last_non_zero=" << last_non_zero - seq.begin() << endl;
- for (unsigned i=0; i<seq.size(); ++i) {
- if (touched[i]) cout << i << " is touched" << endl;
- }
- cout << "end in combine after drop" << endl;
- */
- }
-
- add_numerics_to_hashtab(first_numeric,last_non_zero);
-
- // pop zero elements
- for (unsigned i=0; i<number_of_zeroes; ++i) {
- seq.pop_back();
- }
-
- // shrink hashtabsize to calculated value
- GINAC_ASSERT(!has_coeff_0());
-
- shrink_hashtab();
-
- GINAC_ASSERT(!has_coeff_0());
+ // combine same terms, drop term with coeff 0, move numerics to end
+
+ // calculate size of hashtab
+ hashtabsize = calc_hashtabsize(seq.size());
+
+ // hashtabsize is a power of 2
+ hashmask = hashtabsize-1;
+
+ // allocate hashtab
+ hashtab.clear();
+ hashtab.resize(hashtabsize);
+
+ if (hashtabsize==0) {
+ canonicalize();
+ combine_same_terms_sorted_seq();
+ GINAC_ASSERT(!has_coeff_0());
+ return;
+ }
+
+ // iterate through seq, move numerics to end,
+ // fill hashtab and combine same terms
+ epvector::iterator first_numeric=seq.end();
+ epvector::iterator last_non_zero=seq.end()-1;
+
+ vector<bool> touched;
+ touched.reserve(seq.size());
+ for (unsigned i=0; i<seq.size(); ++i) touched[i]=false;
+
+ unsigned number_of_zeroes = 0;
+
+ GINAC_ASSERT(!has_coeff_0());
+ build_hashtab_and_combine(first_numeric,last_non_zero,touched,number_of_zeroes);
+ /*
+ cout << "in combine:" << std::endl;
+ printtree(cout,0);
+ cout << "size=" << seq.end() - seq.begin() << std::endl;
+ cout << "first_numeric=" << first_numeric - seq.begin() << std::endl;
+ cout << "last_non_zero=" << last_non_zero - seq.begin() << std::endl;
+ for (unsigned i=0; i<seq.size(); ++i) {
+ if (touched[i]) cout << i << " is touched" << std::endl;
+ }
+ cout << "end in combine" << std::endl;
+ */
+
+ // there should not be any terms with coeff 0 from the beginning,
+ // so it should be safe to skip this step
+ if (number_of_zeroes!=0) {
+ drop_coeff_0_terms(first_numeric,last_non_zero,touched,number_of_zeroes);
+ /*
+ cout << "in combine after drop:" << std::endl;
+ printtree(cout,0);
+ cout << "size=" << seq.end() - seq.begin() << std::endl;
+ cout << "first_numeric=" << first_numeric - seq.begin() << std::endl;
+ cout << "last_non_zero=" << last_non_zero - seq.begin() << std::endl;
+ for (unsigned i=0; i<seq.size(); ++i) {
+ if (touched[i]) cout << i << " is touched" << std::endl;
+ }
+ cout << "end in combine after drop" << std::endl;
+ */
+ }
+
+ add_numerics_to_hashtab(first_numeric,last_non_zero);
+
+ // pop zero elements
+ for (unsigned i=0; i<number_of_zeroes; ++i) {
+ seq.pop_back();
+ }
+
+ // shrink hashtabsize to calculated value
+ GINAC_ASSERT(!has_coeff_0());
+
+ shrink_hashtab();
+
+ GINAC_ASSERT(!has_coeff_0());