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