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