[71f00c5] | 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" |
---|
[5d0556] | 18 | #include "f5data.h" |
---|
[f4e338f] | 19 | #include "f5lists.h" |
---|
[71f00c5] | 20 | |
---|
| 21 | /* |
---|
| 22 | ==================================== |
---|
| 23 | functions working on the class LNode |
---|
| 24 | ==================================== |
---|
| 25 | */ |
---|
| 26 | |
---|
[a0350e9] | 27 | // generating new list elements (labeled / classical polynomial / LNode view) |
---|
[9bb97e] | 28 | LNode::LNode() { |
---|
[87beab7] | 29 | data = NULL; |
---|
| 30 | next = NULL; |
---|
| 31 | gPrevRedCheck = NULL; |
---|
[9bb97e] | 32 | } |
---|
| 33 | LNode::LNode(LPoly* lp) { |
---|
[87beab7] | 34 | data = lp; |
---|
| 35 | next = NULL; |
---|
| 36 | gPrevRedCheck = NULL; |
---|
[71f00c5] | 37 | } |
---|
| 38 | |
---|
[66e7b5] | 39 | LNode::LNode(LPoly* lp, LNode* l) { |
---|
[87beab7] | 40 | Print("HIER LNODE\n"); |
---|
| 41 | data = lp; |
---|
| 42 | next = l; |
---|
| 43 | gPrevRedCheck = NULL; |
---|
[66e7b5] | 44 | } |
---|
[87beab7] | 45 | |
---|
[416ea2] | 46 | LNode::LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck) { |
---|
[61d32c] | 47 | LPoly* lp = new LPoly(t,i,p,r); |
---|
[87beab7] | 48 | data = lp; |
---|
| 49 | next = NULL; |
---|
| 50 | gPrevRedCheck = gPCheck; |
---|
[71f00c5] | 51 | } |
---|
| 52 | |
---|
[416ea2] | 53 | LNode::LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck, LNode* l) { |
---|
[87beab7] | 54 | LPoly* lp = new LPoly(t,i,p,r); |
---|
| 55 | data = lp; |
---|
| 56 | next = l; |
---|
| 57 | gPrevRedCheck = gPCheck; |
---|
[66e7b5] | 58 | } |
---|
| 59 | |
---|
| 60 | LNode::LNode(LNode* ln) { |
---|
[87beab7] | 61 | data = ln->getLPoly(); |
---|
| 62 | next = ln->getNext(); |
---|
| 63 | gPrevRedCheck = NULL; |
---|
[71f00c5] | 64 | } |
---|
| 65 | |
---|
| 66 | LNode::~LNode() { |
---|
[416ea2] | 67 | //delete next; |
---|
[87beab7] | 68 | delete gPrevRedCheck; |
---|
[71f00c5] | 69 | delete data; |
---|
| 70 | } |
---|
| 71 | |
---|
[a0350e9] | 72 | // insert new elements to the list always in front (labeled / classical polynomial view) |
---|
| 73 | LNode* LNode::insert(LPoly* lp) { |
---|
[87beab7] | 74 | Print("HIER\n"); |
---|
[66e7b5] | 75 | LNode* newElement = new LNode(lp, this); |
---|
[a0350e9] | 76 | return newElement; |
---|
[71f00c5] | 77 | } |
---|
| 78 | |
---|
[87beab7] | 79 | LNode* LNode::insert(poly t, int i, poly p, Rule* r) { |
---|
[416ea2] | 80 | LNode* newElement = new LNode(t, i, p, r, NULL, this); |
---|
[a0350e9] | 81 | return newElement; |
---|
[71f00c5] | 82 | } |
---|
[416ea2] | 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 | |
---|
[cce6ed3] | 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) |
---|
[87beab7] | 91 | LNode* LNode::insertByLabel(poly t, int i, poly p, Rule* r) { |
---|
[9bb97e] | 92 | if(0 == pLmCmp(t,this->getTerm()) || -1 == pLmCmp(t,this->getTerm())) { |
---|
[87beab7] | 93 | LNode* newElement = new LNode(t, i, p, r, this); |
---|
[cce6ed3] | 94 | return newElement; |
---|
| 95 | } |
---|
| 96 | else { |
---|
| 97 | LNode* temp = this; |
---|
[9bb97e] | 98 | while( NULL != temp->next->data ) { |
---|
| 99 | if( 0 == pLmCmp(t,temp->next->getTerm()) || -1 == pLmCmp(t,temp->next->getTerm())) { |
---|
[87beab7] | 100 | LNode* newElement = new LNode(t, i, p, r, temp->next); |
---|
[cce6ed3] | 101 | temp->next = newElement; |
---|
| 102 | return this; |
---|
| 103 | } |
---|
| 104 | else { |
---|
| 105 | temp = temp->next; |
---|
| 106 | } |
---|
| 107 | } |
---|
[87beab7] | 108 | LNode* newElement = new LNode(t, i, p, r, NULL); |
---|
[cce6ed3] | 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 | |
---|
[71f00c5] | 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 | |
---|
[cce6ed3] | 130 | // get the data from the LPoly saved in LNode |
---|
[66e7b5] | 131 | poly LNode::getPoly() { |
---|
[71f00c5] | 132 | return data->getPoly(); |
---|
| 133 | } |
---|
| 134 | |
---|
[66e7b5] | 135 | poly LNode::getTerm() { |
---|
[cce6ed3] | 136 | return data->getTerm(); |
---|
| 137 | } |
---|
| 138 | |
---|
[66e7b5] | 139 | int LNode::getIndex() { |
---|
[cce6ed3] | 140 | return data->getIndex(); |
---|
| 141 | } |
---|
| 142 | |
---|
[87beab7] | 143 | Rule* LNode::getRule() { |
---|
| 144 | return data->getRule(); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | LNode* LNode::getGPrevRedCheck() { |
---|
| 148 | return gPrevRedCheck; |
---|
| 149 | } |
---|
| 150 | |
---|
[9bb97e] | 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 | |
---|
[87beab7] | 164 | void LNode::setGPrevRedCheck(LNode* l) { |
---|
| 165 | gPrevRedCheck = l; |
---|
| 166 | } |
---|
| 167 | |
---|
[71f00c5] | 168 | // test if for any list element the polynomial part of the data is equal to *p |
---|
[a0350e9] | 169 | bool LNode::polyTest(poly* p) { |
---|
[71f00c5] | 170 | LNode* temp = new LNode(this); |
---|
| 171 | while(NULL != temp) { |
---|
[66e7b5] | 172 | if(pComparePolys(temp->getPoly(),*p)) { |
---|
[71f00c5] | 173 | return 1; |
---|
| 174 | } |
---|
| 175 | temp = temp->next; |
---|
| 176 | } |
---|
| 177 | return 0; |
---|
| 178 | } |
---|
| 179 | |
---|
[cce6ed3] | 180 | LNode* LNode::getNext(LNode* l) { |
---|
| 181 | return l->next; |
---|
| 182 | } |
---|
[71f00c5] | 183 | |
---|
| 184 | /* |
---|
| 185 | ==================================== |
---|
| 186 | functions working on the class LList |
---|
| 187 | ==================================== |
---|
| 188 | */ |
---|
| 189 | |
---|
[9bb97e] | 190 | LList::LList() { |
---|
| 191 | first = new LNode(); |
---|
[416ea2] | 192 | last = first; |
---|
[9bb97e] | 193 | length = 0; |
---|
| 194 | } |
---|
| 195 | |
---|
[71f00c5] | 196 | LList::LList(LPoly* lp) { |
---|
[9bb97e] | 197 | first = new LNode(lp); |
---|
[416ea2] | 198 | last = first; |
---|
[9bb97e] | 199 | length = 1; |
---|
[71f00c5] | 200 | } |
---|
| 201 | |
---|
[87beab7] | 202 | LList::LList(poly t,int i,poly p,Rule* r) { |
---|
| 203 | first = new LNode(t,i,p,r); |
---|
[416ea2] | 204 | last = first; |
---|
[9bb97e] | 205 | length = 1; |
---|
[71f00c5] | 206 | } |
---|
| 207 | |
---|
| 208 | LList::~LList() { |
---|
| 209 | delete first; |
---|
| 210 | } |
---|
| 211 | |
---|
[a0350e9] | 212 | // insertion in front of the list |
---|
| 213 | void LList::insert(LPoly* lp) { |
---|
| 214 | first = first->insert(lp); |
---|
[9bb97e] | 215 | length++; |
---|
[71f00c5] | 216 | } |
---|
| 217 | |
---|
[87beab7] | 218 | void LList::insert(poly t,int i, poly p, Rule* r) { |
---|
| 219 | first = first->insert(t,i,p,r); |
---|
| 220 | length++; |
---|
| 221 | } |
---|
| 222 | |
---|
[416ea2] | 223 | void LList::append(poly t, int i, poly p, Rule* r) { |
---|
| 224 | last = last->append(t,i,p,r); |
---|
| 225 | length++; |
---|
| 226 | } |
---|
| 227 | |
---|
[87beab7] | 228 | void LList::insertByLabel(poly t, int i, poly p, Rule* r) { |
---|
| 229 | first = first->insertByLabel(t,i,p,r); |
---|
[9bb97e] | 230 | length++; |
---|
[71f00c5] | 231 | } |
---|
| 232 | |
---|
[87beab7] | 233 | void LList::insertByLabel(LNode* l) { |
---|
| 234 | first = first->insertByLabel(l->getTerm(),l->getIndex(),l->getPoly(),l->getRule()); |
---|
[9bb97e] | 235 | length++; |
---|
[71f00c5] | 236 | } |
---|
| 237 | |
---|
[cce6ed3] | 238 | void LList::deleteByDeg() { |
---|
| 239 | first = first->deleteByDeg(); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | bool LList::polyTest(poly* p) { |
---|
| 243 | return first->polyTest(p); |
---|
[71f00c5] | 244 | } |
---|
| 245 | |
---|
| 246 | LNode* LList::getFirst() { |
---|
| 247 | return first; |
---|
| 248 | } |
---|
| 249 | |
---|
[416ea2] | 250 | LNode* LList::getLast() { |
---|
| 251 | return last; |
---|
| 252 | } |
---|
| 253 | |
---|
[cce6ed3] | 254 | LNode* LList::getNext(LNode* l) { |
---|
| 255 | return l->getNext(); |
---|
| 256 | } |
---|
[a0350e9] | 257 | |
---|
[9bb97e] | 258 | int LList::getLength() { |
---|
| 259 | return length; |
---|
| 260 | } |
---|
| 261 | |
---|
[fcb8022] | 262 | void LList::setFirst(LNode* l) { |
---|
| 263 | LNode* temp = first; |
---|
| 264 | first = l; |
---|
| 265 | delete(temp); |
---|
[416ea2] | 266 | length--; |
---|
[fcb8022] | 267 | } |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | |
---|
[a0350e9] | 271 | /* |
---|
| 272 | ======================================= |
---|
[66e7b5] | 273 | functions working on the class LTagNode |
---|
[a0350e9] | 274 | ======================================= |
---|
| 275 | */ |
---|
[87beab7] | 276 | LTagNode::LTagNode() { |
---|
| 277 | data = NULL; |
---|
| 278 | next = NULL; |
---|
| 279 | } |
---|
[a0350e9] | 280 | |
---|
[66e7b5] | 281 | LTagNode::LTagNode(LNode* l) { |
---|
[a0350e9] | 282 | data = l; |
---|
| 283 | next = NULL; |
---|
| 284 | } |
---|
| 285 | |
---|
[66e7b5] | 286 | LTagNode::LTagNode(LNode* l, LTagNode* n) { |
---|
| 287 | data = l; |
---|
| 288 | next = n; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | LTagNode::~LTagNode() { |
---|
[a0350e9] | 292 | delete next; |
---|
| 293 | delete data; |
---|
| 294 | } |
---|
| 295 | |
---|
[66e7b5] | 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; |
---|
[a0350e9] | 300 | } |
---|
| 301 | |
---|
[66e7b5] | 302 | LNode* LTagNode::getLNode() { |
---|
[a0350e9] | 303 | return this->data; |
---|
| 304 | } |
---|
| 305 | |
---|
[66e7b5] | 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; |
---|
[a0350e9] | 320 | } |
---|
| 321 | } |
---|
| 322 | |
---|
[66e7b5] | 323 | |
---|
[a0350e9] | 324 | /* |
---|
| 325 | ======================================= |
---|
[66e7b5] | 326 | functions working on the class LTagList |
---|
[a0350e9] | 327 | ======================================= |
---|
| 328 | */ |
---|
[87beab7] | 329 | LTagList::LTagList() { |
---|
| 330 | LTagNode* first = new LTagNode(); |
---|
| 331 | length = 0; |
---|
| 332 | } |
---|
[a0350e9] | 333 | |
---|
[66e7b5] | 334 | LTagList::LTagList(LNode* l) { |
---|
| 335 | LTagNode* first = new LTagNode(l); |
---|
| 336 | length = 1; |
---|
[a0350e9] | 337 | } |
---|
| 338 | |
---|
[66e7b5] | 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++; |
---|
[a0350e9] | 343 | } |
---|
| 344 | |
---|
[66e7b5] | 345 | LNode* LTagList::get(int idx) { |
---|
| 346 | return first->get(idx, length); |
---|
[a0350e9] | 347 | } |
---|
| 348 | |
---|
[87beab7] | 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 | |
---|
[a0350e9] | 378 | /* |
---|
| 379 | ==================================== |
---|
| 380 | functions working on the class CNode |
---|
| 381 | ==================================== |
---|
| 382 | */ |
---|
| 383 | |
---|
[66e7b5] | 384 | CNode::CNode() { |
---|
| 385 | data = NULL; |
---|
| 386 | next = NULL; |
---|
| 387 | } |
---|
| 388 | |
---|
[a0350e9] | 389 | CNode::CNode(CPair* c) { |
---|
| 390 | data = c; |
---|
| 391 | next = NULL; |
---|
| 392 | } |
---|
| 393 | |
---|
[66e7b5] | 394 | CNode::CNode(CPair* c, CNode* n) { |
---|
| 395 | data = c; |
---|
| 396 | next = n; |
---|
| 397 | } |
---|
| 398 | |
---|
[a0350e9] | 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 |
---|
[66e7b5] | 408 | CNode* CNode::insert(CPair* c, CNode* last) { |
---|
| 409 | if(NULL == this->data) { |
---|
| 410 | CNode* newElement = new CNode(c, this); |
---|
[a0350e9] | 411 | return newElement; |
---|
| 412 | } |
---|
[66e7b5] | 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); |
---|
[a0350e9] | 417 | return newElement; |
---|
| 418 | } |
---|
[66e7b5] | 419 | if( c->getDeg() == this->data->getDeg() ) { // same degree than the first list element |
---|
[fcb8022] | 420 | if(1 != pLmCmp(u1,ppMult_qq(this->data->getT1(), this->data->getLp1Term()))) { |
---|
[66e7b5] | 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 | } |
---|
[a0350e9] | 440 | } |
---|
| 441 | else { |
---|
[66e7b5] | 442 | CNode* newElement = new CNode(c, temp->next); |
---|
[a0350e9] | 443 | temp->next = newElement; |
---|
| 444 | return this; |
---|
[66e7b5] | 445 | } |
---|
[a0350e9] | 446 | } |
---|
[66e7b5] | 447 | CNode* newElement = new CNode(c, last); |
---|
[a0350e9] | 448 | temp->next = newElement; |
---|
| 449 | return this; |
---|
| 450 | } |
---|
[66e7b5] | 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); |
---|
[a0350e9] | 457 | temp->next = newElement; |
---|
| 458 | return this; |
---|
| 459 | } |
---|
[66e7b5] | 460 | if( c->getDeg() == temp->next->data->getDeg() ) { |
---|
[fcb8022] | 461 | if(1 != pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),temp->next->data->getLp1Term()))) { |
---|
[66e7b5] | 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 | } |
---|
[a0350e9] | 479 | } |
---|
| 480 | else { |
---|
[66e7b5] | 481 | CNode* newElement = new CNode(c, temp->next); |
---|
[a0350e9] | 482 | temp->next = newElement; |
---|
| 483 | return this; |
---|
[66e7b5] | 484 | } |
---|
[a0350e9] | 485 | } |
---|
[66e7b5] | 486 | CNode* newElement = new CNode(c, last); |
---|
| 487 | temp->next = newElement; |
---|
| 488 | return this; |
---|
[a0350e9] | 489 | } |
---|
[66e7b5] | 490 | } |
---|
| 491 | if( c->getDeg() > temp->next->data->getDeg() ) { |
---|
| 492 | temp = temp->next; |
---|
[a0350e9] | 493 | } |
---|
| 494 | } |
---|
[66e7b5] | 495 | CNode* newElement = new CNode(c, last); |
---|
| 496 | temp->next = newElement; |
---|
| 497 | return this; |
---|
[a0350e9] | 498 | } |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | |
---|
[cce6ed3] | 502 | // get the first elements from CList which by the above sorting have minimal degree |
---|
| 503 | CNode* CNode::getMinDeg() { |
---|
| 504 | CNode* temp = this; |
---|
[66e7b5] | 505 | while( NULL != temp->data ) { |
---|
[9bb97e] | 506 | while(NULL != temp->next->data && temp->next->data->getDeg() == this->data->getDeg()) { |
---|
[cce6ed3] | 507 | temp = temp->next; |
---|
| 508 | } |
---|
| 509 | CNode* returnCNode = temp->next; |
---|
[9bb97e] | 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(); |
---|
[cce6ed3] | 513 | return returnCNode; |
---|
| 514 | } |
---|
| 515 | return NULL; |
---|
| 516 | } |
---|
| 517 | |
---|
[9bb97e] | 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 | |
---|
[66e7b5] | 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 | |
---|
[9bb97e] | 562 | poly* CNode::getAdT1() { |
---|
| 563 | return this->data->getAdT1(); |
---|
| 564 | } |
---|
| 565 | |
---|
[66e7b5] | 566 | poly CNode::getT2() { |
---|
| 567 | return this->data->getT2(); |
---|
| 568 | } |
---|
| 569 | |
---|
[9bb97e] | 570 | poly* CNode::getAdT2() { |
---|
| 571 | return this->data->getAdT2(); |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | Rule* CNode::getLastRuleTested() { |
---|
| 575 | return this->data->getLastRuleTested(); |
---|
| 576 | } |
---|
| 577 | |
---|
[66e7b5] | 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 | } |
---|
[cce6ed3] | 595 | |
---|
[a0350e9] | 596 | /* |
---|
| 597 | ==================================== |
---|
| 598 | functions working on the class CList |
---|
| 599 | ==================================== |
---|
| 600 | */ |
---|
[66e7b5] | 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 | |
---|
[a0350e9] | 607 | CList::CList(CPair* c) { |
---|
[66e7b5] | 608 | first = new CNode(c); |
---|
| 609 | last = first; |
---|
[a0350e9] | 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) { |
---|
[66e7b5] | 619 | first = first->insert(c, last); |
---|
[71f00c5] | 620 | } |
---|
[cce6ed3] | 621 | |
---|
[9bb97e] | 622 | CNode* CList::getFirst() { |
---|
| 623 | return first; |
---|
| 624 | } |
---|
| 625 | |
---|
[cce6ed3] | 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 | |
---|
[66e7b5] | 634 | void CList::print() { |
---|
| 635 | first->print(); |
---|
| 636 | } |
---|
[cce6ed3] | 637 | |
---|
| 638 | /* |
---|
| 639 | ==================================== |
---|
| 640 | functions working on the class RNode |
---|
| 641 | ==================================== |
---|
| 642 | */ |
---|
[66e7b5] | 643 | RNode::RNode() { |
---|
| 644 | data = NULL; |
---|
| 645 | next = NULL; |
---|
| 646 | } |
---|
| 647 | |
---|
[cce6ed3] | 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 | |
---|
[87beab7] | 664 | RNode* RNode::insert(int i, poly t) { |
---|
| 665 | Rule* r = new Rule(i,t); |
---|
[9bb97e] | 666 | RNode* newElement = new RNode(r); |
---|
| 667 | newElement->next = this; |
---|
| 668 | return newElement; |
---|
| 669 | } |
---|
| 670 | |
---|
[66e7b5] | 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 | |
---|
[cce6ed3] | 687 | /* |
---|
| 688 | ==================================== |
---|
| 689 | functions working on the class RList |
---|
| 690 | ==================================== |
---|
| 691 | */ |
---|
[66e7b5] | 692 | RList::RList() { |
---|
| 693 | first = new RNode(); |
---|
| 694 | } |
---|
| 695 | |
---|
[cce6ed3] | 696 | RList::RList(Rule* r) { |
---|
| 697 | first = new RNode(r); |
---|
| 698 | } |
---|
| 699 | |
---|
[87beab7] | 700 | void RList::insert(int i, poly t) { |
---|
| 701 | first = first->insert(i,t); |
---|
[9bb97e] | 702 | } |
---|
| 703 | |
---|
[cce6ed3] | 704 | void RList::insert(Rule* r) { |
---|
| 705 | first = first->insert(r); |
---|
| 706 | } |
---|
[66e7b5] | 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 | |
---|
[a41f3aa] | 722 | RTagNode::RTagNode() { |
---|
| 723 | data = NULL; |
---|
| 724 | next = NULL; |
---|
| 725 | } |
---|
| 726 | |
---|
[66e7b5] | 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 | |
---|
[fcb8022] | 742 | // declaration with first as parameter due to sorting of RTagList |
---|
[66e7b5] | 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) { |
---|
[a41f3aa] | 758 | if(idx==1 || idx==0) { |
---|
[87beab7] | 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 |
---|
[66e7b5] | 762 | return NULL; |
---|
| 763 | } |
---|
| 764 | else { |
---|
| 765 | int j; |
---|
| 766 | RTagNode* temp = this; |
---|
[87beab7] | 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++) { |
---|
[66e7b5] | 770 | temp = temp->next; |
---|
| 771 | } |
---|
| 772 | return temp->data; |
---|
| 773 | } |
---|
| 774 | } |
---|
| 775 | |
---|
[fcb8022] | 776 | void RTagNode::set(RNode* r) { |
---|
| 777 | this->data = r; |
---|
| 778 | } |
---|
[66e7b5] | 779 | |
---|
[87beab7] | 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 | } |
---|
[66e7b5] | 793 | /* |
---|
| 794 | ======================================= |
---|
| 795 | functions working on the class LTagList |
---|
| 796 | ======================================= |
---|
| 797 | */ |
---|
| 798 | |
---|
[a41f3aa] | 799 | RTagList::RTagList() { |
---|
| 800 | RTagNode* first = new RTagNode(); |
---|
| 801 | length = 0; |
---|
| 802 | } |
---|
| 803 | |
---|
[66e7b5] | 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); |
---|
[87beab7] | 812 | Print("LENGTH:%d\n",length); |
---|
| 813 | length = length +1; |
---|
| 814 | Print("LENGTH:%d\n",length); |
---|
[66e7b5] | 815 | } |
---|
| 816 | |
---|
[8978fd] | 817 | RNode* RTagList::getFirst() { |
---|
| 818 | return first->getRNode(); |
---|
| 819 | } |
---|
| 820 | |
---|
[66e7b5] | 821 | RNode* RTagList::get(int idx) { |
---|
| 822 | return first->get(idx, length); |
---|
| 823 | } |
---|
[fcb8022] | 824 | |
---|
| 825 | void RTagList::setFirst(RNode* r) { |
---|
| 826 | first->set(r); |
---|
| 827 | } |
---|
[87beab7] | 828 | |
---|
| 829 | void RTagList::print() { |
---|
| 830 | first->print(); |
---|
| 831 | } |
---|
| 832 | |
---|
| 833 | int RTagList::getLength() { |
---|
| 834 | return length; |
---|
| 835 | } |
---|
[71f00c5] | 836 | #endif |
---|