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