bool TournamentReducer::leadTerm(const_term& result) { if (mLeadTermKnown) { result = mLeadTerm; return true; } do { if (mQueue.empty()) return false; MultipleWithPos* entry = mQueue.top(); mLeadTerm.monom.swap(entry->current); entry->currentCoefficient(mRing, mLeadTerm.coeff); while (true) { ++entry->pos; if (entry->pos == entry->end) { mQueue.pop(); entry->destroy(mRing); mPool.free(entry); } else { entry->computeCurrent(mRing); mQueue.decreaseTop(entry); } if (mQueue.empty()) break; entry = mQueue.top(); if (!mRing.monomialEQ(entry->current, mLeadTerm.monom)) break; coefficient coeff; entry->currentCoefficient(mRing, coeff); mRing.coefficientAddTo(mLeadTerm.coeff, const_cast<const coefficient&>(coeff)); } } while (mRing.coefficientIsZero(mLeadTerm.coeff)); result = mLeadTerm; mLeadTermKnown = true; return true; }
bool ReducerPack<Q>::leadTerm(NewConstTerm& result) { if (!mLeadTermKnown) { do { if (mQueue.empty()) return false; MultipleWithPos* entry = mQueue.top(); std::swap(mLeadTerm.mono, entry->current); entry->currentCoefficient(mRing, mLeadTerm.coef); while (true) { ++entry->pos; if (entry->pos == entry->end) { mQueue.pop(); entry->destroy(mRing); mPool.free(entry); } else { entry->computeCurrent(mRing); mQueue.decreaseTop(entry); } if (mQueue.empty()) break; entry = mQueue.top(); if (!mRing.monoid().equal(*entry->current, *mLeadTerm.mono)) break; coefficient coef; entry->currentCoefficient(mRing, coef); mRing.coefficientAddTo (mLeadTerm.coef, const_cast<const coefficient&>(coef)); } } while (mRing.coefficientIsZero(mLeadTerm.coef)); } result = mLeadTerm; mLeadTermKnown = true; return true; }