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