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