Macaulay2 Engine
Loading...
Searching...
No Matches

◆ combine()

MonomialView newf4::MonomialView::combine ( const MonomialView & left,
const MonomialView & right,
bool copyLeft,
bool copyRight,
std::function< int(int, int)> ,
MemoryBlock & block )
static

Definition at line 6 of file MonomialView.cpp.

12{
13 auto rng = block.allocateArray<MonomialInt>(left.size() + right.size() - 1);
14 MonomialView result(rng.first);
15
16 auto leftIt = left.begin();
17 auto rightIt = right.begin();
18 auto leftEnd = left.end();
19 auto rightEnd = right.end();
20 auto resultIt = result.begin();
21
22 while (true)
23 {
24 if (leftIt == leftEnd)
25 {
26 // take from right and increment right and result
27 if (useRight)
28 {
29 std::copy(rightIt.loc(),rightEnd.loc(),resultIt.loc());
30 resultIt += ((rightEnd.loc() - rightIt.loc()) >> 1);
31 }
32 break;
33 }
34 if (rightIt == rightEnd)
35 {
36 // take from left and increment left and result
37 if (useLeft)
38 {
39 std::copy(leftIt.loc(),leftEnd.loc(),resultIt.loc());
40 resultIt += ((leftEnd.loc() - leftIt.loc()) >> 1);
41 }
42 break;
43 }
44 if (leftIt.var() < rightIt.var())
45 {
46 // take from left and increment left and result
47 std::copy(leftIt.loc(), leftIt.loc() + 2, resultIt.loc());
48 ++resultIt;
49 ++leftIt;
50 }
51 else if (leftIt.var() > rightIt.var())
52 {
53 // take from right and increment right and result
54 std::copy(rightIt.loc(), rightIt.loc() + 2, resultIt.loc());
55 ++resultIt;
56 ++rightIt;
57 }
58 else
59 {
60 // take maximum and increment both
61 resultIt.loc()[0] = leftIt.var();
62 auto temp = bothFunc(leftIt.power(), rightIt.power());
63 if (temp > 0) // if we actually need this variable, store power and increment result
64 {
65 resultIt.loc()[1] = bothFunc(leftIt.power(), rightIt.power());
66 ++resultIt;
67 }
68 ++leftIt;
69 ++rightIt;
70 }
71 }
72 block.shrinkLastAllocate(rng.first, rng.second, resultIt.loc());
73 *rng.first = resultIt.loc() - rng.first;
74 return result;
75}
std::pair< T *, T * > shrinkLastAllocate(T *begin, T *end, T *newtop)
std::pair< T *, T * > allocateArray(size_t nelems)
MonomialView(MonomialInt *data)
VALGRIND_MAKE_MEM_DEFINED & result(result)
int32_t MonomialInt
std::mt19937 rng(rd())

References MemoryBlock::allocateArray(), begin(), end(), MonomialView(), result(), rng(), MemoryBlock::shrinkLastAllocate(), and size().

Referenced by lcm(), product(), and quotient().