10#ifndef BIBASIS_POLYNOM_HPP
11#define BIBASIS_POLYNOM_HPP
49 template <
typename MonomType>
65 unsigned long Length()
const;
66 typename MonomType::Integer
Degree()
const;
67 const MonomType&
Lm()
const;
70 void*
operator new(std::size_t);
71 void operator delete(
void *ptr);
91 const MonomType *
const *
Find(
const MonomType& monom)
const;
94 template <
typename MonomType>
97 template <
typename MonomType>
100 template <
typename MonomType>
106 template <
typename MonomType>
116 MonomType **iterator = &MonomListHead,
117 *iteratorAnother = anotherPolynom.MonomListHead;
118 while (iteratorAnother)
120 *iterator = new MonomType(*iteratorAnother);
122 iterator = &((*iterator)->Next);
123 iteratorAnother = iteratorAnother->Next;
128 template <
typename MonomType>
134 template <
typename MonomType>
141 template <
typename MonomType>
146 MonomType* tmpMonom = 0;
156 template <
typename MonomType>
162 template <
typename MonomType>
165 unsigned long length = 0;
169 iterator = iterator->Next;
175 template <
typename MonomType>
188 template <
typename MonomType>
201 template <
typename MonomType>
212 template <
typename MonomType>
218 template <
typename MonomType>
224 template <
typename MonomType>
235 while (*iterator && iteratorAnother)
237 **iterator = *iteratorAnother;
238 iterator = &((*iterator)->Next);
239 iteratorAnother = iteratorAnother->Next;
244 MonomType* monomToDelete = (*iterator)->Next;
246 while (monomToDelete)
248 iteratorAnother = monomToDelete;
249 monomToDelete = monomToDelete->Next;
250 delete iteratorAnother;
253 else while (iteratorAnother)
255 *iterator =
new MonomType(*iteratorAnother);
256 iterator = &((*iterator)->Next);
257 iteratorAnother = iteratorAnother->Next;
263 template <
typename MonomType>
266 MonomType** position =
const_cast<MonomType**
>(
Find(newMonom));
267 MonomType* tmpMonom = 0;
271 tmpMonom =
new MonomType(newMonom);
277 if (*position && **position == newMonom)
279 tmpMonom = *position;
280 *position = (*position)->Next;
285 tmpMonom =
new MonomType(newMonom);
286 tmpMonom->Next = (*position)->Next;
287 (*position)->Next = tmpMonom;
294 template <
typename MonomType>
303 while (*iterator && iteratorAnother)
305 switch ((**iterator).Compare(*iteratorAnother))
308 tmpMonom =
new MonomType(*iteratorAnother);
309 tmpMonom->Next = *iterator;
310 *iterator = tmpMonom;
311 iterator = &(tmpMonom->Next);
312 iteratorAnother = iteratorAnother->Next;
315 tmpMonom = *iterator;
316 *iterator = (*iterator)->Next;
318 iteratorAnother = iteratorAnother->Next;
321 iterator = &((*iterator)->Next);
326 while (iteratorAnother)
328 *iterator =
new MonomType(*iteratorAnother);
329 iterator = &((*iterator)->Next);
330 iteratorAnother = iteratorAnother->Next;
337 template <
typename MonomType>
348 if ((**iterator)[var])
350 *iteratorWithVar = *iterator;
351 *iterator = (*iterator)->Next;
352 (*iteratorWithVar)->Next = 0;
353 iteratorWithVar = &((*iteratorWithVar)->Next);
357 iterator = &((*iterator)->Next);
365 iterator = &((*iterator)->Next);
374 template <
typename MonomType>
379 for (
typename MonomType::Integer i = 0; i < anotherMonom.GetDimIndepend(); ++i)
390 template <
typename MonomType>
399 while (iteratorAnother)
402 *tmpPolynom *= *iteratorAnother;
405 iteratorAnother = iteratorAnother->Next;
409 tmpResult->MonomListHead = 0;
415 template <
typename MonomType>
421 while (iterator && anotherIterator)
423 if (*iterator != *anotherIterator)
427 iterator = iterator->Next;
428 anotherIterator = anotherIterator->Next;
430 return !iterator && !anotherIterator;
433 template <
typename MonomType>
439 while (iterator && anotherIterator)
441 if (*iterator != *anotherIterator)
445 iterator = iterator->Next;
446 anotherIterator = anotherIterator->Next;
448 return iterator || anotherIterator;
451 template <
typename MonomType>
457 while (iterator && anotherIterator)
459 switch ((*iterator).Compare(*anotherIterator))
468 iterator = iterator->Next;
469 anotherIterator = anotherIterator->Next;
473 return !iterator && !anotherIterator;
476 template <
typename MonomType>
482 while (iterator && anotherIterator)
484 switch ((*iterator).Compare(*anotherIterator))
493 iterator = iterator->Next;
494 anotherIterator = anotherIterator->Next;
498 return iterator && !anotherIterator;
501 template <
typename MonomType>
507 while (iteratorA && iteratorB)
509 switch ((*iteratorA).Compare(*iteratorB))
518 iteratorA = iteratorA->Next;
519 iteratorB = iteratorB->Next;
538 template <
typename MonomType>
543 MonomType* tmpMonom =
new MonomType();
546 const MonomType& anotherLm = anotherPolynom.
Lm();
550 if (iterator->IsDivisibleBy(anotherLm))
552 tmpMonom->SetQuotientOf(*iterator, anotherLm);
554 *tmpPolynom *= *tmpMonom;
567 MonomType* iterator2 = iterator;
568 iterator = iterator->Next;
571 if (iterator->IsDivisibleBy(anotherLm))
573 tmpMonom->SetQuotientOf(*iterator, anotherLm);
575 *tmpPolynom *= *tmpMonom;
578 iterator = iterator2->Next;
582 iterator2 = iterator2->Next;
583 iterator = iterator2->Next;
591 template <
typename MonomType>
596 MonomType* tmpMonom =
new MonomType();
599 const MonomType& anotherLm = anotherPolynom.
Lm();
603 if (iterator->IsDivisibleBy(anotherLm))
605 tmpMonom->SetQuotientOf(*iterator, anotherLm);
607 *tmpPolynom *= *tmpMonom;
621 template <
typename MonomType>
628 while (*iterator && iteratorAnother)
630 switch ((**iterator).Compare(*iteratorAnother))
633 tmpPointer = iteratorAnother;
634 iteratorAnother = iteratorAnother->Next;
635 tmpPointer->Next = *iterator;
636 *iterator = tmpPointer;
637 iterator = &(tmpPointer->Next);
640 tmpPointer = *iterator;
641 *iterator = (*iterator)->Next;
643 tmpPointer = iteratorAnother;
644 iteratorAnother = iteratorAnother->Next;
648 iterator = &((*iterator)->Next);
655 *iterator = iteratorAnother;
661 template <
typename MonomType>
670 *
const *currentPointer = 0;
671 unsigned long range(
Length()), middle;
673 while ((middle = range >> 1) > 0)
675 currentPointer = previousPointer;
676 for (
unsigned long i = 0; i < middle; ++i)
678 currentPointer = &((*currentPointer)->Next);
681 switch ((**currentPointer).Compare(monom))
684 previousPointer = currentPointer;
691 return currentPointer;
695 return previousPointer;
BIBasis::FastAllocator — per-size-class slab allocator for BIBasis's small objects.
Slab allocator handing out fixed-size blocks for one BIBasis type per instance.
bool operator!=(const Polynom &anotherPolynom) const
static FastAllocator Allocator
const Polynom & operator=(const Polynom &anotherPolynom)
static int Compare(const Polynom &polynomA, const Polynom &polynomB)
MonomType::Integer Degree() const
void Reduction(const Polynom &anotherPolynom)
MonomType * MonomListHead
bool operator==(const Polynom &anotherPolynom) const
const Polynom & operator+=(const MonomType &newMonom)
void MergeWith(Polynom &anotherPolynom)
const MonomType & Lm() const
bool operator<(const Polynom &anotherPolynom) const
unsigned long Length() const
static MonomType UniteMonom
bool operator>(const Polynom &anotherPolynom) const
const MonomType *const * Find(const MonomType &monom) const
const Polynom & operator*=(typename MonomType::Integer var)
void HeadReduction(const Polynom &anotherPolynom)