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