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