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 CList |
---|
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 | bool LNode::getDel() { |
---|
247 | return data->getDel(); |
---|
248 | } |
---|
249 | |
---|
250 | // set the data from the LPoly saved in LNode |
---|
251 | void LNode::setPoly(poly p) { |
---|
252 | data->setPoly(p); |
---|
253 | } |
---|
254 | |
---|
255 | void LNode::setTerm(poly t) { |
---|
256 | data->setTerm(t); |
---|
257 | } |
---|
258 | |
---|
259 | void LNode::setIndex(int i) { |
---|
260 | data->setIndex(i); |
---|
261 | } |
---|
262 | |
---|
263 | void LNode::setNext(LNode* l) { |
---|
264 | next = l; |
---|
265 | } |
---|
266 | |
---|
267 | void LNode::setDel(bool d) { |
---|
268 | data->setDel(d); |
---|
269 | } |
---|
270 | |
---|
271 | // test if for any list element the polynomial part of the data is equal to *p |
---|
272 | bool LNode::polyTest(poly* p) { |
---|
273 | LNode* temp = new LNode(this); |
---|
274 | while(NULL != temp) { |
---|
275 | if(pComparePolys(temp->getPoly(),*p)) { |
---|
276 | return 1; |
---|
277 | } |
---|
278 | temp = temp->next; |
---|
279 | } |
---|
280 | return 0; |
---|
281 | } |
---|
282 | |
---|
283 | LNode* LNode::getNext(LNode* l) { |
---|
284 | return l->next; |
---|
285 | } |
---|
286 | |
---|
287 | // for debugging |
---|
288 | void LNode::print() { |
---|
289 | LNode* temp = this; |
---|
290 | Print("___________________List of S-polynomials______________________:\n"); |
---|
291 | Print("%p\n",this); |
---|
292 | while(NULL != temp && NULL != temp->data) { |
---|
293 | Print("Index: %d\n",temp->getIndex()); |
---|
294 | Print("Term: "); |
---|
295 | pWrite(temp->getTerm()); |
---|
296 | Print("Poly: "); |
---|
297 | pWrite(temp->getPoly()); |
---|
298 | Print("%p\n",temp->getPoly()); |
---|
299 | Print("DELETE? %d\n",temp->getDel()); |
---|
300 | temp = temp->next; |
---|
301 | } |
---|
302 | Print("_______________________________________________________________\n"); |
---|
303 | } |
---|
304 | |
---|
305 | int LNode::count(LNode* l) { |
---|
306 | int nonDel = 0; |
---|
307 | LNode* temp = l; |
---|
308 | while(NULL != temp) { |
---|
309 | if(!temp->getDel()) { |
---|
310 | nonDel++; |
---|
311 | temp = temp->next; |
---|
312 | } |
---|
313 | else { |
---|
314 | temp = temp->next; |
---|
315 | } |
---|
316 | } |
---|
317 | return nonDel; |
---|
318 | } |
---|
319 | |
---|
320 | /* |
---|
321 | ==================================== |
---|
322 | functions working on the class LList |
---|
323 | ==================================== |
---|
324 | */ |
---|
325 | |
---|
326 | LList::LList() { |
---|
327 | first = last = NULL;; |
---|
328 | length = 0; |
---|
329 | } |
---|
330 | |
---|
331 | LList::LList(LPoly* lp) { |
---|
332 | first = new LNode(lp); |
---|
333 | last = first; |
---|
334 | length = 1; |
---|
335 | } |
---|
336 | |
---|
337 | LList::LList(poly t,int i,poly p,Rule* r) { |
---|
338 | first = new LNode(t,i,p,r); |
---|
339 | last = first; |
---|
340 | length = 1; |
---|
341 | } |
---|
342 | |
---|
343 | LList::~LList() { |
---|
344 | LNode* temp; |
---|
345 | while(first) { |
---|
346 | temp = first; |
---|
347 | first = first->getNext(); |
---|
348 | delete temp; |
---|
349 | //Print("%p\n",first); |
---|
350 | } |
---|
351 | } |
---|
352 | |
---|
353 | // insertion at the end of the list, needed for gPrev |
---|
354 | void LList::insert(LPoly* lp) { |
---|
355 | last = last->insert(lp); |
---|
356 | if(NULL == first) { |
---|
357 | first = last; |
---|
358 | } |
---|
359 | //Print("NEW LAST GPREV: "); |
---|
360 | //pWrite(last->getPoly()); |
---|
361 | //Print("%p\n",first); |
---|
362 | //pWrite(first->getPoly()); |
---|
363 | length++; |
---|
364 | //Print("LENGTH %d\n",length); |
---|
365 | } |
---|
366 | |
---|
367 | void LList::insert(poly t,int i, poly p, Rule* r) { |
---|
368 | last = last->insert(t,i,p,r); |
---|
369 | if(NULL == first) { |
---|
370 | first = last; |
---|
371 | } |
---|
372 | length++; |
---|
373 | //Print("LENGTH %d\n",length); |
---|
374 | } |
---|
375 | |
---|
376 | // insertion in front of the list, needed for sPolyList |
---|
377 | void LList::insertSP(LPoly* lp) { |
---|
378 | first = first->insertSP(lp); |
---|
379 | length++; |
---|
380 | //Print("LENGTH %d\n",length); |
---|
381 | } |
---|
382 | |
---|
383 | void LList::insertSP(poly t,int i, poly p, Rule* r) { |
---|
384 | first = first->insertSP(t,i,p,r); |
---|
385 | length++; |
---|
386 | //Print("LENGTH %d\n",length); |
---|
387 | } |
---|
388 | |
---|
389 | |
---|
390 | void LList::insertByLabel(poly t, int i, poly p, Rule* r) { |
---|
391 | first = first->insertByLabel(t,i,p,r); |
---|
392 | length++; |
---|
393 | //Print("LENGTH %d\n",length); |
---|
394 | } |
---|
395 | |
---|
396 | void LList::insertFirst(LNode* l) { |
---|
397 | first = first->insertFirst(l); |
---|
398 | length++; |
---|
399 | //Print("LENGTH %d\n",length); |
---|
400 | } |
---|
401 | |
---|
402 | void LList::insertByLabel(LNode* l) { |
---|
403 | first = first->insertByLabel(l); |
---|
404 | length++; |
---|
405 | //Print("LENGTH %d\n",length); |
---|
406 | } |
---|
407 | |
---|
408 | void LList::deleteByDeg() { |
---|
409 | first = first->deleteByDeg(); |
---|
410 | } |
---|
411 | |
---|
412 | bool LList::polyTest(poly* p) { |
---|
413 | return first->polyTest(p); |
---|
414 | } |
---|
415 | |
---|
416 | LNode* LList::getFirst() { |
---|
417 | return first; |
---|
418 | } |
---|
419 | |
---|
420 | LNode* LList::getLast() { |
---|
421 | return last; |
---|
422 | } |
---|
423 | |
---|
424 | int LList::getLength() { |
---|
425 | return length; |
---|
426 | } |
---|
427 | |
---|
428 | void LList::setFirst(LNode* l) { |
---|
429 | LNode* temp = first; |
---|
430 | temp->setNext(NULL); |
---|
431 | first = l; |
---|
432 | length--; |
---|
433 | } |
---|
434 | |
---|
435 | void LList::print() { |
---|
436 | first->print(); |
---|
437 | } |
---|
438 | |
---|
439 | int LList::count(LNode* l) { |
---|
440 | return first->count(l); |
---|
441 | } |
---|
442 | /* |
---|
443 | ======================================= |
---|
444 | functions working on the class LTagNode |
---|
445 | ======================================= |
---|
446 | */ |
---|
447 | LTagNode::LTagNode() { |
---|
448 | data = NULL; |
---|
449 | next = NULL; |
---|
450 | } |
---|
451 | |
---|
452 | LTagNode::LTagNode(LNode* l) { |
---|
453 | data = l; |
---|
454 | next = NULL; |
---|
455 | } |
---|
456 | |
---|
457 | LTagNode::LTagNode(LNode* l, LTagNode* n) { |
---|
458 | data = l; |
---|
459 | next = n; |
---|
460 | } |
---|
461 | |
---|
462 | LTagNode::~LTagNode() { |
---|
463 | delete data; |
---|
464 | } |
---|
465 | |
---|
466 | // declaration with first as parameter due to sorting of LTagList |
---|
467 | LTagNode* LTagNode::insert(LNode* l) { |
---|
468 | LTagNode* newElement = new LTagNode(l, this); |
---|
469 | return newElement; |
---|
470 | } |
---|
471 | |
---|
472 | LNode* LTagNode::getLNode() { |
---|
473 | return this->data; |
---|
474 | } |
---|
475 | |
---|
476 | LTagNode* LTagNode::getNext() { |
---|
477 | return next; |
---|
478 | } |
---|
479 | |
---|
480 | // NOTE: We insert at the beginning of the list and length = i-1, where i is the actual index. |
---|
481 | // Thus given actual index i and idx being the index of the LPoly under investigation |
---|
482 | // the element on position length-idx is the right one |
---|
483 | LNode* LTagNode::get(int idx, int length) { |
---|
484 | if(idx == 1) { |
---|
485 | return NULL; |
---|
486 | } |
---|
487 | else { |
---|
488 | int j; |
---|
489 | LTagNode* temp = this; // last |
---|
490 | for(j=1;j<=length-idx+1;j++) { |
---|
491 | temp = temp->next; |
---|
492 | } |
---|
493 | return temp->data; |
---|
494 | } |
---|
495 | } |
---|
496 | |
---|
497 | |
---|
498 | /* |
---|
499 | ======================================= |
---|
500 | functions working on the class LTagList |
---|
501 | ======================================= |
---|
502 | */ |
---|
503 | LTagList::LTagList() { |
---|
504 | LTagNode* first = new LTagNode(); |
---|
505 | |
---|
506 | length = 0; |
---|
507 | } |
---|
508 | |
---|
509 | LTagList::LTagList(LNode* l) { |
---|
510 | LTagNode* first = new LTagNode(l); |
---|
511 | length = 1; |
---|
512 | } |
---|
513 | |
---|
514 | LTagList::~LTagList() { |
---|
515 | LTagNode* temp; |
---|
516 | while(first) { |
---|
517 | temp = first; |
---|
518 | first = first->getNext(); |
---|
519 | delete temp; |
---|
520 | //Print("%p\n",first); |
---|
521 | } |
---|
522 | } |
---|
523 | |
---|
524 | // declaration with first as parameter in LTagNode due to sorting of LTagList |
---|
525 | void LTagList::insert(LNode* l) { |
---|
526 | first = first->insert(l); |
---|
527 | length++; |
---|
528 | } |
---|
529 | |
---|
530 | void LTagList::setFirstCurrentIdx(LNode* l) { |
---|
531 | firstCurrentIdx = l; |
---|
532 | } |
---|
533 | |
---|
534 | LNode* LTagList::get(int idx) { |
---|
535 | return first->get(idx, length); |
---|
536 | } |
---|
537 | |
---|
538 | LNode* LTagList::getFirst() { |
---|
539 | return first->getLNode(); |
---|
540 | } |
---|
541 | |
---|
542 | LNode* LTagList::getFirstCurrentIdx() { |
---|
543 | return firstCurrentIdx; |
---|
544 | } |
---|
545 | |
---|
546 | /* |
---|
547 | ===================================== |
---|
548 | functions working on the class TopRed |
---|
549 | ===================================== |
---|
550 | */ |
---|
551 | |
---|
552 | TopRed::TopRed() { |
---|
553 | _completed = NULL; |
---|
554 | _toDo = NULL; |
---|
555 | } |
---|
556 | |
---|
557 | TopRed::TopRed(LList* c, LList* t) { |
---|
558 | _completed = c; |
---|
559 | _toDo = t; |
---|
560 | } |
---|
561 | |
---|
562 | LList* TopRed::getCompleted() { |
---|
563 | return _completed; |
---|
564 | } |
---|
565 | |
---|
566 | LList* TopRed::getToDo() { |
---|
567 | return _toDo; |
---|
568 | } |
---|
569 | |
---|
570 | /* |
---|
571 | ==================================== |
---|
572 | functions working on the class CNode |
---|
573 | ==================================== |
---|
574 | */ |
---|
575 | |
---|
576 | CNode::CNode() { |
---|
577 | data = NULL; |
---|
578 | next = NULL; |
---|
579 | } |
---|
580 | |
---|
581 | CNode::CNode(CPair* c) { |
---|
582 | data = c; |
---|
583 | next = NULL; |
---|
584 | } |
---|
585 | |
---|
586 | CNode::CNode(CPair* c, CNode* n) { |
---|
587 | data = c; |
---|
588 | next = n; |
---|
589 | } |
---|
590 | |
---|
591 | CNode::~CNode() { |
---|
592 | delete data; |
---|
593 | } |
---|
594 | |
---|
595 | // insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label |
---|
596 | // note: as all critical pairs have the same index here, the second sort is done on the terms of the labels |
---|
597 | // working only with linked, but not doubly linked lists due to memory usage we have to check the |
---|
598 | // insertion around the first element separately from the insertion around all other elements in the list |
---|
599 | CNode* CNode::insert(CPair* c) { |
---|
600 | if(NULL == this) { |
---|
601 | CNode* newElement = new CNode(c, this); |
---|
602 | return newElement; |
---|
603 | } |
---|
604 | else { |
---|
605 | poly u1 = ppMult_qq(c->getT1(),c->getLp1Term()); |
---|
606 | if( c->getDeg() < this->data->getDeg() ) { // lower degree than the first list element |
---|
607 | CNode* newElement = new CNode(c, this); |
---|
608 | return newElement; |
---|
609 | } |
---|
610 | if( c->getDeg() == this->data->getDeg() ) { // same degree than the first list element |
---|
611 | if(1 != pLmCmp(u1,ppMult_qq(this->data->getT1(), this->data->getLp1Term()))) { |
---|
612 | //pWrite(u1); |
---|
613 | //Print("Multi-Term in CritPairs Sortierung altes Element: "); |
---|
614 | //pWrite(ppMult_qq(this->data->getT1(),this->data->getLp1Term())); |
---|
615 | CNode* newElement = new CNode(c, this); |
---|
616 | return newElement; |
---|
617 | } |
---|
618 | else { |
---|
619 | //Print("Insert Deg\n"); |
---|
620 | CNode* temp = this; |
---|
621 | while( NULL != temp->next) { |
---|
622 | if(temp->next->data->getDeg() == c->getDeg() ) { |
---|
623 | if(1 == pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),temp->next->data->getLp1Term()))) { |
---|
624 | temp = temp->next; |
---|
625 | } |
---|
626 | else { |
---|
627 | CNode* newElement = new CNode(c, temp->next); |
---|
628 | temp->next = newElement; |
---|
629 | return this; |
---|
630 | } |
---|
631 | } |
---|
632 | else { |
---|
633 | CNode* newElement = new CNode(c, temp->next); |
---|
634 | temp->next = newElement; |
---|
635 | return this; |
---|
636 | } |
---|
637 | } |
---|
638 | CNode* newElement = new CNode(c, NULL); |
---|
639 | temp->next = newElement; |
---|
640 | return this; |
---|
641 | } |
---|
642 | } // outer if-clause |
---|
643 | if( c->getDeg() > this->data->getDeg() ) { // greater degree than the first list element |
---|
644 | CNode* temp = this; |
---|
645 | while( NULL != temp->next ) { |
---|
646 | if( c->getDeg() < temp->next->data->getDeg() ) { |
---|
647 | CNode* newElement = new CNode(c, temp->next); |
---|
648 | temp->next = newElement; |
---|
649 | return this; |
---|
650 | } |
---|
651 | if( c->getDeg() == temp->next->data->getDeg() ) { |
---|
652 | if(1 != pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),temp->next->data->getLp1Term()))) { |
---|
653 | CNode* newElement = new CNode(c, temp->next); |
---|
654 | temp->next = newElement; |
---|
655 | return this; |
---|
656 | } |
---|
657 | else { |
---|
658 | temp = temp->next; |
---|
659 | while( NULL != temp->next ) { |
---|
660 | if( temp->next->data->getDeg() == c->getDeg() ) { |
---|
661 | if(1 == pLmCmp(u1,ppMult_qq(temp->next->data->getT1(), |
---|
662 | temp->next->data->getLp1Term()))) { |
---|
663 | temp = temp->next; |
---|
664 | } |
---|
665 | else { |
---|
666 | CNode* newElement = new CNode(c, temp->next); |
---|
667 | temp->next = newElement; |
---|
668 | return this; |
---|
669 | } |
---|
670 | } |
---|
671 | else { |
---|
672 | CNode* newElement = new CNode(c, temp->next); |
---|
673 | temp->next = newElement; |
---|
674 | return this; |
---|
675 | } |
---|
676 | } |
---|
677 | CNode* newElement = new CNode(c, NULL); |
---|
678 | temp->next = newElement; |
---|
679 | return this; |
---|
680 | } |
---|
681 | } |
---|
682 | if( c->getDeg() > temp->next->data->getDeg() ) { |
---|
683 | temp = temp->next; |
---|
684 | } |
---|
685 | } |
---|
686 | CNode* newElement = new CNode(c, NULL); |
---|
687 | temp->next = newElement; |
---|
688 | return this; |
---|
689 | } |
---|
690 | } |
---|
691 | } |
---|
692 | |
---|
693 | // get the first elements from CList which by the above sorting have minimal degree |
---|
694 | CNode* CNode::getMinDeg() { |
---|
695 | CNode* temp = this; |
---|
696 | while(NULL != temp) { |
---|
697 | while(NULL != temp->next && temp->next->data->getDeg() == this->data->getDeg()) { |
---|
698 | temp = temp->next; |
---|
699 | } |
---|
700 | CNode* returnCNode = temp->next; |
---|
701 | // every CList should end with a (NULL,NULL) element for a similar behaviour |
---|
702 | // using termination conditions throughout the algorithm |
---|
703 | temp->next = NULL; |
---|
704 | return returnCNode; |
---|
705 | } |
---|
706 | return NULL; |
---|
707 | } |
---|
708 | |
---|
709 | CPair* CNode::getData() { |
---|
710 | return data; |
---|
711 | } |
---|
712 | |
---|
713 | CNode* CNode::getNext() { |
---|
714 | return next; |
---|
715 | } |
---|
716 | |
---|
717 | LPoly* CNode::getAdLp1() { |
---|
718 | return this->data->getAdLp1(); |
---|
719 | } |
---|
720 | |
---|
721 | LPoly* CNode::getAdLp2() { |
---|
722 | return this->data->getAdLp2(); |
---|
723 | } |
---|
724 | |
---|
725 | poly CNode::getLp1Poly() { |
---|
726 | return this->data->getLp1Poly(); |
---|
727 | } |
---|
728 | |
---|
729 | poly CNode::getLp2Poly() { |
---|
730 | return this->data->getLp2Poly(); |
---|
731 | } |
---|
732 | |
---|
733 | poly CNode::getLp1Term() { |
---|
734 | return this->data->getLp1Term(); |
---|
735 | } |
---|
736 | |
---|
737 | poly CNode::getLp2Term() { |
---|
738 | return this->data->getLp2Term(); |
---|
739 | } |
---|
740 | |
---|
741 | int CNode::getLp1Index() { |
---|
742 | return this->data->getLp1Index(); |
---|
743 | } |
---|
744 | |
---|
745 | int CNode::getLp2Index() { |
---|
746 | return this->data->getLp2Index(); |
---|
747 | } |
---|
748 | |
---|
749 | poly CNode::getT1() { |
---|
750 | return this->data->getT1(); |
---|
751 | } |
---|
752 | |
---|
753 | poly* CNode::getAdT1() { |
---|
754 | return this->data->getAdT1(); |
---|
755 | } |
---|
756 | |
---|
757 | poly CNode::getT2() { |
---|
758 | return this->data->getT2(); |
---|
759 | } |
---|
760 | |
---|
761 | poly* CNode::getAdT2() { |
---|
762 | return this->data->getAdT2(); |
---|
763 | } |
---|
764 | |
---|
765 | Rule* CNode::getTestedRule() { |
---|
766 | return this->data->getTestedRule(); |
---|
767 | } |
---|
768 | |
---|
769 | // for debugging |
---|
770 | void CNode::print() { |
---|
771 | CNode* temp = this; |
---|
772 | Print("___________________List of critical pairs______________________:\n"); |
---|
773 | while(NULL != temp) { |
---|
774 | pWrite(ppMult_qq(temp->getT1(),temp->getLp1Term())); |
---|
775 | Print("LP1 Index: %d\n",temp->getLp1Index()); |
---|
776 | Print("T1: "); |
---|
777 | pWrite(temp->getT1()); |
---|
778 | Print("%p\n",temp->getT1()); |
---|
779 | Print("LP1 Term: "); |
---|
780 | pWrite(temp->getLp1Term()); |
---|
781 | Print("LP1 Poly: "); |
---|
782 | pWrite(temp->getLp1Poly()); |
---|
783 | Print("LP2 Index: %d\n",temp->getLp2Index()); |
---|
784 | Print("T2: "); |
---|
785 | pWrite(temp->getT2()); |
---|
786 | Print("%p\n",temp->getT2()); |
---|
787 | Print("LP2 Term: "); |
---|
788 | pWrite(temp->getLp2Term()); |
---|
789 | Print("LP2 Poly: "); |
---|
790 | pWrite(temp->getLp2Poly()); |
---|
791 | Print("\n"); |
---|
792 | temp = temp->next; |
---|
793 | } |
---|
794 | } |
---|
795 | |
---|
796 | /* |
---|
797 | ==================================== |
---|
798 | functions working on the class CList |
---|
799 | ==================================== |
---|
800 | */ |
---|
801 | // for initialization of CLists, last element alwas has data=NULL and next=NULL |
---|
802 | CList::CList() { |
---|
803 | first = NULL; |
---|
804 | } |
---|
805 | |
---|
806 | CList::CList(CPair* c) { |
---|
807 | first = new CNode(c); |
---|
808 | } |
---|
809 | |
---|
810 | CList::~CList() { |
---|
811 | CNode* temp; |
---|
812 | while(NULL != first) { |
---|
813 | temp = first; |
---|
814 | first = first->getNext(); |
---|
815 | delete temp; |
---|
816 | } |
---|
817 | } |
---|
818 | |
---|
819 | // insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label |
---|
820 | // note: as all critical pairs have the same index here, the second sort is done on the terms of the labels |
---|
821 | void CList::insert(CPair* c) { |
---|
822 | first = first->insert(c); |
---|
823 | } |
---|
824 | |
---|
825 | CNode* CList::getFirst() { |
---|
826 | return first; |
---|
827 | } |
---|
828 | |
---|
829 | // get the first elements from CList which by the above sorting have minimal degree |
---|
830 | // returns the pointer on the first element of those |
---|
831 | CNode* CList::getMinDeg() { |
---|
832 | CNode* temp = first; |
---|
833 | first = first->getMinDeg(); |
---|
834 | return temp; |
---|
835 | } |
---|
836 | |
---|
837 | void CList::print() { |
---|
838 | first->print(); |
---|
839 | } |
---|
840 | |
---|
841 | /* |
---|
842 | ==================================== |
---|
843 | functions working on the class RNode |
---|
844 | ==================================== |
---|
845 | */ |
---|
846 | RNode::RNode() { |
---|
847 | //Print("HIER RNODE CONSTRUCTOR\n"); |
---|
848 | data = NULL; |
---|
849 | next = NULL; |
---|
850 | } |
---|
851 | |
---|
852 | RNode::RNode(Rule* r) { |
---|
853 | data = r; |
---|
854 | next = NULL; |
---|
855 | } |
---|
856 | |
---|
857 | RNode::~RNode() { |
---|
858 | //Print("DELETE RULE\n"); |
---|
859 | delete data; |
---|
860 | } |
---|
861 | |
---|
862 | RNode* RNode::insert(Rule* r) { |
---|
863 | RNode* newElement = new RNode(r); |
---|
864 | newElement->next = this; |
---|
865 | return newElement; |
---|
866 | } |
---|
867 | |
---|
868 | RNode* RNode::insert(int i, poly t) { |
---|
869 | //Print("IN INSERT: "); |
---|
870 | //pWrite(t); |
---|
871 | Rule* r = new Rule(i,t); |
---|
872 | //Print("ADDRESS OF RULE: %p\n",r); |
---|
873 | RNode* newElement = new RNode(r); |
---|
874 | //Print("ADDRESS OF RNODE: %p\n",newElement); |
---|
875 | //Print("ADDRESS OF RNODE DATA: %p\n",newElement->getRule()); |
---|
876 | newElement->next = this; |
---|
877 | return newElement; |
---|
878 | |
---|
879 | /* |
---|
880 | * not useful, as it does not only adds new rules to be tested but also |
---|
881 | * deletes rules to be tested if a rule is set to another place in the line |
---|
882 | * |
---|
883 | if(NULL == this || this->getRuleIndex() < newElement->getRuleIndex()) { |
---|
884 | newElement->next = this; |
---|
885 | } |
---|
886 | else { |
---|
887 | if(pDeg(newElement->getRuleTerm()) > pDeg(this->getRuleTerm())) { |
---|
888 | newElement->next = this; |
---|
889 | } |
---|
890 | if(-1 == pLmCmp(newElement->getRuleTerm(),this->getRuleTerm())) { |
---|
891 | Print("HAHI\n"); |
---|
892 | Print("%ld\n",pDeg(newElement->getRuleTerm())); |
---|
893 | Print("%ld\n",pDeg(this->getRuleTerm())); |
---|
894 | |
---|
895 | pWrite(newElement->getRuleTerm()); |
---|
896 | pWrite(this->getRuleTerm()); |
---|
897 | RNode* temp = this; |
---|
898 | while(NULL != temp->next && pDeg(newElement->getRuleTerm()) <= pDeg(temp->next->getRuleTerm()) |
---|
899 | && -1 == pLmCmp(newElement->getRuleTerm(),temp->next->getRuleTerm())) { |
---|
900 | temp = temp->next; |
---|
901 | } |
---|
902 | newElement->next = temp->next; |
---|
903 | temp->next = newElement; |
---|
904 | return this; |
---|
905 | } |
---|
906 | else { |
---|
907 | newElement->next = this; |
---|
908 | return newElement; |
---|
909 | } |
---|
910 | } |
---|
911 | return newElement; |
---|
912 | */ |
---|
913 | } |
---|
914 | |
---|
915 | RNode* RNode::getNext() { |
---|
916 | return next; |
---|
917 | } |
---|
918 | |
---|
919 | Rule* RNode::getRule() { |
---|
920 | return data; |
---|
921 | } |
---|
922 | |
---|
923 | int RNode::getRuleIndex() { |
---|
924 | return data->getIndex(); |
---|
925 | } |
---|
926 | |
---|
927 | poly RNode::getRuleTerm() { |
---|
928 | return data->getTerm(); |
---|
929 | } |
---|
930 | |
---|
931 | void RNode::print() { |
---|
932 | RNode* temp = this; |
---|
933 | while(NULL != temp) { |
---|
934 | pWrite(temp->getRuleTerm()); |
---|
935 | Print("%d\n\n",temp->getRuleIndex()); |
---|
936 | temp = temp->getNext(); |
---|
937 | } |
---|
938 | } |
---|
939 | |
---|
940 | /* |
---|
941 | ==================================== |
---|
942 | functions working on the class RList |
---|
943 | ==================================== |
---|
944 | */ |
---|
945 | RList::RList() { |
---|
946 | first = NULL; |
---|
947 | } |
---|
948 | |
---|
949 | RList::RList(Rule* r) { |
---|
950 | first = new RNode(r); |
---|
951 | } |
---|
952 | |
---|
953 | RList::~RList() { |
---|
954 | RNode* temp; |
---|
955 | //Print("%p\n",first); |
---|
956 | while(first) { |
---|
957 | temp = first; |
---|
958 | first = first->getNext(); |
---|
959 | //Print("1 %p\n",first); |
---|
960 | //if(first) { |
---|
961 | //Print("1' %p\n",first->getRule()); |
---|
962 | //Print("2 %p\n",first->getNext()); |
---|
963 | //Print("3 %p\n",first->getNext()->getRule()); |
---|
964 | //Print("3 %p\n",first->getNext()->getRuleTerm()); |
---|
965 | //} |
---|
966 | delete temp; |
---|
967 | } |
---|
968 | //Print("FERTIG\n"); |
---|
969 | } |
---|
970 | |
---|
971 | void RList::insert(int i, poly t) { |
---|
972 | first = first->insert(i,t); |
---|
973 | } |
---|
974 | |
---|
975 | void RList::insert(Rule* r) { |
---|
976 | first = first->insert(r); |
---|
977 | } |
---|
978 | |
---|
979 | RNode* RList::getFirst() { |
---|
980 | return first; |
---|
981 | } |
---|
982 | |
---|
983 | Rule* RList::getRule() { |
---|
984 | return this->getRule(); |
---|
985 | } |
---|
986 | |
---|
987 | void RList::print() { |
---|
988 | first->print(); |
---|
989 | } |
---|
990 | |
---|
991 | /* |
---|
992 | ======================================= |
---|
993 | functions working on the class RTagNode |
---|
994 | ======================================= |
---|
995 | */ |
---|
996 | |
---|
997 | RTagNode::RTagNode() { |
---|
998 | data = NULL; |
---|
999 | next = NULL; |
---|
1000 | } |
---|
1001 | |
---|
1002 | RTagNode::RTagNode(RNode* r) { |
---|
1003 | data = r; |
---|
1004 | next = NULL; |
---|
1005 | } |
---|
1006 | |
---|
1007 | RTagNode::RTagNode(RNode* r, RTagNode* n) { |
---|
1008 | |
---|
1009 | data = r; |
---|
1010 | next = n; |
---|
1011 | } |
---|
1012 | |
---|
1013 | RTagNode::~RTagNode() { |
---|
1014 | delete data; |
---|
1015 | } |
---|
1016 | |
---|
1017 | // declaration with first as parameter due to sorting of RTagList |
---|
1018 | RTagNode* RTagNode::insert(RNode* r) { |
---|
1019 | //Print("Hier1\n"); |
---|
1020 | RTagNode* newElement = new RTagNode(r, this); |
---|
1021 | //Print("Hier2\n"); |
---|
1022 | return newElement; |
---|
1023 | } |
---|
1024 | |
---|
1025 | RNode* RTagNode::getRNode() { |
---|
1026 | return this->data; |
---|
1027 | } |
---|
1028 | |
---|
1029 | RTagNode* RTagNode::getNext() { |
---|
1030 | return next; |
---|
1031 | } |
---|
1032 | |
---|
1033 | // NOTE: We insert at the beginning of the list and length = i-1, where i is the actual index. |
---|
1034 | // Thus given actual index i and idx being the index of the LPoly under investigation |
---|
1035 | // the element on position length-idx+1 is the right one |
---|
1036 | RNode* RTagNode::get(int idx, int length) { |
---|
1037 | if(idx==1 || idx==0) { |
---|
1038 | // NOTE: We set this NULL as putting it the last element in the list, i.e. the element having |
---|
1039 | // RNode* = NULL would cost lots of iterations at each step of F5inc, with increasing |
---|
1040 | // length of the list this should be prevented |
---|
1041 | return NULL; |
---|
1042 | } |
---|
1043 | else { |
---|
1044 | int j; |
---|
1045 | RTagNode* temp = this; |
---|
1046 | //Print("\n\nHIER IN GET IDX\n"); |
---|
1047 | //Print("FOR LOOP: %d\n",length-idx+1); |
---|
1048 | for(j=1; j<=length-idx+1; j++) { |
---|
1049 | temp = temp->next; |
---|
1050 | } |
---|
1051 | return temp->data; |
---|
1052 | } |
---|
1053 | } |
---|
1054 | |
---|
1055 | void RTagNode::set(RNode* r) { |
---|
1056 | this->data = r; |
---|
1057 | } |
---|
1058 | |
---|
1059 | void RTagNode::print() { |
---|
1060 | RTagNode* temp = this; |
---|
1061 | if(NULL != temp && NULL != temp->getRNode()) { |
---|
1062 | Print("1. element: %d, ",getRNode()->getRule()->getIndex()); |
---|
1063 | pWrite(getRNode()->getRule()->getTerm()); |
---|
1064 | temp = temp->next; |
---|
1065 | int i = 2; |
---|
1066 | while(NULL != temp->getRNode() && NULL != temp) { |
---|
1067 | Print("%d. element: %d, ",i,getRNode()->getRule()->getIndex()); |
---|
1068 | pWrite(getRNode()->getRule()->getTerm()); |
---|
1069 | temp = temp->next; |
---|
1070 | i++; |
---|
1071 | } |
---|
1072 | } |
---|
1073 | } |
---|
1074 | /* |
---|
1075 | ======================================= |
---|
1076 | functions working on the class LTagList |
---|
1077 | ======================================= |
---|
1078 | */ |
---|
1079 | |
---|
1080 | RTagList::RTagList() { |
---|
1081 | RTagNode* first = new RTagNode(); |
---|
1082 | length = 0; |
---|
1083 | } |
---|
1084 | |
---|
1085 | RTagList::RTagList(RNode* r) { |
---|
1086 | RTagNode* first = new RTagNode(r); |
---|
1087 | length = 1; |
---|
1088 | } |
---|
1089 | |
---|
1090 | RTagList::~RTagList() { |
---|
1091 | RTagNode* temp; |
---|
1092 | while(first) { |
---|
1093 | temp = first; |
---|
1094 | first = first->getNext(); |
---|
1095 | delete temp; |
---|
1096 | } |
---|
1097 | } |
---|
1098 | |
---|
1099 | // declaration with first as parameter in LTagNode due to sorting of LTagList |
---|
1100 | void RTagList::insert(RNode* r) { |
---|
1101 | first = first->insert(r); |
---|
1102 | //Print("LENGTH:%d\n",length); |
---|
1103 | length = length +1; |
---|
1104 | //Print("LENGTH:%d\n",length); |
---|
1105 | } |
---|
1106 | |
---|
1107 | RNode* RTagList::getFirst() { |
---|
1108 | return first->getRNode(); |
---|
1109 | } |
---|
1110 | |
---|
1111 | RNode* RTagList::get(int idx) { |
---|
1112 | return first->get(idx, length); |
---|
1113 | } |
---|
1114 | |
---|
1115 | void RTagList::setFirst(RNode* r) { |
---|
1116 | first->set(r); |
---|
1117 | } |
---|
1118 | |
---|
1119 | void RTagList::print() { |
---|
1120 | first->print(); |
---|
1121 | } |
---|
1122 | |
---|
1123 | int RTagList::getLength() { |
---|
1124 | return length; |
---|
1125 | } |
---|
1126 | #endif |
---|