[599326] | 1 | #include <kernel/mod2.h> |
---|
[71f00c5] | 2 | |
---|
[ae5177] | 3 | #ifdef HAVE_F5 |
---|
[599326] | 4 | #include <kernel/kutil.h> |
---|
| 5 | #include <kernel/structs.h> |
---|
[76cfef] | 6 | #include <omalloc/omalloc.h> |
---|
[737a68] | 7 | #include <kernel/polys.h> |
---|
[210e07] | 8 | #include <polys/monomials/p_polys.h> |
---|
[599326] | 9 | #include <kernel/ideals.h> |
---|
| 10 | #include <kernel/febase.h> |
---|
| 11 | #include <kernel/kstd1.h> |
---|
| 12 | #include <kernel/khstd.h> |
---|
[210e07] | 13 | #include <polys/kbuckets.h> |
---|
[76cfef] | 14 | #include <polys/weight.h> |
---|
[210e07] | 15 | #include <misc/intvec.h> |
---|
[737a68] | 16 | #include <kernel/polys.h> |
---|
[599326] | 17 | #include <kernel/f5gb.h> |
---|
| 18 | #include <kernel/f5data.h> |
---|
| 19 | #include <kernel/f5lists.h> |
---|
[71f00c5] | 20 | |
---|
[ab76b4] | 21 | /** |
---|
| 22 | * functions working on the class PNode |
---|
| 23 | */ |
---|
| 24 | PNode::PNode(poly p, PNode* n) { |
---|
| 25 | data = p; |
---|
| 26 | next = n; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | poly PNode::getPoly() { |
---|
| 30 | return this->data; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | PNode* PNode::getNext() { |
---|
| 34 | return this->next; |
---|
| 35 | } |
---|
| 36 | PNode* PNode::insert(poly p) { |
---|
| 37 | poly q = pOne(); |
---|
| 38 | q = pCopy(p); |
---|
| 39 | PNode* temp = this; |
---|
| 40 | if(NULL == temp) { |
---|
| 41 | PNode* pn = new PNode(q,temp); |
---|
| 42 | return pn; |
---|
| 43 | } |
---|
| 44 | if(1 == pLmCmp(q,temp->getPoly())) { |
---|
| 45 | PNode* pn = new PNode(q,temp); |
---|
| 46 | return pn; |
---|
| 47 | } |
---|
| 48 | if(0 == pLmCmp(q,temp->getPoly())) { |
---|
| 49 | return this; |
---|
| 50 | } |
---|
| 51 | if(-1 == pLmCmp(q,temp->getPoly())) { |
---|
| 52 | while(NULL != temp->getNext() && -1 == pLmCmp(q,temp->getNext()->getPoly())) { |
---|
| 53 | temp = temp->getNext(); |
---|
| 54 | } |
---|
| 55 | if(NULL == temp->getNext() || 1 == pLmCmp(q,temp->getNext()->getPoly())) { |
---|
| 56 | PNode* pn = new PNode(q,temp->getNext()); |
---|
| 57 | temp->next = pn; |
---|
| 58 | return this; |
---|
| 59 | } |
---|
| 60 | if(0 == pLmCmp(q,temp->getNext()->getPoly())) { |
---|
| 61 | return this; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | /* |
---|
| 66 | PNode* PNode::insert(poly p) { |
---|
| 67 | PNode* pn = new PNode(p,this); |
---|
| 68 | return pn; |
---|
| 69 | } |
---|
| 70 | */ |
---|
| 71 | /** |
---|
| 72 | * functions working on the class PList |
---|
| 73 | */ |
---|
| 74 | PList::PList() { |
---|
| 75 | first = NULL; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | void PList::insert(poly p) { |
---|
| 80 | first = first->insert(p); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | /* |
---|
| 85 | PNode* PList::insert(poly p) { |
---|
| 86 | PNode* temp = first; |
---|
| 87 | PNode* pn = new PNode(p,temp); |
---|
| 88 | first = pn; |
---|
| 89 | return first; |
---|
| 90 | } |
---|
| 91 | */ |
---|
| 92 | bool PList::check(poly p) { |
---|
| 93 | PNode* temp = first; |
---|
| 94 | //Print("\nCHECK: \n"); |
---|
| 95 | //pWrite(p); |
---|
| 96 | //Print("-----\n"); |
---|
| 97 | while(NULL != temp) { |
---|
| 98 | //pWrite(temp->getPoly()); |
---|
| 99 | //pWrite(p); |
---|
| 100 | //Print("COMAPRE: %d\n",pLmEqual(p,temp->getPoly())); |
---|
| 101 | if(1 == pLmEqual(p,temp->getPoly())) { |
---|
| 102 | //Print("YES!\n"); |
---|
| 103 | //pWrite(pHead(temp->getPoly())); |
---|
| 104 | //Print("YES!\n"); |
---|
| 105 | return 1; |
---|
| 106 | } |
---|
| 107 | temp = temp->getNext(); |
---|
| 108 | } |
---|
| 109 | //Print("NOTHING!\n"); |
---|
| 110 | return 0; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void PList::print() { |
---|
| 114 | Print("-----LIST-----\n"); |
---|
| 115 | PNode* temp = first; |
---|
| 116 | while(NULL != temp) { |
---|
| 117 | pWrite(temp->getPoly()); |
---|
| 118 | temp = temp->getNext(); |
---|
| 119 | } |
---|
| 120 | } |
---|
[71f00c5] | 121 | /* |
---|
| 122 | ==================================== |
---|
| 123 | functions working on the class LNode |
---|
| 124 | ==================================== |
---|
| 125 | */ |
---|
| 126 | |
---|
[a0350e9] | 127 | // generating new list elements (labeled / classical polynomial / LNode view) |
---|
[9bb97e] | 128 | LNode::LNode() { |
---|
[87beab7] | 129 | data = NULL; |
---|
| 130 | next = NULL; |
---|
[9bb97e] | 131 | } |
---|
[a05c71] | 132 | LNode::LNode(LPolyOld* lp) { |
---|
[87beab7] | 133 | data = lp; |
---|
| 134 | next = NULL; |
---|
[71f00c5] | 135 | } |
---|
| 136 | |
---|
[a05c71] | 137 | LNode::LNode(LPolyOld* lp, LNode* l) { |
---|
[598870] | 138 | //Print("HIER LNODE\n"); |
---|
[87beab7] | 139 | data = lp; |
---|
| 140 | next = l; |
---|
[66e7b5] | 141 | } |
---|
[87beab7] | 142 | |
---|
[a05c71] | 143 | LNode::LNode(poly t, int i, poly p, RuleOld* r) { |
---|
| 144 | LPolyOld* lp = new LPolyOld(t,i,p,r); |
---|
[87beab7] | 145 | data = lp; |
---|
| 146 | next = NULL; |
---|
[71f00c5] | 147 | } |
---|
| 148 | |
---|
[a05c71] | 149 | LNode::LNode(poly t, int i, poly p, RuleOld* r, LNode* l) { |
---|
| 150 | LPolyOld* lp = new LPolyOld(t,i,p,r); |
---|
[87beab7] | 151 | data = lp; |
---|
| 152 | next = l; |
---|
[66e7b5] | 153 | } |
---|
| 154 | |
---|
[9cb4078] | 155 | LNode::LNode(LNode* ln) { |
---|
[a05c71] | 156 | data = ln->getLPolyOld(); |
---|
[87beab7] | 157 | next = ln->getNext(); |
---|
[71f00c5] | 158 | } |
---|
| 159 | |
---|
| 160 | LNode::~LNode() { |
---|
[416ea2] | 161 | //delete next; |
---|
[55a828] | 162 | //Print("DELETE LNODE\n"); |
---|
[71f00c5] | 163 | delete data; |
---|
| 164 | } |
---|
[338842d] | 165 | |
---|
| 166 | void LNode::deleteAll() { |
---|
| 167 | while(NULL != next) { |
---|
[55a828] | 168 | //Print("%p\n",next); |
---|
| 169 | //pWrite(next->data->getPoly()); |
---|
[338842d] | 170 | next->deleteAll(); |
---|
| 171 | } |
---|
| 172 | delete data; |
---|
| 173 | } |
---|
| 174 | |
---|
[d51339] | 175 | // insert new elements to the list always at the end (labeled / classical polynomial view) |
---|
| 176 | // needed for list gPrev |
---|
[a05c71] | 177 | inline LNode* LNode::insert(LPolyOld* lp) { |
---|
[598870] | 178 | //Print("LAST GPREV: "); |
---|
| 179 | //pWrite(this->getPoly()); |
---|
[e3b5ed] | 180 | if(NULL == this) { |
---|
| 181 | LNode* newElement = new LNode(lp,this); |
---|
| 182 | return newElement; |
---|
| 183 | } |
---|
| 184 | else { |
---|
| 185 | LNode* newElement = new LNode(lp, NULL); |
---|
| 186 | this->next = newElement; |
---|
| 187 | return newElement; |
---|
| 188 | } |
---|
[71f00c5] | 189 | } |
---|
| 190 | |
---|
[a05c71] | 191 | inline LNode* LNode::insert(poly t, int i, poly p, RuleOld* r) { |
---|
[e3b5ed] | 192 | if(NULL == this) { |
---|
| 193 | LNode* newElement = new LNode(t,i,p,r,this); |
---|
| 194 | return newElement; |
---|
| 195 | } |
---|
| 196 | else { |
---|
| 197 | LNode* newElement = new LNode(t, i, p, r, NULL); |
---|
| 198 | this->next = newElement; |
---|
| 199 | return newElement; |
---|
| 200 | } |
---|
[71f00c5] | 201 | } |
---|
[416ea2] | 202 | |
---|
[d51339] | 203 | // insert new elements to the list always in front (labeled / classical polynomial view) |
---|
| 204 | // needed for sPolyList |
---|
[a05c71] | 205 | inline LNode* LNode::insertSP(LPolyOld* lp) { |
---|
[d51339] | 206 | LNode* newElement = new LNode(lp, this); |
---|
[c9193a] | 207 | //Print("INSERTED IN SPOLYLIST: "); |
---|
| 208 | //pWrite(lp->getTerm()); |
---|
[d51339] | 209 | return newElement; |
---|
| 210 | } |
---|
| 211 | |
---|
[a05c71] | 212 | inline LNode* LNode::insertSP(poly t, int i, poly p, RuleOld* r) { |
---|
[338842d] | 213 | LNode* newElement = new LNode(t, i, p, r, this); |
---|
[c9193a] | 214 | //Print("INSERTED IN SPOLYLIST: "); |
---|
| 215 | //pWrite(t); |
---|
[8066e80] | 216 | return newElement; |
---|
[416ea2] | 217 | } |
---|
[cce6ed3] | 218 | // insert new elemets to the list w.r.t. increasing labels |
---|
| 219 | // only used for the S-polys to be reduced (TopReduction building new S-polys with higher label) |
---|
[a05c71] | 220 | inline LNode* LNode::insertByLabel(poly t, int i, poly p, RuleOld* r) { |
---|
[c9193a] | 221 | //Print("ADDING SOLYS TO THE LIST\n"); |
---|
| 222 | //Print("new element: "); |
---|
| 223 | //pWrite(t); |
---|
[c4158f] | 224 | if(NULL == this) { // || NULL == data) { |
---|
[338842d] | 225 | LNode* newElement = new LNode(t, i, p, r, this); |
---|
[cce6ed3] | 226 | return newElement; |
---|
| 227 | } |
---|
| 228 | else { |
---|
[c9193a] | 229 | //Print("tested element1: "); |
---|
| 230 | //pWrite(this->getTerm()); |
---|
[61944d0] | 231 | if(-1 == pLmCmp(t,this->getTerm())) { |
---|
[c9193a] | 232 | //Print("HIERDRIN\n"); |
---|
[338842d] | 233 | LNode* newElement = new LNode(t, i, p, r, this); |
---|
[c9193a] | 234 | //Print("%p\n",this); |
---|
| 235 | //Print("%p\n",newElement->next); |
---|
[70c15e] | 236 | return newElement; |
---|
| 237 | } |
---|
| 238 | else { |
---|
| 239 | LNode* temp = this; |
---|
| 240 | while(NULL != temp->next && NULL != temp->next->data) { |
---|
[c9193a] | 241 | //Print("tested element: "); |
---|
| 242 | //pWrite(temp->getTerm()); |
---|
[8066e80] | 243 | if(-1 == pLmCmp(t,temp->next->getTerm())) { |
---|
[338842d] | 244 | LNode* newElement = new LNode(t, i, p, r, temp->next); |
---|
[70c15e] | 245 | temp->next = newElement; |
---|
| 246 | return this; |
---|
| 247 | } |
---|
| 248 | else { |
---|
| 249 | temp = temp->next; |
---|
[598870] | 250 | //Print("%p\n",temp); |
---|
| 251 | //Print("%p\n",temp->data); |
---|
[70c15e] | 252 | |
---|
[598870] | 253 | //Print("%p\n",temp->next); |
---|
[70c15e] | 254 | } |
---|
[cce6ed3] | 255 | } |
---|
[598870] | 256 | //Print("HIER\n"); |
---|
[338842d] | 257 | LNode* newElement = new LNode(t, i, p, r, temp->next); |
---|
[70c15e] | 258 | temp->next = newElement; |
---|
| 259 | return this; |
---|
[cce6ed3] | 260 | } |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | |
---|
[f16a76d] | 264 | inline LNode* LNode::insertFirst(LNode* l) { |
---|
| 265 | l->next = this; |
---|
| 266 | return l; |
---|
| 267 | } |
---|
| 268 | |
---|
[e90881] | 269 | inline LNode* LNode::insertByLabel(LNode* l) { |
---|
[f16a76d] | 270 | //Print("ADDING SOLYS TO THE LIST\n"); |
---|
[e90881] | 271 | //Print("new element: "); |
---|
| 272 | //pWrite(t); |
---|
| 273 | if(NULL == this) { // || NULL == data) { |
---|
| 274 | l->next = this; |
---|
| 275 | return l; |
---|
| 276 | } |
---|
| 277 | else { |
---|
| 278 | //Print("tested element1: "); |
---|
| 279 | //pWrite(this->getTerm()); |
---|
| 280 | if(-1 == pLmCmp(l->getTerm(),this->getTerm())) { |
---|
| 281 | //Print("HIERDRIN\n"); |
---|
| 282 | l->next = this; |
---|
| 283 | //Print("%p\n",this); |
---|
| 284 | //Print("%p\n",newElement->next); |
---|
| 285 | return l; |
---|
| 286 | } |
---|
| 287 | else { |
---|
| 288 | LNode* temp = this; |
---|
| 289 | while(NULL != temp->next && NULL != temp->next->data) { |
---|
| 290 | //Print("tested element: "); |
---|
| 291 | //pWrite(temp->getTerm()); |
---|
| 292 | if(-1 == pLmCmp(l->getTerm(),temp->next->getTerm())) { |
---|
| 293 | l->next = temp->next; |
---|
| 294 | temp->next = l; |
---|
| 295 | return this; |
---|
| 296 | } |
---|
| 297 | else { |
---|
| 298 | temp = temp->next; |
---|
| 299 | //Print("%p\n",temp); |
---|
| 300 | //Print("%p\n",temp->data); |
---|
| 301 | |
---|
| 302 | //Print("%p\n",temp->next); |
---|
| 303 | } |
---|
| 304 | } |
---|
| 305 | //Print("HIER\n"); |
---|
| 306 | l->next = temp->next; |
---|
| 307 | temp->next = l; |
---|
| 308 | return this; |
---|
| 309 | } |
---|
| 310 | } |
---|
| 311 | } |
---|
| 312 | |
---|
[cce6ed3] | 313 | // deletes the first elements of the list with the same degree |
---|
[0179d5] | 314 | // only used for the S-polys, which are already sorted by increasing degree by CListOld |
---|
[cce6ed3] | 315 | LNode* LNode::deleteByDeg() { |
---|
| 316 | return this; |
---|
| 317 | } |
---|
| 318 | |
---|
[71f00c5] | 319 | // get next from current LNode |
---|
| 320 | LNode* LNode::getNext() { |
---|
| 321 | return next; |
---|
| 322 | } |
---|
[d51339] | 323 | |
---|
[a05c71] | 324 | // get the LPolyOld* out of LNode* |
---|
| 325 | LPolyOld* LNode::getLPolyOld() { |
---|
[71f00c5] | 326 | return data; |
---|
| 327 | } |
---|
| 328 | |
---|
[a05c71] | 329 | // get the data from the LPolyOld saved in LNode |
---|
[66e7b5] | 330 | poly LNode::getPoly() { |
---|
[71f00c5] | 331 | return data->getPoly(); |
---|
| 332 | } |
---|
| 333 | |
---|
[66e7b5] | 334 | poly LNode::getTerm() { |
---|
[cce6ed3] | 335 | return data->getTerm(); |
---|
| 336 | } |
---|
| 337 | |
---|
[66e7b5] | 338 | int LNode::getIndex() { |
---|
[cce6ed3] | 339 | return data->getIndex(); |
---|
| 340 | } |
---|
| 341 | |
---|
[a05c71] | 342 | RuleOld* LNode::getRuleOld() { |
---|
| 343 | return data->getRuleOld(); |
---|
[87beab7] | 344 | } |
---|
| 345 | |
---|
[a05c71] | 346 | void LNode::setRuleOld(RuleOld* r) { |
---|
| 347 | return data->setRuleOld(r); |
---|
[c3efd3b] | 348 | } |
---|
| 349 | |
---|
[e90881] | 350 | bool LNode::getDel() { |
---|
| 351 | return data->getDel(); |
---|
| 352 | } |
---|
| 353 | |
---|
[a05c71] | 354 | // set the data from the LPolyOld saved in LNode |
---|
[9bb97e] | 355 | void LNode::setPoly(poly p) { |
---|
| 356 | data->setPoly(p); |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | void LNode::setTerm(poly t) { |
---|
| 360 | data->setTerm(t); |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | void LNode::setIndex(int i) { |
---|
| 364 | data->setIndex(i); |
---|
| 365 | } |
---|
| 366 | |
---|
[61944d0] | 367 | void LNode::setNext(LNode* l) { |
---|
| 368 | next = l; |
---|
| 369 | } |
---|
| 370 | |
---|
[e90881] | 371 | void LNode::setDel(bool d) { |
---|
| 372 | data->setDel(d); |
---|
| 373 | } |
---|
| 374 | |
---|
[71f00c5] | 375 | // test if for any list element the polynomial part of the data is equal to *p |
---|
[a0350e9] | 376 | bool LNode::polyTest(poly* p) { |
---|
[71f00c5] | 377 | LNode* temp = new LNode(this); |
---|
| 378 | while(NULL != temp) { |
---|
[66e7b5] | 379 | if(pComparePolys(temp->getPoly(),*p)) { |
---|
[71f00c5] | 380 | return 1; |
---|
| 381 | } |
---|
| 382 | temp = temp->next; |
---|
| 383 | } |
---|
| 384 | return 0; |
---|
| 385 | } |
---|
| 386 | |
---|
[cce6ed3] | 387 | LNode* LNode::getNext(LNode* l) { |
---|
| 388 | return l->next; |
---|
| 389 | } |
---|
[71f00c5] | 390 | |
---|
[d51339] | 391 | // for debugging |
---|
| 392 | void LNode::print() { |
---|
| 393 | LNode* temp = this; |
---|
| 394 | Print("___________________List of S-polynomials______________________:\n"); |
---|
[70c15e] | 395 | while(NULL != temp && NULL != temp->data) { |
---|
[d51339] | 396 | Print("Index: %d\n",temp->getIndex()); |
---|
| 397 | Print("Term: "); |
---|
[61944d0] | 398 | pWrite(temp->getTerm()); |
---|
[d51339] | 399 | Print("Poly: "); |
---|
[61944d0] | 400 | pWrite(temp->getPoly()); |
---|
[d51339] | 401 | temp = temp->next; |
---|
| 402 | } |
---|
[8066e80] | 403 | Print("_______________________________________________________________\n"); |
---|
[d51339] | 404 | } |
---|
| 405 | |
---|
[e90881] | 406 | int LNode::count(LNode* l) { |
---|
| 407 | int nonDel = 0; |
---|
| 408 | LNode* temp = l; |
---|
| 409 | while(NULL != temp) { |
---|
| 410 | if(!temp->getDel()) { |
---|
| 411 | nonDel++; |
---|
| 412 | temp = temp->next; |
---|
| 413 | } |
---|
| 414 | else { |
---|
| 415 | temp = temp->next; |
---|
| 416 | } |
---|
| 417 | } |
---|
| 418 | return nonDel; |
---|
| 419 | } |
---|
[d51339] | 420 | |
---|
[71f00c5] | 421 | /* |
---|
| 422 | ==================================== |
---|
| 423 | functions working on the class LList |
---|
| 424 | ==================================== |
---|
| 425 | */ |
---|
| 426 | |
---|
[9bb97e] | 427 | LList::LList() { |
---|
[c4158f] | 428 | first = last = NULL;; |
---|
[9bb97e] | 429 | length = 0; |
---|
| 430 | } |
---|
| 431 | |
---|
[a05c71] | 432 | LList::LList(LPolyOld* lp) { |
---|
[9bb97e] | 433 | first = new LNode(lp); |
---|
[416ea2] | 434 | last = first; |
---|
[9bb97e] | 435 | length = 1; |
---|
[71f00c5] | 436 | } |
---|
| 437 | |
---|
[a05c71] | 438 | LList::LList(poly t,int i,poly p,RuleOld* r) { |
---|
[87beab7] | 439 | first = new LNode(t,i,p,r); |
---|
[416ea2] | 440 | last = first; |
---|
[9bb97e] | 441 | length = 1; |
---|
[71f00c5] | 442 | } |
---|
| 443 | |
---|
| 444 | LList::~LList() { |
---|
[338842d] | 445 | LNode* temp; |
---|
| 446 | while(first) { |
---|
| 447 | temp = first; |
---|
| 448 | first = first->getNext(); |
---|
| 449 | delete temp; |
---|
[55a828] | 450 | //Print("%p\n",first); |
---|
[338842d] | 451 | } |
---|
[71f00c5] | 452 | } |
---|
| 453 | |
---|
[d51339] | 454 | // insertion at the end of the list, needed for gPrev |
---|
[a05c71] | 455 | void LList::insert(LPolyOld* lp) { |
---|
[d51339] | 456 | last = last->insert(lp); |
---|
[e3b5ed] | 457 | if(NULL == first) { |
---|
| 458 | first = last; |
---|
| 459 | } |
---|
[598870] | 460 | //Print("NEW LAST GPREV: "); |
---|
| 461 | //pWrite(last->getPoly()); |
---|
[e3b5ed] | 462 | //Print("%p\n",first); |
---|
| 463 | //pWrite(first->getPoly()); |
---|
[9bb97e] | 464 | length++; |
---|
[598870] | 465 | //Print("LENGTH %d\n",length); |
---|
[71f00c5] | 466 | } |
---|
| 467 | |
---|
[a05c71] | 468 | void LList::insert(poly t,int i, poly p, RuleOld* r) { |
---|
[d51339] | 469 | last = last->insert(t,i,p,r); |
---|
[e3b5ed] | 470 | if(NULL == first) { |
---|
| 471 | first = last; |
---|
| 472 | } |
---|
[d51339] | 473 | length++; |
---|
[598870] | 474 | //Print("LENGTH %d\n",length); |
---|
[d51339] | 475 | } |
---|
| 476 | |
---|
| 477 | // insertion in front of the list, needed for sPolyList |
---|
[a05c71] | 478 | void LList::insertSP(LPolyOld* lp) { |
---|
[d51339] | 479 | first = first->insertSP(lp); |
---|
[87beab7] | 480 | length++; |
---|
[598870] | 481 | //Print("LENGTH %d\n",length); |
---|
[87beab7] | 482 | } |
---|
| 483 | |
---|
[a05c71] | 484 | void LList::insertSP(poly t,int i, poly p, RuleOld* r) { |
---|
[d51339] | 485 | first = first->insertSP(t,i,p,r); |
---|
[416ea2] | 486 | length++; |
---|
[598870] | 487 | //Print("LENGTH %d\n",length); |
---|
[416ea2] | 488 | } |
---|
| 489 | |
---|
[d51339] | 490 | |
---|
[a05c71] | 491 | void LList::insertByLabel(poly t, int i, poly p, RuleOld* r) { |
---|
[87beab7] | 492 | first = first->insertByLabel(t,i,p,r); |
---|
[9bb97e] | 493 | length++; |
---|
[598870] | 494 | //Print("LENGTH %d\n",length); |
---|
[71f00c5] | 495 | } |
---|
| 496 | |
---|
[f16a76d] | 497 | void LList::insertFirst(LNode* l) { |
---|
| 498 | first = first->insertFirst(l); |
---|
| 499 | length++; |
---|
| 500 | //Print("LENGTH %d\n",length); |
---|
| 501 | } |
---|
| 502 | |
---|
[87beab7] | 503 | void LList::insertByLabel(LNode* l) { |
---|
[e90881] | 504 | first = first->insertByLabel(l); |
---|
[9bb97e] | 505 | length++; |
---|
[598870] | 506 | //Print("LENGTH %d\n",length); |
---|
[71f00c5] | 507 | } |
---|
| 508 | |
---|
[cce6ed3] | 509 | void LList::deleteByDeg() { |
---|
| 510 | first = first->deleteByDeg(); |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | bool LList::polyTest(poly* p) { |
---|
| 514 | return first->polyTest(p); |
---|
[71f00c5] | 515 | } |
---|
| 516 | |
---|
| 517 | LNode* LList::getFirst() { |
---|
| 518 | return first; |
---|
| 519 | } |
---|
| 520 | |
---|
[416ea2] | 521 | LNode* LList::getLast() { |
---|
| 522 | return last; |
---|
| 523 | } |
---|
| 524 | |
---|
[9bb97e] | 525 | int LList::getLength() { |
---|
| 526 | return length; |
---|
| 527 | } |
---|
| 528 | |
---|
[fcb8022] | 529 | void LList::setFirst(LNode* l) { |
---|
[61944d0] | 530 | LNode* temp = first; |
---|
| 531 | temp->setNext(NULL); |
---|
[fcb8022] | 532 | first = l; |
---|
[416ea2] | 533 | length--; |
---|
[fcb8022] | 534 | } |
---|
| 535 | |
---|
[d51339] | 536 | void LList::print() { |
---|
| 537 | first->print(); |
---|
| 538 | } |
---|
[fcb8022] | 539 | |
---|
[e90881] | 540 | int LList::count(LNode* l) { |
---|
| 541 | return first->count(l); |
---|
| 542 | } |
---|
[a0350e9] | 543 | /* |
---|
| 544 | ======================================= |
---|
[66e7b5] | 545 | functions working on the class LTagNode |
---|
[a0350e9] | 546 | ======================================= |
---|
| 547 | */ |
---|
[87beab7] | 548 | LTagNode::LTagNode() { |
---|
| 549 | data = NULL; |
---|
| 550 | next = NULL; |
---|
| 551 | } |
---|
[a0350e9] | 552 | |
---|
[66e7b5] | 553 | LTagNode::LTagNode(LNode* l) { |
---|
[a0350e9] | 554 | data = l; |
---|
| 555 | next = NULL; |
---|
| 556 | } |
---|
| 557 | |
---|
[66e7b5] | 558 | LTagNode::LTagNode(LNode* l, LTagNode* n) { |
---|
| 559 | data = l; |
---|
| 560 | next = n; |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | LTagNode::~LTagNode() { |
---|
[a0350e9] | 564 | delete data; |
---|
| 565 | } |
---|
| 566 | |
---|
[66e7b5] | 567 | // declaration with first as parameter due to sorting of LTagList |
---|
| 568 | LTagNode* LTagNode::insert(LNode* l) { |
---|
| 569 | LTagNode* newElement = new LTagNode(l, this); |
---|
| 570 | return newElement; |
---|
[a0350e9] | 571 | } |
---|
| 572 | |
---|
[66e7b5] | 573 | LNode* LTagNode::getLNode() { |
---|
[a0350e9] | 574 | return this->data; |
---|
| 575 | } |
---|
| 576 | |
---|
[d51339] | 577 | LTagNode* LTagNode::getNext() { |
---|
| 578 | return next; |
---|
| 579 | } |
---|
| 580 | |
---|
[66e7b5] | 581 | // NOTE: We insert at the beginning of the list and length = i-1, where i is the actual index. |
---|
[a05c71] | 582 | // Thus given actual index i and idx being the index of the LPolyOld under investigation |
---|
[66e7b5] | 583 | // the element on position length-idx is the right one |
---|
| 584 | LNode* LTagNode::get(int idx, int length) { |
---|
| 585 | if(idx == 1) { |
---|
| 586 | return NULL; |
---|
| 587 | } |
---|
| 588 | else { |
---|
| 589 | int j; |
---|
| 590 | LTagNode* temp = this; // last |
---|
| 591 | for(j=1;j<=length-idx+1;j++) { |
---|
| 592 | temp = temp->next; |
---|
| 593 | } |
---|
| 594 | return temp->data; |
---|
[a0350e9] | 595 | } |
---|
| 596 | } |
---|
| 597 | |
---|
[66e7b5] | 598 | |
---|
[a0350e9] | 599 | /* |
---|
| 600 | ======================================= |
---|
[66e7b5] | 601 | functions working on the class LTagList |
---|
[a0350e9] | 602 | ======================================= |
---|
| 603 | */ |
---|
[87beab7] | 604 | LTagList::LTagList() { |
---|
| 605 | LTagNode* first = new LTagNode(); |
---|
[d51339] | 606 | |
---|
[87beab7] | 607 | length = 0; |
---|
| 608 | } |
---|
[a0350e9] | 609 | |
---|
[66e7b5] | 610 | LTagList::LTagList(LNode* l) { |
---|
| 611 | LTagNode* first = new LTagNode(l); |
---|
| 612 | length = 1; |
---|
[a0350e9] | 613 | } |
---|
| 614 | |
---|
[6b0aa2] | 615 | LTagList::~LTagList() { |
---|
| 616 | LTagNode* temp; |
---|
| 617 | while(first) { |
---|
| 618 | temp = first; |
---|
| 619 | first = first->getNext(); |
---|
| 620 | delete temp; |
---|
| 621 | //Print("%p\n",first); |
---|
| 622 | } |
---|
| 623 | } |
---|
| 624 | |
---|
[66e7b5] | 625 | // declaration with first as parameter in LTagNode due to sorting of LTagList |
---|
| 626 | void LTagList::insert(LNode* l) { |
---|
| 627 | first = first->insert(l); |
---|
| 628 | length++; |
---|
[a0350e9] | 629 | } |
---|
| 630 | |
---|
[d51339] | 631 | void LTagList::setFirstCurrentIdx(LNode* l) { |
---|
| 632 | firstCurrentIdx = l; |
---|
| 633 | } |
---|
| 634 | |
---|
[66e7b5] | 635 | LNode* LTagList::get(int idx) { |
---|
| 636 | return first->get(idx, length); |
---|
[a0350e9] | 637 | } |
---|
| 638 | |
---|
[87beab7] | 639 | LNode* LTagList::getFirst() { |
---|
| 640 | return first->getLNode(); |
---|
| 641 | } |
---|
| 642 | |
---|
[d51339] | 643 | LNode* LTagList::getFirstCurrentIdx() { |
---|
| 644 | return firstCurrentIdx; |
---|
| 645 | } |
---|
[87beab7] | 646 | |
---|
| 647 | /* |
---|
| 648 | ===================================== |
---|
| 649 | functions working on the class TopRed |
---|
| 650 | ===================================== |
---|
| 651 | */ |
---|
| 652 | |
---|
| 653 | TopRed::TopRed() { |
---|
| 654 | _completed = NULL; |
---|
| 655 | _toDo = NULL; |
---|
| 656 | } |
---|
| 657 | |
---|
| 658 | TopRed::TopRed(LList* c, LList* t) { |
---|
| 659 | _completed = c; |
---|
| 660 | _toDo = t; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | LList* TopRed::getCompleted() { |
---|
| 664 | return _completed; |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | LList* TopRed::getToDo() { |
---|
| 668 | return _toDo; |
---|
| 669 | } |
---|
| 670 | |
---|
[a0350e9] | 671 | /* |
---|
| 672 | ==================================== |
---|
| 673 | functions working on the class CNode |
---|
| 674 | ==================================== |
---|
| 675 | */ |
---|
| 676 | |
---|
[66e7b5] | 677 | CNode::CNode() { |
---|
| 678 | data = NULL; |
---|
| 679 | next = NULL; |
---|
| 680 | } |
---|
| 681 | |
---|
[0179d5] | 682 | CNode::CNode(CPairOld* c) { |
---|
[a0350e9] | 683 | data = c; |
---|
| 684 | next = NULL; |
---|
| 685 | } |
---|
| 686 | |
---|
[0179d5] | 687 | CNode::CNode(CPairOld* c, CNode* n) { |
---|
[66e7b5] | 688 | data = c; |
---|
| 689 | next = n; |
---|
| 690 | } |
---|
| 691 | |
---|
[a0350e9] | 692 | CNode::~CNode() { |
---|
| 693 | delete data; |
---|
| 694 | } |
---|
| 695 | |
---|
| 696 | // insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label |
---|
| 697 | // note: as all critical pairs have the same index here, the second sort is done on the terms of the labels |
---|
| 698 | // working only with linked, but not doubly linked lists due to memory usage we have to check the |
---|
| 699 | // insertion around the first element separately from the insertion around all other elements in the list |
---|
[0179d5] | 700 | CNode* CNode::insert(CPairOld* c) { |
---|
[7c81165] | 701 | if(NULL == this) { |
---|
[66e7b5] | 702 | CNode* newElement = new CNode(c, this); |
---|
[a0350e9] | 703 | return newElement; |
---|
| 704 | } |
---|
[66e7b5] | 705 | else { |
---|
| 706 | poly u1 = ppMult_qq(c->getT1(),c->getLp1Term()); |
---|
| 707 | if( c->getDeg() < this->data->getDeg() ) { // lower degree than the first list element |
---|
| 708 | CNode* newElement = new CNode(c, this); |
---|
[a0350e9] | 709 | return newElement; |
---|
| 710 | } |
---|
[66e7b5] | 711 | if( c->getDeg() == this->data->getDeg() ) { // same degree than the first list element |
---|
[fcb8022] | 712 | if(1 != pLmCmp(u1,ppMult_qq(this->data->getT1(), this->data->getLp1Term()))) { |
---|
[598870] | 713 | //pWrite(u1); |
---|
| 714 | //Print("Multi-Term in CritPairs Sortierung altes Element: "); |
---|
| 715 | //pWrite(ppMult_qq(this->data->getT1(),this->data->getLp1Term())); |
---|
[66e7b5] | 716 | CNode* newElement = new CNode(c, this); |
---|
| 717 | return newElement; |
---|
| 718 | } |
---|
| 719 | else { |
---|
[598870] | 720 | //Print("Insert Deg\n"); |
---|
[66e7b5] | 721 | CNode* temp = this; |
---|
[7c81165] | 722 | while( NULL != temp->next) { |
---|
[66e7b5] | 723 | if(temp->next->data->getDeg() == c->getDeg() ) { |
---|
| 724 | if(1 == pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),temp->next->data->getLp1Term()))) { |
---|
| 725 | temp = temp->next; |
---|
| 726 | } |
---|
| 727 | else { |
---|
| 728 | CNode* newElement = new CNode(c, temp->next); |
---|
| 729 | temp->next = newElement; |
---|
| 730 | return this; |
---|
| 731 | } |
---|
[a0350e9] | 732 | } |
---|
| 733 | else { |
---|
[66e7b5] | 734 | CNode* newElement = new CNode(c, temp->next); |
---|
[a0350e9] | 735 | temp->next = newElement; |
---|
| 736 | return this; |
---|
[66e7b5] | 737 | } |
---|
[a0350e9] | 738 | } |
---|
[7c81165] | 739 | CNode* newElement = new CNode(c, NULL); |
---|
[a0350e9] | 740 | temp->next = newElement; |
---|
| 741 | return this; |
---|
| 742 | } |
---|
[66e7b5] | 743 | } // outer if-clause |
---|
| 744 | if( c->getDeg() > this->data->getDeg() ) { // greater degree than the first list element |
---|
| 745 | CNode* temp = this; |
---|
[7c81165] | 746 | while( NULL != temp->next ) { |
---|
[66e7b5] | 747 | if( c->getDeg() < temp->next->data->getDeg() ) { |
---|
| 748 | CNode* newElement = new CNode(c, temp->next); |
---|
[a0350e9] | 749 | temp->next = newElement; |
---|
| 750 | return this; |
---|
| 751 | } |
---|
[66e7b5] | 752 | if( c->getDeg() == temp->next->data->getDeg() ) { |
---|
[fcb8022] | 753 | if(1 != pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),temp->next->data->getLp1Term()))) { |
---|
[66e7b5] | 754 | CNode* newElement = new CNode(c, temp->next); |
---|
| 755 | temp->next = newElement; |
---|
| 756 | return this; |
---|
| 757 | } |
---|
| 758 | else { |
---|
| 759 | temp = temp->next; |
---|
[7c81165] | 760 | while( NULL != temp->next ) { |
---|
[66e7b5] | 761 | if( temp->next->data->getDeg() == c->getDeg() ) { |
---|
| 762 | if(1 == pLmCmp(u1,ppMult_qq(temp->next->data->getT1(), |
---|
| 763 | temp->next->data->getLp1Term()))) { |
---|
| 764 | temp = temp->next; |
---|
| 765 | } |
---|
| 766 | else { |
---|
| 767 | CNode* newElement = new CNode(c, temp->next); |
---|
| 768 | temp->next = newElement; |
---|
| 769 | return this; |
---|
| 770 | } |
---|
[a0350e9] | 771 | } |
---|
| 772 | else { |
---|
[66e7b5] | 773 | CNode* newElement = new CNode(c, temp->next); |
---|
[a0350e9] | 774 | temp->next = newElement; |
---|
| 775 | return this; |
---|
[66e7b5] | 776 | } |
---|
[a0350e9] | 777 | } |
---|
[7c81165] | 778 | CNode* newElement = new CNode(c, NULL); |
---|
[66e7b5] | 779 | temp->next = newElement; |
---|
| 780 | return this; |
---|
[a0350e9] | 781 | } |
---|
[66e7b5] | 782 | } |
---|
| 783 | if( c->getDeg() > temp->next->data->getDeg() ) { |
---|
| 784 | temp = temp->next; |
---|
[a0350e9] | 785 | } |
---|
| 786 | } |
---|
[7c81165] | 787 | CNode* newElement = new CNode(c, NULL); |
---|
[66e7b5] | 788 | temp->next = newElement; |
---|
| 789 | return this; |
---|
[a0350e9] | 790 | } |
---|
| 791 | } |
---|
| 792 | } |
---|
| 793 | |
---|
[ab76b4] | 794 | |
---|
| 795 | CNode* CNode::insertWithoutSort(CPairOld* cp) { |
---|
| 796 | CNode* newElement = new CNode(cp); |
---|
| 797 | newElement->next = this; |
---|
| 798 | return newElement; |
---|
| 799 | } |
---|
| 800 | |
---|
| 801 | |
---|
[0179d5] | 802 | // get the first elements from CListOld which by the above sorting have minimal degree |
---|
[cce6ed3] | 803 | CNode* CNode::getMinDeg() { |
---|
| 804 | CNode* temp = this; |
---|
[7c81165] | 805 | while(NULL != temp) { |
---|
| 806 | while(NULL != temp->next && temp->next->data->getDeg() == this->data->getDeg()) { |
---|
[cce6ed3] | 807 | temp = temp->next; |
---|
| 808 | } |
---|
| 809 | CNode* returnCNode = temp->next; |
---|
[0179d5] | 810 | // every CListOld should end with a (NULL,NULL) element for a similar behaviour |
---|
[9bb97e] | 811 | // using termination conditions throughout the algorithm |
---|
[7c81165] | 812 | temp->next = NULL; |
---|
[cce6ed3] | 813 | return returnCNode; |
---|
| 814 | } |
---|
| 815 | return NULL; |
---|
| 816 | } |
---|
| 817 | |
---|
[0179d5] | 818 | CPairOld* CNode::getData() { |
---|
[9bb97e] | 819 | return data; |
---|
| 820 | } |
---|
| 821 | |
---|
| 822 | CNode* CNode::getNext() { |
---|
| 823 | return next; |
---|
| 824 | } |
---|
| 825 | |
---|
[a05c71] | 826 | LPolyOld* CNode::getAdLp1() { |
---|
[9bb97e] | 827 | return this->data->getAdLp1(); |
---|
| 828 | } |
---|
| 829 | |
---|
[a05c71] | 830 | LPolyOld* CNode::getAdLp2() { |
---|
[9bb97e] | 831 | return this->data->getAdLp2(); |
---|
| 832 | } |
---|
| 833 | |
---|
[66e7b5] | 834 | poly CNode::getLp1Poly() { |
---|
| 835 | return this->data->getLp1Poly(); |
---|
| 836 | } |
---|
| 837 | |
---|
| 838 | poly CNode::getLp2Poly() { |
---|
| 839 | return this->data->getLp2Poly(); |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | poly CNode::getLp1Term() { |
---|
| 843 | return this->data->getLp1Term(); |
---|
| 844 | } |
---|
| 845 | |
---|
| 846 | poly CNode::getLp2Term() { |
---|
| 847 | return this->data->getLp2Term(); |
---|
| 848 | } |
---|
| 849 | |
---|
| 850 | int CNode::getLp1Index() { |
---|
| 851 | return this->data->getLp1Index(); |
---|
| 852 | } |
---|
| 853 | |
---|
| 854 | int CNode::getLp2Index() { |
---|
| 855 | return this->data->getLp2Index(); |
---|
| 856 | } |
---|
| 857 | |
---|
| 858 | poly CNode::getT1() { |
---|
| 859 | return this->data->getT1(); |
---|
| 860 | } |
---|
| 861 | |
---|
[9bb97e] | 862 | poly* CNode::getAdT1() { |
---|
| 863 | return this->data->getAdT1(); |
---|
| 864 | } |
---|
| 865 | |
---|
[66e7b5] | 866 | poly CNode::getT2() { |
---|
| 867 | return this->data->getT2(); |
---|
| 868 | } |
---|
| 869 | |
---|
[9bb97e] | 870 | poly* CNode::getAdT2() { |
---|
| 871 | return this->data->getAdT2(); |
---|
| 872 | } |
---|
| 873 | |
---|
[418bd6] | 874 | bool CNode::getDel() { |
---|
| 875 | return data->getDel(); |
---|
| 876 | } |
---|
| 877 | |
---|
[a05c71] | 878 | RuleOld* CNode::getTestedRuleOld() { |
---|
| 879 | return this->data->getTestedRuleOld(); |
---|
[9bb97e] | 880 | } |
---|
| 881 | |
---|
[66e7b5] | 882 | // for debugging |
---|
| 883 | void CNode::print() { |
---|
| 884 | CNode* temp = this; |
---|
[d51339] | 885 | Print("___________________List of critical pairs______________________:\n"); |
---|
[7c81165] | 886 | while(NULL != temp) { |
---|
[f16a76d] | 887 | pWrite(ppMult_qq(temp->getT1(),temp->getLp1Term())); |
---|
[d51339] | 888 | Print("LP1 Index: %d\n",temp->getLp1Index()); |
---|
[66e7b5] | 889 | Print("T1: "); |
---|
| 890 | pWrite(temp->getT1()); |
---|
[1534d9] | 891 | Print("%p\n",temp->getT1()); |
---|
[d51339] | 892 | Print("LP1 Term: "); |
---|
[66e7b5] | 893 | pWrite(temp->getLp1Term()); |
---|
[d51339] | 894 | Print("LP1 Poly: "); |
---|
| 895 | pWrite(temp->getLp1Poly()); |
---|
| 896 | Print("LP2 Index: %d\n",temp->getLp2Index()); |
---|
| 897 | Print("T2: "); |
---|
[66e7b5] | 898 | pWrite(temp->getT2()); |
---|
[1534d9] | 899 | Print("%p\n",temp->getT2()); |
---|
[d51339] | 900 | Print("LP2 Term: "); |
---|
[66e7b5] | 901 | pWrite(temp->getLp2Term()); |
---|
[d51339] | 902 | Print("LP2 Poly: "); |
---|
| 903 | pWrite(temp->getLp2Poly()); |
---|
[66e7b5] | 904 | Print("\n"); |
---|
| 905 | temp = temp->next; |
---|
| 906 | } |
---|
| 907 | } |
---|
[cce6ed3] | 908 | |
---|
[a0350e9] | 909 | /* |
---|
| 910 | ==================================== |
---|
[0179d5] | 911 | functions working on the class CListOld |
---|
[a0350e9] | 912 | ==================================== |
---|
| 913 | */ |
---|
[0179d5] | 914 | // for initialization of CListOlds, last element alwas has data=NULL and next=NULL |
---|
| 915 | CListOld::CListOld() { |
---|
[7c81165] | 916 | first = NULL; |
---|
[66e7b5] | 917 | } |
---|
| 918 | |
---|
[0179d5] | 919 | CListOld::CListOld(CPairOld* c) { |
---|
[66e7b5] | 920 | first = new CNode(c); |
---|
[a0350e9] | 921 | } |
---|
| 922 | |
---|
[0179d5] | 923 | CListOld::~CListOld() { |
---|
[9cb4078] | 924 | CNode* temp; |
---|
[7c81165] | 925 | while(NULL != first) { |
---|
[9cb4078] | 926 | temp = first; |
---|
| 927 | first = first->getNext(); |
---|
| 928 | delete temp; |
---|
| 929 | } |
---|
[a0350e9] | 930 | } |
---|
| 931 | |
---|
| 932 | // insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label |
---|
| 933 | // note: as all critical pairs have the same index here, the second sort is done on the terms of the labels |
---|
[0179d5] | 934 | void CListOld::insert(CPairOld* c) { |
---|
[7c81165] | 935 | first = first->insert(c); |
---|
[71f00c5] | 936 | } |
---|
[cce6ed3] | 937 | |
---|
[ab76b4] | 938 | void CListOld::insertWithoutSort(CPairOld* c) { |
---|
| 939 | first = first->insertWithoutSort(c); |
---|
| 940 | } |
---|
| 941 | |
---|
[0179d5] | 942 | CNode* CListOld::getFirst() { |
---|
[9bb97e] | 943 | return first; |
---|
| 944 | } |
---|
| 945 | |
---|
[0179d5] | 946 | // get the first elements from CListOld which by the above sorting have minimal degree |
---|
[cce6ed3] | 947 | // returns the pointer on the first element of those |
---|
[0179d5] | 948 | CNode* CListOld::getMinDeg() { |
---|
[cce6ed3] | 949 | CNode* temp = first; |
---|
| 950 | first = first->getMinDeg(); |
---|
| 951 | return temp; |
---|
| 952 | } |
---|
| 953 | |
---|
[0179d5] | 954 | void CListOld::print() { |
---|
[66e7b5] | 955 | first->print(); |
---|
| 956 | } |
---|
[cce6ed3] | 957 | |
---|
| 958 | /* |
---|
| 959 | ==================================== |
---|
| 960 | functions working on the class RNode |
---|
| 961 | ==================================== |
---|
| 962 | */ |
---|
[66e7b5] | 963 | RNode::RNode() { |
---|
[55a828] | 964 | //Print("HIER RNODE CONSTRUCTOR\n"); |
---|
[66e7b5] | 965 | data = NULL; |
---|
| 966 | next = NULL; |
---|
| 967 | } |
---|
| 968 | |
---|
[a05c71] | 969 | RNode::RNode(RuleOld* r) { |
---|
[cce6ed3] | 970 | data = r; |
---|
| 971 | next = NULL; |
---|
| 972 | } |
---|
| 973 | |
---|
| 974 | RNode::~RNode() { |
---|
[a05c71] | 975 | //Print("DELETE RuleOld\n"); |
---|
[cce6ed3] | 976 | delete data; |
---|
| 977 | } |
---|
| 978 | |
---|
[a05c71] | 979 | RNode* RNode::insert(RuleOld* r) { |
---|
[cce6ed3] | 980 | RNode* newElement = new RNode(r); |
---|
| 981 | newElement->next = this; |
---|
| 982 | return newElement; |
---|
| 983 | } |
---|
| 984 | |
---|
[87beab7] | 985 | RNode* RNode::insert(int i, poly t) { |
---|
[55a828] | 986 | //Print("IN INSERT: "); |
---|
| 987 | //pWrite(t); |
---|
[a05c71] | 988 | RuleOld* r = new RuleOld(i,t); |
---|
| 989 | //Print("ADDRESS OF RuleOld: %p\n",r); |
---|
[9bb97e] | 990 | RNode* newElement = new RNode(r); |
---|
[55a828] | 991 | //Print("ADDRESS OF RNODE: %p\n",newElement); |
---|
[a05c71] | 992 | //Print("ADDRESS OF RNODE DATA: %p\n",newElement->getRuleOld()); |
---|
[f6c7c9b] | 993 | newElement->next = this; |
---|
| 994 | return newElement; |
---|
[787685] | 995 | } |
---|
| 996 | |
---|
| 997 | |
---|
[a05c71] | 998 | RNode* RNode::insertOrdered(RuleOld* r) { |
---|
[787685] | 999 | RNode* newElement = new RNode(r); |
---|
| 1000 | RNode* temp = this; |
---|
| 1001 | if(NULL == temp) { |
---|
| 1002 | newElement->next = temp; |
---|
| 1003 | return newElement; |
---|
| 1004 | } |
---|
[a05c71] | 1005 | if(1 == pLmCmp(newElement->getRuleOldTerm(),temp->getRuleOldTerm())) { |
---|
[787685] | 1006 | newElement->next = temp; |
---|
| 1007 | return newElement; |
---|
[1534d9] | 1008 | } |
---|
| 1009 | else { |
---|
[a05c71] | 1010 | while(NULL != temp && 1 == pLmCmp(temp->getRuleOldTerm(),newElement->getRuleOldTerm())) { |
---|
[787685] | 1011 | temp = temp->getNext(); |
---|
[1534d9] | 1012 | } |
---|
[787685] | 1013 | newElement->next = temp; |
---|
| 1014 | return this; |
---|
[1534d9] | 1015 | } |
---|
[9bb97e] | 1016 | } |
---|
| 1017 | |
---|
[787685] | 1018 | |
---|
[66e7b5] | 1019 | RNode* RNode::getNext() { |
---|
| 1020 | return next; |
---|
| 1021 | } |
---|
| 1022 | |
---|
[a05c71] | 1023 | RuleOld* RNode::getRuleOld() { |
---|
[66e7b5] | 1024 | return data; |
---|
| 1025 | } |
---|
| 1026 | |
---|
[a05c71] | 1027 | int RNode::getRuleOldIndex() { |
---|
[66e7b5] | 1028 | return data->getIndex(); |
---|
| 1029 | } |
---|
| 1030 | |
---|
[a05c71] | 1031 | poly RNode::getRuleOldTerm() { |
---|
[66e7b5] | 1032 | return data->getTerm(); |
---|
| 1033 | } |
---|
| 1034 | |
---|
[6b0aa2] | 1035 | void RNode::print() { |
---|
| 1036 | RNode* temp = this; |
---|
| 1037 | while(NULL != temp) { |
---|
[a05c71] | 1038 | pWrite(temp->getRuleOldTerm()); |
---|
| 1039 | Print("%d\n\n",temp->getRuleOldIndex()); |
---|
[6b0aa2] | 1040 | temp = temp->getNext(); |
---|
| 1041 | } |
---|
| 1042 | } |
---|
| 1043 | |
---|
[cce6ed3] | 1044 | /* |
---|
| 1045 | ==================================== |
---|
| 1046 | functions working on the class RList |
---|
| 1047 | ==================================== |
---|
| 1048 | */ |
---|
[66e7b5] | 1049 | RList::RList() { |
---|
[1534d9] | 1050 | first = NULL; |
---|
[66e7b5] | 1051 | } |
---|
| 1052 | |
---|
[a05c71] | 1053 | RList::RList(RuleOld* r) { |
---|
[cce6ed3] | 1054 | first = new RNode(r); |
---|
| 1055 | } |
---|
| 1056 | |
---|
[338842d] | 1057 | RList::~RList() { |
---|
[9cb4078] | 1058 | RNode* temp; |
---|
[55a828] | 1059 | //Print("%p\n",first); |
---|
[1534d9] | 1060 | while(first) { |
---|
[9cb4078] | 1061 | temp = first; |
---|
| 1062 | first = first->getNext(); |
---|
[55a828] | 1063 | //Print("1 %p\n",first); |
---|
| 1064 | //if(first) { |
---|
[a05c71] | 1065 | //Print("1' %p\n",first->getRuleOld()); |
---|
[55a828] | 1066 | //Print("2 %p\n",first->getNext()); |
---|
[a05c71] | 1067 | //Print("3 %p\n",first->getNext()->getRuleOld()); |
---|
| 1068 | //Print("3 %p\n",first->getNext()->getRuleOldTerm()); |
---|
[55a828] | 1069 | //} |
---|
[9cb4078] | 1070 | delete temp; |
---|
| 1071 | } |
---|
[55a828] | 1072 | //Print("FERTIG\n"); |
---|
[9cb4078] | 1073 | } |
---|
[338842d] | 1074 | |
---|
[87beab7] | 1075 | void RList::insert(int i, poly t) { |
---|
| 1076 | first = first->insert(i,t); |
---|
[9bb97e] | 1077 | } |
---|
| 1078 | |
---|
[a05c71] | 1079 | void RList::insert(RuleOld* r) { |
---|
[cce6ed3] | 1080 | first = first->insert(r); |
---|
| 1081 | } |
---|
[66e7b5] | 1082 | |
---|
[a05c71] | 1083 | void RList::insertOrdered(RuleOld* r) { |
---|
[787685] | 1084 | first = first->insertOrdered(r); |
---|
| 1085 | } |
---|
| 1086 | |
---|
[66e7b5] | 1087 | RNode* RList::getFirst() { |
---|
| 1088 | return first; |
---|
| 1089 | } |
---|
| 1090 | |
---|
[a05c71] | 1091 | RuleOld* RList::getRuleOld() { |
---|
| 1092 | return this->getRuleOld(); |
---|
[66e7b5] | 1093 | } |
---|
| 1094 | |
---|
[6b0aa2] | 1095 | void RList::print() { |
---|
| 1096 | first->print(); |
---|
| 1097 | } |
---|
| 1098 | |
---|
[66e7b5] | 1099 | /* |
---|
| 1100 | ======================================= |
---|
| 1101 | functions working on the class RTagNode |
---|
| 1102 | ======================================= |
---|
| 1103 | */ |
---|
| 1104 | |
---|
[a41f3aa] | 1105 | RTagNode::RTagNode() { |
---|
| 1106 | data = NULL; |
---|
| 1107 | next = NULL; |
---|
| 1108 | } |
---|
| 1109 | |
---|
[66e7b5] | 1110 | RTagNode::RTagNode(RNode* r) { |
---|
| 1111 | data = r; |
---|
| 1112 | next = NULL; |
---|
| 1113 | } |
---|
| 1114 | |
---|
| 1115 | RTagNode::RTagNode(RNode* r, RTagNode* n) { |
---|
[e6d283f] | 1116 | |
---|
[66e7b5] | 1117 | data = r; |
---|
| 1118 | next = n; |
---|
| 1119 | } |
---|
| 1120 | |
---|
[338842d] | 1121 | RTagNode::~RTagNode() { |
---|
[66e7b5] | 1122 | delete data; |
---|
| 1123 | } |
---|
| 1124 | |
---|
[fcb8022] | 1125 | // declaration with first as parameter due to sorting of RTagList |
---|
[66e7b5] | 1126 | RTagNode* RTagNode::insert(RNode* r) { |
---|
[598870] | 1127 | //Print("Hier1\n"); |
---|
[66e7b5] | 1128 | RTagNode* newElement = new RTagNode(r, this); |
---|
[598870] | 1129 | //Print("Hier2\n"); |
---|
[66e7b5] | 1130 | return newElement; |
---|
| 1131 | } |
---|
| 1132 | |
---|
| 1133 | RNode* RTagNode::getRNode() { |
---|
[df638fb] | 1134 | //Print("%p\n", this); |
---|
| 1135 | //Print("%p\n",this->data); |
---|
[66e7b5] | 1136 | return this->data; |
---|
| 1137 | } |
---|
| 1138 | |
---|
[9cb4078] | 1139 | RTagNode* RTagNode::getNext() { |
---|
| 1140 | return next; |
---|
| 1141 | } |
---|
| 1142 | |
---|
[66e7b5] | 1143 | // NOTE: We insert at the beginning of the list and length = i-1, where i is the actual index. |
---|
[a05c71] | 1144 | // Thus given actual index i and idx being the index of the LPolyOld under investigation |
---|
[66e7b5] | 1145 | // the element on position length-idx+1 is the right one |
---|
| 1146 | RNode* RTagNode::get(int idx, int length) { |
---|
[a41f3aa] | 1147 | if(idx==1 || idx==0) { |
---|
[87beab7] | 1148 | // NOTE: We set this NULL as putting it the last element in the list, i.e. the element having |
---|
| 1149 | // RNode* = NULL would cost lots of iterations at each step of F5inc, with increasing |
---|
| 1150 | // length of the list this should be prevented |
---|
[66e7b5] | 1151 | return NULL; |
---|
| 1152 | } |
---|
| 1153 | else { |
---|
| 1154 | int j; |
---|
| 1155 | RTagNode* temp = this; |
---|
[598870] | 1156 | //Print("\n\nHIER IN GET IDX\n"); |
---|
| 1157 | //Print("FOR LOOP: %d\n",length-idx+1); |
---|
[87beab7] | 1158 | for(j=1; j<=length-idx+1; j++) { |
---|
[66e7b5] | 1159 | temp = temp->next; |
---|
| 1160 | } |
---|
| 1161 | return temp->data; |
---|
| 1162 | } |
---|
| 1163 | } |
---|
| 1164 | |
---|
[fcb8022] | 1165 | void RTagNode::set(RNode* r) { |
---|
| 1166 | this->data = r; |
---|
| 1167 | } |
---|
[66e7b5] | 1168 | |
---|
[ae5177] | 1169 | |
---|
[87beab7] | 1170 | void RTagNode::print() { |
---|
| 1171 | RTagNode* temp = this; |
---|
[e6d283f] | 1172 | if(NULL != temp && NULL != temp->getRNode()) { |
---|
[a05c71] | 1173 | Print("1. element: %d, ",getRNode()->getRuleOld()->getIndex()); |
---|
| 1174 | pWrite(getRNode()->getRuleOld()->getTerm()); |
---|
[87beab7] | 1175 | temp = temp->next; |
---|
[e6d283f] | 1176 | int i = 2; |
---|
| 1177 | while(NULL != temp->getRNode() && NULL != temp) { |
---|
[a05c71] | 1178 | Print("%d. element: %d, ",i,getRNode()->getRuleOld()->getIndex()); |
---|
| 1179 | pWrite(getRNode()->getRuleOld()->getTerm()); |
---|
[e6d283f] | 1180 | temp = temp->next; |
---|
| 1181 | i++; |
---|
| 1182 | } |
---|
[87beab7] | 1183 | } |
---|
| 1184 | } |
---|
[ae5177] | 1185 | |
---|
[66e7b5] | 1186 | /* |
---|
| 1187 | ======================================= |
---|
| 1188 | functions working on the class LTagList |
---|
| 1189 | ======================================= |
---|
| 1190 | */ |
---|
| 1191 | |
---|
[a41f3aa] | 1192 | RTagList::RTagList() { |
---|
| 1193 | RTagNode* first = new RTagNode(); |
---|
| 1194 | length = 0; |
---|
| 1195 | } |
---|
| 1196 | |
---|
[66e7b5] | 1197 | RTagList::RTagList(RNode* r) { |
---|
| 1198 | RTagNode* first = new RTagNode(r); |
---|
| 1199 | length = 1; |
---|
| 1200 | } |
---|
| 1201 | |
---|
[338842d] | 1202 | RTagList::~RTagList() { |
---|
[9cb4078] | 1203 | RTagNode* temp; |
---|
[c4158f] | 1204 | while(first) { |
---|
[9cb4078] | 1205 | temp = first; |
---|
| 1206 | first = first->getNext(); |
---|
| 1207 | delete temp; |
---|
| 1208 | } |
---|
[338842d] | 1209 | } |
---|
| 1210 | |
---|
[66e7b5] | 1211 | // declaration with first as parameter in LTagNode due to sorting of LTagList |
---|
| 1212 | void RTagList::insert(RNode* r) { |
---|
| 1213 | first = first->insert(r); |
---|
[598870] | 1214 | //Print("LENGTH:%d\n",length); |
---|
[87beab7] | 1215 | length = length +1; |
---|
[598870] | 1216 | //Print("LENGTH:%d\n",length); |
---|
[66e7b5] | 1217 | } |
---|
| 1218 | |
---|
[8978fd] | 1219 | RNode* RTagList::getFirst() { |
---|
| 1220 | return first->getRNode(); |
---|
| 1221 | } |
---|
| 1222 | |
---|
[66e7b5] | 1223 | RNode* RTagList::get(int idx) { |
---|
| 1224 | return first->get(idx, length); |
---|
| 1225 | } |
---|
[fcb8022] | 1226 | |
---|
| 1227 | void RTagList::setFirst(RNode* r) { |
---|
| 1228 | first->set(r); |
---|
| 1229 | } |
---|
[87beab7] | 1230 | |
---|
| 1231 | void RTagList::print() { |
---|
| 1232 | first->print(); |
---|
| 1233 | } |
---|
| 1234 | |
---|
| 1235 | int RTagList::getLength() { |
---|
| 1236 | return length; |
---|
| 1237 | } |
---|
[71f00c5] | 1238 | #endif |
---|