source: git/kernel/lists.cc @ a0350e9

spielwiese
Last change on this file since a0350e9 was a0350e9, checked in by Christian Eder, 15 years ago
added lists for critical pairs git-svn-id: file:///usr/local/Singular/svn/trunk@11321 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.5 KB
Line 
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"
18#include "lpolynomial.h"
19#include "lists.h"
20
21/*
22====================================
23functions working on the class LNode
24====================================
25*/
26
27// generating new list elements (labeled / classical polynomial / LNode view)
28LNode::LNode(LPoly* lp) {
29    data = lp;
30    next = NULL;
31}
32       
33LNode::LNode(poly* t, int* i, poly* p) {
34    LPoly* lp = new LPoly(t,i,p);
35    data = lp;
36    Print("Index angelegt?  %d\n",*(data->getIndex()));
37    next = NULL;
38}
39       
40LNode::LNode(LNode* ln) {
41    data = ln->getLPoly();
42    next = ln->getNext();
43}
44       
45LNode::~LNode() {
46    delete next;
47    delete data;   
48}
49       
50// insert new elements to the list always in front (labeled / classical polynomial view)
51LNode* LNode::insert(LPoly* lp) {
52    LNode* newElement = new LNode(lp);
53    newElement->next = this;
54    return newElement;
55}
56       
57LNode* LNode::insert(poly* t, int* i, poly* p) {
58    LNode* newElement = new LNode(t,i,p);
59    newElement->next = this;
60    return newElement;
61}
62       
63// get next from current LNode
64LNode* LNode::getNext() {
65    return next;
66}
67       
68// get the LPoly* out of LNode*
69LPoly* LNode::getLPoly() {
70    return data;
71}
72
73// get the address of the polynomial part of LPoly* of LNode*
74poly* LNode::getPoly() {
75    return data->getPoly();
76}
77
78// test if for any list element the polynomial part of the data is equal to *p
79bool LNode::polyTest(poly* p) {
80    LNode* temp = new LNode(this);
81    while(NULL != temp) {
82        if(pComparePolys(*(temp->getPoly()),*p)) {
83            return 1;
84        }
85        temp = temp->next;
86    }
87    return 0;
88}
89
90
91/*
92====================================
93functions working on the class LList
94====================================
95*/
96
97LList::LList(LPoly* lp) {
98    first   = new LNode(lp);
99    length  = 1;
100}
101
102LList::LList(poly* t,int* i,poly* p) {
103    first   = new LNode(t,i,p);
104    length  = 1;
105} 
106
107LList::~LList() {
108    delete first;
109}
110
111// insertion in front of the list
112void LList::insert(LPoly* lp) {
113    first = first->insert(lp);
114    length++;
115}
116
117void LList::insert(poly* t,int* i, poly* p) {
118    first = first->insert(t,i,p);
119    length++;
120}
121
122bool LList::polyTest(poly* p) {
123    return first->polyTest(p);
124}
125
126int LList::getLength() const {
127    return length;
128}
129
130LNode* LList::getFirst() {
131    return first;
132}
133
134
135/*
136=======================================
137functions working on the class PrevNode
138=======================================
139*/
140
141PrevNode::PrevNode(LNode* l) {
142    data = l;
143    next = NULL;
144}
145       
146PrevNode::~PrevNode() {
147    delete next;
148    delete data;   
149}
150       
151PrevNode* PrevNode::append(LNode* l) {
152    PrevNode* new_element = new PrevNode(l);
153    next = new_element;
154    return new_element;
155}
156
157LNode* PrevNode::getLNode() {
158    return this->data;
159}
160
161LNode* PrevNode::getPrevLast(int i) {
162    int j;
163    PrevNode* temp = this;
164    for(j=1;j<=i-1;j++) {
165        temp = temp->next;
166    }
167    return temp->data;
168}
169
170/*
171=======================================
172functions working on the class PrevList
173=======================================
174*/
175
176PrevList::PrevList(LNode* l) {
177    PrevNode* first =   new PrevNode(l);
178    last            =   first;   
179}
180
181void PrevList::append(LNode* l) {
182    last = last->append(l);
183}
184
185LNode* PrevList::getPrevLast(int i) {
186    switch(i) {
187        case 0:     return NULL;
188        case 1:     return first->getLNode();
189        default:    first->getPrevLast(i);
190    }
191}
192
193/*
194====================================
195functions working on the class CNode
196====================================
197*/
198
199CNode::CNode(CPair* c) {
200    data    =   c;   
201    next    =   NULL;   
202}
203
204CNode::~CNode() {
205    delete next;
206    delete data;
207}
208
209// insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label
210// note: as all critical pairs have the same index here, the second sort is done on the terms of the labels
211// working only with linked, but not doubly linked lists due to memory usage we have to check the
212// insertion around the first element separately from the insertion around all other elements in the list
213CNode* CNode::insert(CPair* c) {
214    if( c->getDeg() < this->data->getDeg() ) { // lower degree than the first list element
215        CNode* newElement = new CNode(c);
216        newElement->next = this;
217        return newElement;
218    }
219    if( c->getDeg() == this->data->getDeg() ) { // same degree than the first list element
220        if( c->getT1() <= this->data->getT1() ) {
221            CNode* newElement   =   new CNode(c);
222            newElement->next    =   this;
223            return newElement;
224        }
225        else {
226            CNode* temp = this;
227            while(  temp->next != NULL ) {
228                if( temp->next->data->getDeg() == c->getDeg() ) { 
229                    if( c->getT1() <= temp->next->data->getT1() ) {
230                        temp = temp->next;
231                    }
232                    else {
233                        CNode* newElement   =   new CNode(c);
234                        newElement->next    =   temp->next;
235                        temp->next          =   newElement;
236                        return this;
237                    } 
238                }
239                else {
240                    CNode* newElement   =   new CNode(c);
241                    newElement->next    =   temp->next;
242                    temp->next          =   newElement;
243                    return this;
244                }
245            }
246            CNode* newElement   =   new CNode(c);
247            newElement->next    =   NULL;
248            temp->next          =   newElement;
249            return this;
250        }
251    } // outer if-clause
252    if( c->getDeg() > this->data->getDeg() ) { // greater degree than the first list element
253        CNode* temp =   this;
254        while( temp->next != NULL) {   
255            if( c->getDeg() < temp->next->data->getDeg() ) {
256                CNode* newElement   =   new CNode(c);
257                newElement->next    =   temp->next;
258                temp->next          =   newElement;
259                return this;
260            }
261            if( c->getDeg() == temp->next->data->getDeg() ) {
262                if( c->getT1() <= temp->next->data->getT1() ) {
263                    CNode* newElement   =   new CNode(c);
264                    newElement->next    =   temp->next;
265                    temp->next          =   newElement;
266                    return this;
267                }
268                else {
269                    temp = temp->next;
270                    while(  temp->next != NULL ) {
271                        if( temp->next->data->getDeg() == c->getDeg() ) { 
272                            if( c->getT1() <= temp->next->data->getT1() ) {
273                                temp = temp->next;
274                            }
275                            else {
276                                CNode* newElement   =   new CNode(c);
277                                newElement->next    =   temp->next;
278                                temp->next          =   newElement;
279                                return this;
280                            } 
281                        }
282                        else {
283                            CNode* newElement   =   new CNode(c);
284                            newElement->next    =   temp->next;
285                            temp->next          =   newElement;
286                            return this;
287                        }
288                    }
289                    CNode* newElement   =   new CNode(c);
290                    newElement->next    =   NULL;
291                    temp->next          =   newElement;
292                    return this;
293                }
294            }
295            if( c->getDeg() > temp->next->data->getDeg() ) {
296                temp    =   temp->next;
297            }
298        }
299        CNode* newElement   =   new CNode(c);
300        newElement->next    =   NULL;
301        temp->next          =   newElement;
302        return this;
303    }
304}
305
306/*
307====================================
308functions working on the class CList
309====================================
310*/
311
312CList::CList(CPair* c) {
313    first   = new CNode(c);
314}
315
316CList::~CList() {
317    delete first;
318}
319
320// insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label
321// note: as all critical pairs have the same index here, the second sort is done on the terms of the labels
322void CList::insert(CPair* c) {
323    first = first->insert(c);
324}
325#endif
Note: See TracBrowser for help on using the repository browser.