1 | #include "mod2.h" |
---|
2 | |
---|
3 | #ifdef HAVE_F5 |
---|
4 | #include "kutil.h" |
---|
5 | #include "structs.h" |
---|
6 | #include "omalloc.h" |
---|
7 | #include "polys.h" |
---|
8 | #include "p_polys.h" |
---|
9 | #include "ideals.h" |
---|
10 | #include "febase.h" |
---|
11 | #include "kstd1.h" |
---|
12 | #include "khstd.h" |
---|
13 | #include "kbuckets.h" |
---|
14 | #include "weight.h" |
---|
15 | #include "intvec.h" |
---|
16 | #include "pInline1.h" |
---|
17 | #include "f5gb.h" |
---|
18 | #include "f5data.h" |
---|
19 | #include "f5lists.h" |
---|
20 | |
---|
21 | /* |
---|
22 | ==================================== |
---|
23 | functions working on the class LNode |
---|
24 | ==================================== |
---|
25 | */ |
---|
26 | |
---|
27 | // generating new list elements (labeled / classical polynomial / LNode view) |
---|
28 | LNode::LNode() { |
---|
29 | data = NULL; |
---|
30 | next = NULL; |
---|
31 | } |
---|
32 | LNode::LNode(LPoly* lp) { |
---|
33 | data = lp; |
---|
34 | next = NULL; |
---|
35 | } |
---|
36 | |
---|
37 | LNode::LNode(LPoly* lp, LNode* l) { |
---|
38 | //Print("HIER LNODE\n"); |
---|
39 | data = lp; |
---|
40 | next = l; |
---|
41 | } |
---|
42 | |
---|
43 | LNode::LNode(poly t, int i, poly p, Rule* r) { |
---|
44 | LPoly* lp = new LPoly(t,i,p,r); |
---|
45 | data = lp; |
---|
46 | next = NULL; |
---|
47 | } |
---|
48 | |
---|
49 | LNode::LNode(poly t, int i, poly p, Rule* r, LNode* l) { |
---|
50 | LPoly* lp = new LPoly(t,i,p,r); |
---|
51 | data = lp; |
---|
52 | next = l; |
---|
53 | } |
---|
54 | |
---|
55 | LNode::LNode(LNode* ln) { |
---|
56 | data = ln->getLPoly(); |
---|
57 | next = ln->getNext(); |
---|
58 | } |
---|
59 | |
---|
60 | LNode::~LNode() { |
---|
61 | //delete next; |
---|
62 | //Print("DELETE LNODE\n"); |
---|
63 | delete data; |
---|
64 | } |
---|
65 | |
---|
66 | void LNode::deleteAll() { |
---|
67 | while(NULL != next) { |
---|
68 | //Print("%p\n",next); |
---|
69 | //pWrite(next->data->getPoly()); |
---|
70 | next->deleteAll(); |
---|
71 | } |
---|
72 | delete data; |
---|
73 | } |
---|
74 | |
---|
75 | // insert new elements to the list always at the end (labeled / classical polynomial view) |
---|
76 | // needed for list gPrev |
---|
77 | inline LNode* LNode::insert(LPoly* lp) { |
---|
78 | //Print("LAST GPREV: "); |
---|
79 | //pWrite(this->getPoly()); |
---|
80 | if(NULL == this) { |
---|
81 | LNode* newElement = new LNode(lp,this); |
---|
82 | return newElement; |
---|
83 | } |
---|
84 | else { |
---|
85 | LNode* newElement = new LNode(lp, NULL); |
---|
86 | this->next = newElement; |
---|
87 | return newElement; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | inline LNode* LNode::insert(poly t, int i, poly p, Rule* r) { |
---|
92 | if(NULL == this) { |
---|
93 | LNode* newElement = new LNode(t,i,p,r,this); |
---|
94 | return newElement; |
---|
95 | } |
---|
96 | else { |
---|
97 | LNode* newElement = new LNode(t, i, p, r, NULL); |
---|
98 | this->next = newElement; |
---|
99 | return newElement; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | // insert new elements to the list always in front (labeled / classical polynomial view) |
---|
104 | // needed for sPolyList |
---|
105 | inline LNode* LNode::insertSP(LPoly* lp) { |
---|
106 | LNode* newElement = new LNode(lp, this); |
---|
107 | //Print("INSERTED IN SPOLYLIST: "); |
---|
108 | //pWrite(lp->getTerm()); |
---|
109 | return newElement; |
---|
110 | } |
---|
111 | |
---|
112 | inline LNode* LNode::insertSP(poly t, int i, poly p, Rule* r) { |
---|
113 | LNode* newElement = new LNode(t, i, p, r, this); |
---|
114 | //Print("INSERTED IN SPOLYLIST: "); |
---|
115 | //pWrite(t); |
---|
116 | return newElement; |
---|
117 | } |
---|
118 | // insert new elemets to the list w.r.t. increasing labels |
---|
119 | // only used for the S-polys to be reduced (TopReduction building new S-polys with higher label) |
---|
120 | inline LNode* LNode::insertByLabel(poly t, int i, poly p, Rule* r) { |
---|
121 | //Print("ADDING SOLYS TO THE LIST\n"); |
---|
122 | //Print("new element: "); |
---|
123 | //pWrite(t); |
---|
124 | if(NULL == this) { // || NULL == data) { |
---|
125 | LNode* newElement = new LNode(t, i, p, r, this); |
---|
126 | return newElement; |
---|
127 | } |
---|
128 | else { |
---|
129 | //Print("tested element1: "); |
---|
130 | //pWrite(this->getTerm()); |
---|
131 | if(-1 == pLmCmp(t,this->getTerm())) { |
---|
132 | //Print("HIERDRIN\n"); |
---|
133 | LNode* newElement = new LNode(t, i, p, r, this); |
---|
134 | //Print("%p\n",this); |
---|
135 | //Print("%p\n",newElement->next); |
---|
136 | return newElement; |
---|
137 | } |
---|
138 | else { |
---|
139 | LNode* temp = this; |
---|
140 | while(NULL != temp->next && NULL != temp->next->data) { |
---|
141 | //Print("tested element: "); |
---|
142 | //pWrite(temp->getTerm()); |
---|
143 | if(-1 == pLmCmp(t,temp->next->getTerm())) { |
---|
144 | LNode* newElement = new LNode(t, i, p, r, temp->next); |
---|
145 | temp->next = newElement; |
---|
146 | return this; |
---|
147 | } |
---|
148 | else { |
---|
149 | temp = temp->next; |
---|
150 | //Print("%p\n",temp); |
---|
151 | //Print("%p\n",temp->data); |
---|
152 | |
---|
153 | //Print("%p\n",temp->next); |
---|
154 | } |
---|
155 | } |
---|
156 | //Print("HIER\n"); |
---|
157 | LNode* newElement = new LNode(t, i, p, r, temp->next); |
---|
158 | temp->next = newElement; |
---|
159 | return this; |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | inline LNode* LNode::insertFirst(LNode* l) { |
---|
165 | l->next = this; |
---|
166 | return l; |
---|
167 | } |
---|
168 | |
---|
169 | inline LNode* LNode::insertByLabel(LNode* l) { |
---|
170 | //Print("ADDING SOLYS TO THE LIST\n"); |
---|
171 | //Print("new element: "); |
---|
172 | //pWrite(t); |
---|
173 | if(NULL == this) { // || NULL == data) { |
---|
174 | l->next = this; |
---|
175 | return l; |
---|
176 | } |
---|
177 | else { |
---|
178 | //Print("tested element1: "); |
---|
179 | //pWrite(this->getTerm()); |
---|
180 | if(-1 == pLmCmp(l->getTerm(),this->getTerm())) { |
---|
181 | //Print("HIERDRIN\n"); |
---|
182 | l->next = this; |
---|
183 | //Print("%p\n",this); |
---|
184 | //Print("%p\n",newElement->next); |
---|
185 | return l; |
---|
186 | } |
---|
187 | else { |
---|
188 | LNode* temp = this; |
---|
189 | while(NULL != temp->next && NULL != temp->next->data) { |
---|
190 | //Print("tested element: "); |
---|
191 | //pWrite(temp->getTerm()); |
---|
192 | if(-1 == pLmCmp(l->getTerm(),temp->next->getTerm())) { |
---|
193 | l->next = temp->next; |
---|
194 | temp->next = l; |
---|
195 | return this; |
---|
196 | } |
---|
197 | else { |
---|
198 | temp = temp->next; |
---|
199 | //Print("%p\n",temp); |
---|
200 | //Print("%p\n",temp->data); |
---|
201 | |
---|
202 | //Print("%p\n",temp->next); |
---|
203 | } |
---|
204 | } |
---|
205 | //Print("HIER\n"); |
---|
206 | l->next = temp->next; |
---|
207 | temp->next = l; |
---|
208 | return this; |
---|
209 | } |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | // deletes the first elements of the list with the same degree |
---|
214 | // only used for the S-polys, which are already sorted by increasing degree by CListOld |
---|
215 | LNode* LNode::deleteByDeg() { |
---|
216 | return this; |
---|
217 | } |
---|
218 | |
---|
219 | // get next from current LNode |
---|
220 | LNode* LNode::getNext() { |
---|
221 | return next; |
---|
222 | } |
---|
223 | |
---|
224 | // get the LPoly* out of LNode* |
---|
225 | LPoly* LNode::getLPoly() { |
---|
226 | return data; |
---|
227 | } |
---|
228 | |
---|
229 | // get the data from the LPoly saved in LNode |
---|
230 | poly LNode::getPoly() { |
---|
231 | return data->getPoly(); |
---|
232 | } |
---|
233 | |
---|
234 | poly LNode::getTerm() { |
---|
235 | return data->getTerm(); |
---|
236 | } |
---|
237 | |
---|
238 | int LNode::getIndex() { |
---|
239 | return data->getIndex(); |
---|
240 | } |
---|
241 | |
---|
242 | Rule* LNode::getRule() { |
---|
243 | return data->getRule(); |
---|
244 | } |
---|
245 | |
---|
246 | void LNode::setRule(Rule* r) { |
---|
247 | return data->setRule(r); |
---|
248 | } |
---|
249 | |
---|
250 | bool LNode::getDel() { |
---|
251 | return data->getDel(); |
---|
252 | } |
---|
253 | |
---|
254 | // set the data from the LPoly saved in LNode |
---|
255 | void LNode::setPoly(poly p) { |
---|
256 | data->setPoly(p); |
---|
257 | } |
---|
258 | |
---|
259 | void LNode::setTerm(poly t) { |
---|
260 | data->setTerm(t); |
---|
261 | } |
---|
262 | |
---|
263 | void LNode::setIndex(int i) { |
---|
264 | data->setIndex(i); |
---|
265 | } |
---|
266 | |
---|
267 | void LNode::setNext(LNode* l) { |
---|
268 | next = l; |
---|
269 | } |
---|
270 | |
---|
271 | void LNode::setDel(bool d) { |
---|
272 | data->setDel(d); |
---|
273 | } |
---|
274 | |
---|
275 | // test if for any list element the polynomial part of the data is equal to *p |
---|
276 | bool LNode::polyTest(poly* p) { |
---|
277 | LNode* temp = new LNode(this); |
---|
278 | while(NULL != temp) { |
---|
279 | if(pComparePolys(temp->getPoly(),*p)) { |
---|
280 | return 1; |
---|
281 | } |
---|
282 | temp = temp->next; |
---|
283 | } |
---|
284 | return 0; |
---|
285 | } |
---|
286 | |
---|
287 | LNode* LNode::getNext(LNode* l) { |
---|
288 | return l->next; |
---|
289 | } |
---|
290 | |
---|
291 | // for debugging |
---|
292 | void LNode::print() { |
---|
293 | LNode* temp = this; |
---|
294 | Print("___________________List of S-polynomials______________________:\n"); |
---|
295 | Print("%p\n",this); |
---|
296 | while(NULL != temp && NULL != temp->data) { |
---|
297 | Print("Index: %d\n",temp->getIndex()); |
---|
298 | Print("Term: "); |
---|
299 | pWrite(temp->getTerm()); |
---|
300 | Print("Poly: "); |
---|
301 | pWrite(temp->getPoly()); |
---|
302 | Print("%p\n",temp->getPoly()); |
---|
303 | Print("DELETE? %d\n",temp->getDel()); |
---|
304 | temp = temp->next; |
---|
305 | } |
---|
306 | Print("_______________________________________________________________\n"); |
---|
307 | } |
---|
308 | |
---|
309 | int LNode::count(LNode* l) { |
---|
310 | int nonDel = 0; |
---|
311 | LNode* temp = l; |
---|
312 | while(NULL != temp) { |
---|
313 | if(!temp->getDel()) { |
---|
314 | nonDel++; |
---|
315 | temp = temp->next; |
---|
316 | } |
---|
317 | else { |
---|
318 | temp = temp->next; |
---|
319 | } |
---|
320 | } |
---|
321 | return nonDel; |
---|
322 | } |
---|
323 | |
---|
324 | /* |
---|
325 | ==================================== |
---|
326 | functions working on the class LList |
---|
327 | ==================================== |
---|
328 | */ |
---|
329 | |
---|
330 | LList::LList() { |
---|
331 | first = last = NULL;; |
---|
332 | length = 0; |
---|
333 | } |
---|
334 | |
---|
335 | LList::LList(LPoly* lp) { |
---|
336 | first = new LNode(lp); |
---|
337 | last = first; |
---|
338 | length = 1; |
---|
339 | } |
---|
340 | |
---|
341 | LList::LList(poly t,int i,poly p,Rule* r) { |
---|
342 | first = new LNode(t,i,p,r); |
---|
343 | last = first; |
---|
344 | length = 1; |
---|
345 | } |
---|
346 | |
---|
347 | LList::~LList() { |
---|
348 | LNode* temp; |
---|
349 | while(first) { |
---|
350 | temp = first; |
---|
351 | first = first->getNext(); |
---|
352 | delete temp; |
---|
353 | //Print("%p\n",first); |
---|
354 | } |
---|
355 | } |
---|
356 | |
---|
357 | // insertion at the end of the list, needed for gPrev |
---|
358 | void LList::insert(LPoly* lp) { |
---|
359 | last = last->insert(lp); |
---|
360 | if(NULL == first) { |
---|
361 | first = last; |
---|
362 | } |
---|
363 | //Print("NEW LAST GPREV: "); |
---|
364 | //pWrite(last->getPoly()); |
---|
365 | //Print("%p\n",first); |
---|
366 | //pWrite(first->getPoly()); |
---|
367 | length++; |
---|
368 | //Print("LENGTH %d\n",length); |
---|
369 | } |
---|
370 | |
---|
371 | void LList::insert(poly t,int i, poly p, Rule* r) { |
---|
372 | last = last->insert(t,i,p,r); |
---|
373 | if(NULL == first) { |
---|
374 | first = last; |
---|
375 | } |
---|
376 | length++; |
---|
377 | //Print("LENGTH %d\n",length); |
---|
378 | } |
---|
379 | |
---|
380 | // insertion in front of the list, needed for sPolyList |
---|
381 | void LList::insertSP(LPoly* lp) { |
---|
382 | first = first->insertSP(lp); |
---|
383 | length++; |
---|
384 | //Print("LENGTH %d\n",length); |
---|
385 | } |
---|
386 | |
---|
387 | void LList::insertSP(poly t,int i, poly p, Rule* r) { |
---|
388 | first = first->insertSP(t,i,p,r); |
---|
389 | length++; |
---|
390 | //Print("LENGTH %d\n",length); |
---|
391 | } |
---|
392 | |
---|
393 | |
---|
394 | void LList::insertByLabel(poly t, int i, poly p, Rule* r) { |
---|
395 | first = first->insertByLabel(t,i,p,r); |
---|
396 | length++; |
---|
397 | //Print("LENGTH %d\n",length); |
---|
398 | } |
---|
399 | |
---|
400 | void LList::insertFirst(LNode* l) { |
---|
401 | first = first->insertFirst(l); |
---|
402 | length++; |
---|
403 | //Print("LENGTH %d\n",length); |
---|
404 | } |
---|
405 | |
---|
406 | void LList::insertByLabel(LNode* l) { |
---|
407 | first = first->insertByLabel(l); |
---|
408 | length++; |
---|
409 | //Print("LENGTH %d\n",length); |
---|
410 | } |
---|
411 | |
---|
412 | void LList::deleteByDeg() { |
---|
413 | first = first->deleteByDeg(); |
---|
414 | } |
---|
415 | |
---|
416 | bool LList::polyTest(poly* p) { |
---|
417 | return first->polyTest(p); |
---|
418 | } |
---|
419 | |
---|
420 | LNode* LList::getFirst() { |
---|
421 | return first; |
---|
422 | } |
---|
423 | |
---|
424 | LNode* LList::getLast() { |
---|
425 | return last; |
---|
426 | } |
---|
427 | |
---|
428 | int LList::getLength() { |
---|
429 | return length; |
---|
430 | } |
---|
431 | |
---|
432 | void LList::setFirst(LNode* l) { |
---|
433 | LNode* temp = first; |
---|
434 | temp->setNext(NULL); |
---|
435 | first = l; |
---|
436 | length--; |
---|
437 | } |
---|
438 | |
---|
439 | void LList::print() { |
---|
440 | first->print(); |
---|
441 | } |
---|
442 | |
---|
443 | int LList::count(LNode* l) { |
---|
444 | return first->count(l); |
---|
445 | } |
---|
446 | /* |
---|
447 | ======================================= |
---|
448 | functions working on the class LTagNode |
---|
449 | ======================================= |
---|
450 | */ |
---|
451 | LTagNode::LTagNode() { |
---|
452 | data = NULL; |
---|
453 | next = NULL; |
---|
454 | } |
---|
455 | |
---|
456 | LTagNode::LTagNode(LNode* l) { |
---|
457 | data = l; |
---|
458 | next = NULL; |
---|
459 | } |
---|
460 | |
---|
461 | LTagNode::LTagNode(LNode* l, LTagNode* n) { |
---|
462 | data = l; |
---|
463 | next = n; |
---|
464 | } |
---|
465 | |
---|
466 | LTagNode::~LTagNode() { |
---|
467 | delete data; |
---|
468 | } |
---|
469 | |
---|
470 | // declaration with first as parameter due to sorting of LTagList |
---|
471 | LTagNode* LTagNode::insert(LNode* l) { |
---|
472 | LTagNode* newElement = new LTagNode(l, this); |
---|
473 | return newElement; |
---|
474 | } |
---|
475 | |
---|
476 | LNode* LTagNode::getLNode() { |
---|
477 | return this->data; |
---|
478 | } |
---|
479 | |
---|
480 | LTagNode* LTagNode::getNext() { |
---|
481 | return next; |
---|
482 | } |
---|
483 | |
---|
484 | // NOTE: We insert at the beginning of the list and length = i-1, where i is the actual index. |
---|
485 | // Thus given actual index i and idx being the index of the LPoly under investigation |
---|
486 | // the element on position length-idx is the right one |
---|
487 | LNode* LTagNode::get(int idx, int length) { |
---|
488 | if(idx == 1) { |
---|
489 | return NULL; |
---|
490 | } |
---|
491 | else { |
---|
492 | int j; |
---|
493 | LTagNode* temp = this; // last |
---|
494 | for(j=1;j<=length-idx+1;j++) { |
---|
495 | temp = temp->next; |
---|
496 | } |
---|
497 | return temp->data; |
---|
498 | } |
---|
499 | } |
---|
500 | |
---|
501 | |
---|
502 | /* |
---|
503 | ======================================= |
---|
504 | functions working on the class LTagList |
---|
505 | ======================================= |
---|
506 | */ |
---|
507 | LTagList::LTagList() { |
---|
508 | LTagNode* first = new LTagNode(); |
---|
509 | |
---|
510 | length = 0; |
---|
511 | } |
---|
512 | |
---|
513 | LTagList::LTagList(LNode* l) { |
---|
514 | LTagNode* first = new LTagNode(l); |
---|
515 | length = 1; |
---|
516 | } |
---|
517 | |
---|
518 | LTagList::~LTagList() { |
---|
519 | LTagNode* temp; |
---|
520 | while(first) { |
---|
521 | temp = first; |
---|
522 | first = first->getNext(); |
---|
523 | delete temp; |
---|
524 | //Print("%p\n",first); |
---|
525 | } |
---|
526 | } |
---|
527 | |
---|
528 | // declaration with first as parameter in LTagNode due to sorting of LTagList |
---|
529 | void LTagList::insert(LNode* l) { |
---|
530 | first = first->insert(l); |
---|
531 | length++; |
---|
532 | } |
---|
533 | |
---|
534 | void LTagList::setFirstCurrentIdx(LNode* l) { |
---|
535 | firstCurrentIdx = l; |
---|
536 | } |
---|
537 | |
---|
538 | LNode* LTagList::get(int idx) { |
---|
539 | return first->get(idx, length); |
---|
540 | } |
---|
541 | |
---|
542 | LNode* LTagList::getFirst() { |
---|
543 | return first->getLNode(); |
---|
544 | } |
---|
545 | |
---|
546 | LNode* LTagList::getFirstCurrentIdx() { |
---|
547 | return firstCurrentIdx; |
---|
548 | } |
---|
549 | |
---|
550 | /* |
---|
551 | ===================================== |
---|
552 | functions working on the class TopRed |
---|
553 | ===================================== |
---|
554 | */ |
---|
555 | |
---|
556 | TopRed::TopRed() { |
---|
557 | _completed = NULL; |
---|
558 | _toDo = NULL; |
---|
559 | } |
---|
560 | |
---|
561 | TopRed::TopRed(LList* c, LList* t) { |
---|
562 | _completed = c; |
---|
563 | _toDo = t; |
---|
564 | } |
---|
565 | |
---|
566 | LList* TopRed::getCompleted() { |
---|
567 | return _completed; |
---|
568 | } |
---|
569 | |
---|
570 | LList* TopRed::getToDo() { |
---|
571 | return _toDo; |
---|
572 | } |
---|
573 | |
---|
574 | /* |
---|
575 | ==================================== |
---|
576 | functions working on the class CNode |
---|
577 | ==================================== |
---|
578 | */ |
---|
579 | |
---|
580 | CNode::CNode() { |
---|
581 | data = NULL; |
---|
582 | next = NULL; |
---|
583 | } |
---|
584 | |
---|
585 | CNode::CNode(CPairOld* c) { |
---|
586 | data = c; |
---|
587 | next = NULL; |
---|
588 | } |
---|
589 | |
---|
590 | CNode::CNode(CPairOld* c, CNode* n) { |
---|
591 | data = c; |
---|
592 | next = n; |
---|
593 | } |
---|
594 | |
---|
595 | CNode::~CNode() { |
---|
596 | delete data; |
---|
597 | } |
---|
598 | |
---|
599 | // insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label |
---|
600 | // note: as all critical pairs have the same index here, the second sort is done on the terms of the labels |
---|
601 | // working only with linked, but not doubly linked lists due to memory usage we have to check the |
---|
602 | // insertion around the first element separately from the insertion around all other elements in the list |
---|
603 | CNode* CNode::insert(CPairOld* c) { |
---|
604 | if(NULL == this) { |
---|
605 | CNode* newElement = new CNode(c, this); |
---|
606 | return newElement; |
---|
607 | } |
---|
608 | else { |
---|
609 | poly u1 = ppMult_qq(c->getT1(),c->getLp1Term()); |
---|
610 | if( c->getDeg() < this->data->getDeg() ) { // lower degree than the first list element |
---|
611 | CNode* newElement = new CNode(c, this); |
---|
612 | return newElement; |
---|
613 | } |
---|
614 | if( c->getDeg() == this->data->getDeg() ) { // same degree than the first list element |
---|
615 | if(1 != pLmCmp(u1,ppMult_qq(this->data->getT1(), this->data->getLp1Term()))) { |
---|
616 | //pWrite(u1); |
---|
617 | //Print("Multi-Term in CritPairs Sortierung altes Element: "); |
---|
618 | //pWrite(ppMult_qq(this->data->getT1(),this->data->getLp1Term())); |
---|
619 | CNode* newElement = new CNode(c, this); |
---|
620 | return newElement; |
---|
621 | } |
---|
622 | else { |
---|
623 | //Print("Insert Deg\n"); |
---|
624 | CNode* temp = this; |
---|
625 | while( NULL != temp->next) { |
---|
626 | if(temp->next->data->getDeg() == c->getDeg() ) { |
---|
627 | if(1 == pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),temp->next->data->getLp1Term()))) { |
---|
628 | temp = temp->next; |
---|
629 | } |
---|
630 | else { |
---|
631 | CNode* newElement = new CNode(c, temp->next); |
---|
632 | temp->next = newElement; |
---|
633 | return this; |
---|
634 | } |
---|
635 | } |
---|
636 | else { |
---|
637 | CNode* newElement = new CNode(c, temp->next); |
---|
638 | temp->next = newElement; |
---|
639 | return this; |
---|
640 | } |
---|
641 | } |
---|
642 | CNode* newElement = new CNode(c, NULL); |
---|
643 | temp->next = newElement; |
---|
644 | return this; |
---|
645 | } |
---|
646 | } // outer if-clause |
---|
647 | if( c->getDeg() > this->data->getDeg() ) { // greater degree than the first list element |
---|
648 | CNode* temp = this; |
---|
649 | while( NULL != temp->next ) { |
---|
650 | if( c->getDeg() < temp->next->data->getDeg() ) { |
---|
651 | CNode* newElement = new CNode(c, temp->next); |
---|
652 | temp->next = newElement; |
---|
653 | return this; |
---|
654 | } |
---|
655 | if( c->getDeg() == temp->next->data->getDeg() ) { |
---|
656 | if(1 != pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),temp->next->data->getLp1Term()))) { |
---|
657 | CNode* newElement = new CNode(c, temp->next); |
---|
658 | temp->next = newElement; |
---|
659 | return this; |
---|
660 | } |
---|
661 | else { |
---|
662 | temp = temp->next; |
---|
663 | while( NULL != temp->next ) { |
---|
664 | if( temp->next->data->getDeg() == c->getDeg() ) { |
---|
665 | if(1 == pLmCmp(u1,ppMult_qq(temp->next->data->getT1(), |
---|
666 | temp->next->data->getLp1Term()))) { |
---|
667 | temp = temp->next; |
---|
668 | } |
---|
669 | else { |
---|
670 | CNode* newElement = new CNode(c, temp->next); |
---|
671 | temp->next = newElement; |
---|
672 | return this; |
---|
673 | } |
---|
674 | } |
---|
675 | else { |
---|
676 | CNode* newElement = new CNode(c, temp->next); |
---|
677 | temp->next = newElement; |
---|
678 | return this; |
---|
679 | } |
---|
680 | } |
---|
681 | CNode* newElement = new CNode(c, NULL); |
---|
682 | temp->next = newElement; |
---|
683 | return this; |
---|
684 | } |
---|
685 | } |
---|
686 | if( c->getDeg() > temp->next->data->getDeg() ) { |
---|
687 | temp = temp->next; |
---|
688 | } |
---|
689 | } |
---|
690 | CNode* newElement = new CNode(c, NULL); |
---|
691 | temp->next = newElement; |
---|
692 | return this; |
---|
693 | } |
---|
694 | } |
---|
695 | } |
---|
696 | |
---|
697 | // get the first elements from CListOld which by the above sorting have minimal degree |
---|
698 | CNode* CNode::getMinDeg() { |
---|
699 | CNode* temp = this; |
---|
700 | while(NULL != temp) { |
---|
701 | while(NULL != temp->next && temp->next->data->getDeg() == this->data->getDeg()) { |
---|
702 | temp = temp->next; |
---|
703 | } |
---|
704 | CNode* returnCNode = temp->next; |
---|
705 | // every CListOld should end with a (NULL,NULL) element for a similar behaviour |
---|
706 | // using termination conditions throughout the algorithm |
---|
707 | temp->next = NULL; |
---|
708 | return returnCNode; |
---|
709 | } |
---|
710 | return NULL; |
---|
711 | } |
---|
712 | |
---|
713 | CPairOld* CNode::getData() { |
---|
714 | return data; |
---|
715 | } |
---|
716 | |
---|
717 | CNode* CNode::getNext() { |
---|
718 | return next; |
---|
719 | } |
---|
720 | |
---|
721 | LPoly* CNode::getAdLp1() { |
---|
722 | return this->data->getAdLp1(); |
---|
723 | } |
---|
724 | |
---|
725 | LPoly* CNode::getAdLp2() { |
---|
726 | return this->data->getAdLp2(); |
---|
727 | } |
---|
728 | |
---|
729 | poly CNode::getLp1Poly() { |
---|
730 | return this->data->getLp1Poly(); |
---|
731 | } |
---|
732 | |
---|
733 | poly CNode::getLp2Poly() { |
---|
734 | return this->data->getLp2Poly(); |
---|
735 | } |
---|
736 | |
---|
737 | poly CNode::getLp1Term() { |
---|
738 | return this->data->getLp1Term(); |
---|
739 | } |
---|
740 | |
---|
741 | poly CNode::getLp2Term() { |
---|
742 | return this->data->getLp2Term(); |
---|
743 | } |
---|
744 | |
---|
745 | int CNode::getLp1Index() { |
---|
746 | return this->data->getLp1Index(); |
---|
747 | } |
---|
748 | |
---|
749 | int CNode::getLp2Index() { |
---|
750 | return this->data->getLp2Index(); |
---|
751 | } |
---|
752 | |
---|
753 | poly CNode::getT1() { |
---|
754 | return this->data->getT1(); |
---|
755 | } |
---|
756 | |
---|
757 | poly* CNode::getAdT1() { |
---|
758 | return this->data->getAdT1(); |
---|
759 | } |
---|
760 | |
---|
761 | poly CNode::getT2() { |
---|
762 | return this->data->getT2(); |
---|
763 | } |
---|
764 | |
---|
765 | poly* CNode::getAdT2() { |
---|
766 | return this->data->getAdT2(); |
---|
767 | } |
---|
768 | |
---|
769 | Rule* CNode::getTestedRule() { |
---|
770 | return this->data->getTestedRule(); |
---|
771 | } |
---|
772 | |
---|
773 | // for debugging |
---|
774 | void CNode::print() { |
---|
775 | CNode* temp = this; |
---|
776 | Print("___________________List of critical pairs______________________:\n"); |
---|
777 | while(NULL != temp) { |
---|
778 | pWrite(ppMult_qq(temp->getT1(),temp->getLp1Term())); |
---|
779 | Print("LP1 Index: %d\n",temp->getLp1Index()); |
---|
780 | Print("T1: "); |
---|
781 | pWrite(temp->getT1()); |
---|
782 | Print("%p\n",temp->getT1()); |
---|
783 | Print("LP1 Term: "); |
---|
784 | pWrite(temp->getLp1Term()); |
---|
785 | Print("LP1 Poly: "); |
---|
786 | pWrite(temp->getLp1Poly()); |
---|
787 | Print("LP2 Index: %d\n",temp->getLp2Index()); |
---|
788 | Print("T2: "); |
---|
789 | pWrite(temp->getT2()); |
---|
790 | Print("%p\n",temp->getT2()); |
---|
791 | Print("LP2 Term: "); |
---|
792 | pWrite(temp->getLp2Term()); |
---|
793 | Print("LP2 Poly: "); |
---|
794 | pWrite(temp->getLp2Poly()); |
---|
795 | Print("\n"); |
---|
796 | temp = temp->next; |
---|
797 | } |
---|
798 | } |
---|
799 | |
---|
800 | /* |
---|
801 | ==================================== |
---|
802 | functions working on the class CListOld |
---|
803 | ==================================== |
---|
804 | */ |
---|
805 | // for initialization of CListOlds, last element alwas has data=NULL and next=NULL |
---|
806 | CListOld::CListOld() { |
---|
807 | first = NULL; |
---|
808 | } |
---|
809 | |
---|
810 | CListOld::CListOld(CPairOld* c) { |
---|
811 | first = new CNode(c); |
---|
812 | } |
---|
813 | |
---|
814 | CListOld::~CListOld() { |
---|
815 | CNode* temp; |
---|
816 | while(NULL != first) { |
---|
817 | temp = first; |
---|
818 | first = first->getNext(); |
---|
819 | delete temp; |
---|
820 | } |
---|
821 | } |
---|
822 | |
---|
823 | // insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label |
---|
824 | // note: as all critical pairs have the same index here, the second sort is done on the terms of the labels |
---|
825 | void CListOld::insert(CPairOld* c) { |
---|
826 | first = first->insert(c); |
---|
827 | } |
---|
828 | |
---|
829 | CNode* CListOld::getFirst() { |
---|
830 | return first; |
---|
831 | } |
---|
832 | |
---|
833 | // get the first elements from CListOld which by the above sorting have minimal degree |
---|
834 | // returns the pointer on the first element of those |
---|
835 | CNode* CListOld::getMinDeg() { |
---|
836 | CNode* temp = first; |
---|
837 | first = first->getMinDeg(); |
---|
838 | return temp; |
---|
839 | } |
---|
840 | |
---|
841 | void CListOld::print() { |
---|
842 | first->print(); |
---|
843 | } |
---|
844 | |
---|
845 | /* |
---|
846 | ==================================== |
---|
847 | functions working on the class RNode |
---|
848 | ==================================== |
---|
849 | */ |
---|
850 | RNode::RNode() { |
---|
851 | //Print("HIER RNODE CONSTRUCTOR\n"); |
---|
852 | data = NULL; |
---|
853 | next = NULL; |
---|
854 | } |
---|
855 | |
---|
856 | RNode::RNode(Rule* r) { |
---|
857 | data = r; |
---|
858 | next = NULL; |
---|
859 | } |
---|
860 | |
---|
861 | RNode::~RNode() { |
---|
862 | //Print("DELETE RULE\n"); |
---|
863 | delete data; |
---|
864 | } |
---|
865 | |
---|
866 | RNode* RNode::insert(Rule* r) { |
---|
867 | RNode* newElement = new RNode(r); |
---|
868 | newElement->next = this; |
---|
869 | return newElement; |
---|
870 | } |
---|
871 | |
---|
872 | RNode* RNode::insert(int i, poly t) { |
---|
873 | //Print("IN INSERT: "); |
---|
874 | //pWrite(t); |
---|
875 | Rule* r = new Rule(i,t); |
---|
876 | //Print("ADDRESS OF RULE: %p\n",r); |
---|
877 | RNode* newElement = new RNode(r); |
---|
878 | //Print("ADDRESS OF RNODE: %p\n",newElement); |
---|
879 | //Print("ADDRESS OF RNODE DATA: %p\n",newElement->getRule()); |
---|
880 | newElement->next = this; |
---|
881 | return newElement; |
---|
882 | } |
---|
883 | |
---|
884 | |
---|
885 | RNode* RNode::insertOrdered(Rule* r) { |
---|
886 | RNode* newElement = new RNode(r); |
---|
887 | RNode* temp = this; |
---|
888 | if(NULL == temp) { |
---|
889 | newElement->next = temp; |
---|
890 | return newElement; |
---|
891 | } |
---|
892 | if(1 == pLmCmp(newElement->getRuleTerm(),temp->getRuleTerm())) { |
---|
893 | newElement->next = temp; |
---|
894 | return newElement; |
---|
895 | } |
---|
896 | else { |
---|
897 | while(NULL != temp && 1 == pLmCmp(temp->getRuleTerm(),newElement->getRuleTerm())) { |
---|
898 | temp = temp->getNext(); |
---|
899 | } |
---|
900 | newElement->next = temp; |
---|
901 | return this; |
---|
902 | } |
---|
903 | } |
---|
904 | |
---|
905 | |
---|
906 | RNode* RNode::getNext() { |
---|
907 | return next; |
---|
908 | } |
---|
909 | |
---|
910 | Rule* RNode::getRule() { |
---|
911 | return data; |
---|
912 | } |
---|
913 | |
---|
914 | int RNode::getRuleIndex() { |
---|
915 | return data->getIndex(); |
---|
916 | } |
---|
917 | |
---|
918 | poly RNode::getRuleTerm() { |
---|
919 | return data->getTerm(); |
---|
920 | } |
---|
921 | |
---|
922 | void RNode::print() { |
---|
923 | RNode* temp = this; |
---|
924 | while(NULL != temp) { |
---|
925 | pWrite(temp->getRuleTerm()); |
---|
926 | Print("%d\n\n",temp->getRuleIndex()); |
---|
927 | temp = temp->getNext(); |
---|
928 | } |
---|
929 | } |
---|
930 | |
---|
931 | /* |
---|
932 | ==================================== |
---|
933 | functions working on the class RList |
---|
934 | ==================================== |
---|
935 | */ |
---|
936 | RList::RList() { |
---|
937 | first = NULL; |
---|
938 | } |
---|
939 | |
---|
940 | RList::RList(Rule* r) { |
---|
941 | first = new RNode(r); |
---|
942 | } |
---|
943 | |
---|
944 | RList::~RList() { |
---|
945 | RNode* temp; |
---|
946 | //Print("%p\n",first); |
---|
947 | while(first) { |
---|
948 | temp = first; |
---|
949 | first = first->getNext(); |
---|
950 | //Print("1 %p\n",first); |
---|
951 | //if(first) { |
---|
952 | //Print("1' %p\n",first->getRule()); |
---|
953 | //Print("2 %p\n",first->getNext()); |
---|
954 | //Print("3 %p\n",first->getNext()->getRule()); |
---|
955 | //Print("3 %p\n",first->getNext()->getRuleTerm()); |
---|
956 | //} |
---|
957 | delete temp; |
---|
958 | } |
---|
959 | //Print("FERTIG\n"); |
---|
960 | } |
---|
961 | |
---|
962 | void RList::insert(int i, poly t) { |
---|
963 | first = first->insert(i,t); |
---|
964 | } |
---|
965 | |
---|
966 | void RList::insert(Rule* r) { |
---|
967 | first = first->insert(r); |
---|
968 | } |
---|
969 | |
---|
970 | void RList::insertOrdered(Rule* r) { |
---|
971 | first = first->insertOrdered(r); |
---|
972 | } |
---|
973 | |
---|
974 | RNode* RList::getFirst() { |
---|
975 | return first; |
---|
976 | } |
---|
977 | |
---|
978 | Rule* RList::getRule() { |
---|
979 | return this->getRule(); |
---|
980 | } |
---|
981 | |
---|
982 | void RList::print() { |
---|
983 | first->print(); |
---|
984 | } |
---|
985 | |
---|
986 | /* |
---|
987 | ======================================= |
---|
988 | functions working on the class RTagNode |
---|
989 | ======================================= |
---|
990 | */ |
---|
991 | |
---|
992 | RTagNode::RTagNode() { |
---|
993 | data = NULL; |
---|
994 | next = NULL; |
---|
995 | } |
---|
996 | |
---|
997 | RTagNode::RTagNode(RNode* r) { |
---|
998 | data = r; |
---|
999 | next = NULL; |
---|
1000 | } |
---|
1001 | |
---|
1002 | RTagNode::RTagNode(RNode* r, RTagNode* n) { |
---|
1003 | |
---|
1004 | data = r; |
---|
1005 | next = n; |
---|
1006 | } |
---|
1007 | |
---|
1008 | RTagNode::~RTagNode() { |
---|
1009 | delete data; |
---|
1010 | } |
---|
1011 | |
---|
1012 | // declaration with first as parameter due to sorting of RTagList |
---|
1013 | RTagNode* RTagNode::insert(RNode* r) { |
---|
1014 | //Print("Hier1\n"); |
---|
1015 | RTagNode* newElement = new RTagNode(r, this); |
---|
1016 | //Print("Hier2\n"); |
---|
1017 | return newElement; |
---|
1018 | } |
---|
1019 | |
---|
1020 | RNode* RTagNode::getRNode() { |
---|
1021 | //Print("%p\n", this); |
---|
1022 | //Print("%p\n",this->data); |
---|
1023 | return this->data; |
---|
1024 | } |
---|
1025 | |
---|
1026 | RTagNode* RTagNode::getNext() { |
---|
1027 | return next; |
---|
1028 | } |
---|
1029 | |
---|
1030 | // NOTE: We insert at the beginning of the list and length = i-1, where i is the actual index. |
---|
1031 | // Thus given actual index i and idx being the index of the LPoly under investigation |
---|
1032 | // the element on position length-idx+1 is the right one |
---|
1033 | RNode* RTagNode::get(int idx, int length) { |
---|
1034 | if(idx==1 || idx==0) { |
---|
1035 | // NOTE: We set this NULL as putting it the last element in the list, i.e. the element having |
---|
1036 | // RNode* = NULL would cost lots of iterations at each step of F5inc, with increasing |
---|
1037 | // length of the list this should be prevented |
---|
1038 | return NULL; |
---|
1039 | } |
---|
1040 | else { |
---|
1041 | int j; |
---|
1042 | RTagNode* temp = this; |
---|
1043 | //Print("\n\nHIER IN GET IDX\n"); |
---|
1044 | //Print("FOR LOOP: %d\n",length-idx+1); |
---|
1045 | for(j=1; j<=length-idx+1; j++) { |
---|
1046 | temp = temp->next; |
---|
1047 | } |
---|
1048 | return temp->data; |
---|
1049 | } |
---|
1050 | } |
---|
1051 | |
---|
1052 | void RTagNode::set(RNode* r) { |
---|
1053 | this->data = r; |
---|
1054 | } |
---|
1055 | |
---|
1056 | |
---|
1057 | void RTagNode::print() { |
---|
1058 | RTagNode* temp = this; |
---|
1059 | if(NULL != temp && NULL != temp->getRNode()) { |
---|
1060 | Print("1. element: %d, ",getRNode()->getRule()->getIndex()); |
---|
1061 | pWrite(getRNode()->getRule()->getTerm()); |
---|
1062 | temp = temp->next; |
---|
1063 | int i = 2; |
---|
1064 | while(NULL != temp->getRNode() && NULL != temp) { |
---|
1065 | Print("%d. element: %d, ",i,getRNode()->getRule()->getIndex()); |
---|
1066 | pWrite(getRNode()->getRule()->getTerm()); |
---|
1067 | temp = temp->next; |
---|
1068 | i++; |
---|
1069 | } |
---|
1070 | } |
---|
1071 | } |
---|
1072 | |
---|
1073 | /* |
---|
1074 | ======================================= |
---|
1075 | functions working on the class LTagList |
---|
1076 | ======================================= |
---|
1077 | */ |
---|
1078 | |
---|
1079 | RTagList::RTagList() { |
---|
1080 | RTagNode* first = new RTagNode(); |
---|
1081 | length = 0; |
---|
1082 | } |
---|
1083 | |
---|
1084 | RTagList::RTagList(RNode* r) { |
---|
1085 | RTagNode* first = new RTagNode(r); |
---|
1086 | length = 1; |
---|
1087 | } |
---|
1088 | |
---|
1089 | RTagList::~RTagList() { |
---|
1090 | RTagNode* temp; |
---|
1091 | while(first) { |
---|
1092 | temp = first; |
---|
1093 | first = first->getNext(); |
---|
1094 | delete temp; |
---|
1095 | } |
---|
1096 | } |
---|
1097 | |
---|
1098 | // declaration with first as parameter in LTagNode due to sorting of LTagList |
---|
1099 | void RTagList::insert(RNode* r) { |
---|
1100 | first = first->insert(r); |
---|
1101 | //Print("LENGTH:%d\n",length); |
---|
1102 | length = length +1; |
---|
1103 | //Print("LENGTH:%d\n",length); |
---|
1104 | } |
---|
1105 | |
---|
1106 | RNode* RTagList::getFirst() { |
---|
1107 | return first->getRNode(); |
---|
1108 | } |
---|
1109 | |
---|
1110 | RNode* RTagList::get(int idx) { |
---|
1111 | return first->get(idx, length); |
---|
1112 | } |
---|
1113 | |
---|
1114 | void RTagList::setFirst(RNode* r) { |
---|
1115 | first->set(r); |
---|
1116 | } |
---|
1117 | |
---|
1118 | void RTagList::print() { |
---|
1119 | first->print(); |
---|
1120 | } |
---|
1121 | |
---|
1122 | int RTagList::getLength() { |
---|
1123 | return length; |
---|
1124 | } |
---|
1125 | #endif |
---|