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