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