source: git/kernel/splist.cc @ f599a46

spielwiese
Last change on this file since f599a46 was f599a46, checked in by mlee <martinlee84@…>, 13 years ago
moved spectrum.cc,.h and splist.cc,.h again to kernel commented out stuff related to lists and functions in ipshell.cc
  • Property mode set to 100644
File size: 10.8 KB
RevLine 
[35aab3]1// ----------------------------------------------------------------------------
2//  splist.cc
3//  begin of file
4//  Stephan Endrass, endrass@mathematik.uni-mainz.de
5//  23.7.99
6// ----------------------------------------------------------------------------
7
8#define SPLIST_CC
9
[599326]10#include <kernel/mod2.h>
[35aab3]11
12#ifdef HAVE_SPECTRUM
13
14#ifdef  SPLIST_PRINT
15#include <iostream.h>
16#ifndef SPLIST_IOSTREAM
17#include <stdio.h>
18#endif
19#endif
20
[599326]21#include <kernel/structs.h>
22#include <kernel/GMPrat.h>
[0f401f]23#include <coeffs/numbers.h>
[9af8d18]24#include <polys/monomials/p_polys.h>
[599326]25#include <kernel/npolygon.h>
26#include <kernel/splist.h>
[210e07]27#include <misc/intvec.h>
[35aab3]28
29// ------------------------
30//  class spectrumPolyNode
31// ------------------------
32
33// ----------------------------------------------------------------------------
34//  Initialize a  spectrumPolyNode  with zero
35// ----------------------------------------------------------------------------
36
37void    spectrumPolyNode::copy_zero( void )
38{
39    next   = (spectrumPolyNode*)NULL;
[ee3e1ae]40    mon    = NULL;
[35aab3]41    weight = (Rational)0;
[ee3e1ae]42    nf     = NULL;
[9af8d18]43    r      = NULL;
[35aab3]44}
45
46// ----------------------------------------------------------------------------
47//  Inizialize a  spectrumPolyNode  shallow from data
48// ----------------------------------------------------------------------------
49
50void    spectrumPolyNode::copy_shallow(
[9af8d18]51         spectrumPolyNode *pnode,poly m,const Rational &w,poly f, const ring R )
[35aab3]52{
53    next   = pnode;
54    mon    = m;
55    weight = w;
56    nf     = f;
[9af8d18]57    r      = R;
[35aab3]58}
59
60// ----------------------------------------------------------------------------
61//  Inizialize a  spectrumPolyNode  shallow from another  spectrumPolyNode
62// ----------------------------------------------------------------------------
63
64void    spectrumPolyNode::copy_shallow( spectrumPolyNode &node )
65{
66    next   = node.next;
67    mon    = node.mon;
68    weight = node.weight;
69    nf     = node.nf;
[9af8d18]70    r      = node.r;
[35aab3]71}
72
73// ----------------------------------------------------------------------------
74//  Zero constructor for  spectrumPolyNode
75// ----------------------------------------------------------------------------
76
77spectrumPolyNode::spectrumPolyNode( )
78{
79    copy_zero( );
80}
81
82// ----------------------------------------------------------------------------
83//  Data constructor for  spectrumPolyNode  is shallow
84// ----------------------------------------------------------------------------
85
86spectrumPolyNode::spectrumPolyNode(
[9af8d18]87        spectrumPolyNode *pnode,poly m,const Rational &w,poly f, const ring R )
[35aab3]88{
[9af8d18]89    copy_shallow( pnode,m,w,f,R );
[35aab3]90}
91
92// ----------------------------------------------------------------------------
93//  Destructor is empty since we construct our objects shallow
94// ----------------------------------------------------------------------------
95
[9af8d18]96spectrumPolyNode::~spectrumPolyNode()
[35aab3]97{
[9af8d18]98    if( mon!=NULL ) p_Delete( &mon, r );
99    if( nf !=NULL ) p_Delete( &nf,r );
[35aab3]100    copy_zero( );
101}
102
103// ------------------------
104//  class spectrumPolyList
105// ------------------------
106
107// ----------------------------------------------------------------------------
108//  Initialize a  spectrumPolyList  with zero
109// ----------------------------------------------------------------------------
110
111void    spectrumPolyList::copy_zero( void )
112{
113    root = (spectrumPolyNode*)NULL;
114    N    = 0;
115    np   = (newtonPolygon*)NULL;
116}
117
118// ----------------------------------------------------------------------------
119//  Inizialize a  spectrumPolyList  shallow from data
120// ----------------------------------------------------------------------------
121
122void    spectrumPolyList::copy_shallow(
123                spectrumPolyNode *node,int k,newtonPolygon *npolygon )
124{
125    root = node;
126    N    = k;
127    np   = npolygon;
128}
129
130// ----------------------------------------------------------------------------
131//  Inizialize a  spectrumPolyList  shallow from another  spectrumPolyList
132// ----------------------------------------------------------------------------
133
134void    spectrumPolyList::copy_shallow( spectrumPolyList &splist )
135{
136    copy_shallow( splist.root,splist.N,splist.np );
137}
138
139// ----------------------------------------------------------------------------
140//  Zero constructor for  spectrumPolyList
141// ----------------------------------------------------------------------------
142
143spectrumPolyList::spectrumPolyList( )
144{
145    copy_zero( );
146}
147
148// ----------------------------------------------------------------------------
149//  Data constructor for  spectrumPolyList
150// ----------------------------------------------------------------------------
151
152spectrumPolyList::spectrumPolyList( newtonPolygon *npolygon )
153{
154    copy_shallow( (spectrumPolyNode*)NULL,0,npolygon );
155}
156
157// ----------------------------------------------------------------------------
158//  Destuctor for  spectrumPolyList
159// ----------------------------------------------------------------------------
160
161spectrumPolyList::~spectrumPolyList( )
162{
163    spectrumPolyNode *node;
164
165    while( root!=(spectrumPolyNode*)NULL )
166    {
167        node = root->next;
168        delete root;
169        root = node;
170    }
171
172    copy_zero( );
173}
174
175// ----------------------------------------------------------------------------
176//  Insert a new node into a  spectrumPolyList  at position k
177//      If the list is sorted, then
178//      the new node ist inserted such that the list remains sorted.
179// ----------------------------------------------------------------------------
180
[9af8d18]181void    spectrumPolyList::insert_node( poly m,poly f, const ring R )
[35aab3]182{
183    #ifdef SPLIST_DEBUG
184        if( np==(newtonPolygon*)NULL )
185        {
186            #ifdef SPLIST_PRINT
187            #ifdef SPLIST_IOSTREAM
188                cerr << "void    spectrumPolyList::insert_node( poly f )" << endl;
189                cerr << "    no Newton polygon" << endl;
190                cerr << "    exiting..." << endl;
191            #else
192                fprintf( stderr,"void    spectrumPolyList::insert_node( poly f )\n" );
193                fprintf( stderr,"    no Newton polygon\n" );
194                fprintf( stderr,"    exiting...\n" );
195            #endif
196            #endif
197
198            exit( 1 );
199        }
200    #endif
201
202    spectrumPolyNode    *newnode = new spectrumPolyNode(
[9af8d18]203        (spectrumPolyNode*)NULL,m,np->weight_shift( m,R ),f, R );
[35aab3]204
205    if( N==0 ||
206              root->weight>newnode->weight ||
207            ( root->weight==newnode->weight &&
[9af8d18]208              p_Cmp( root->mon,newnode->mon,R )<0 ) )
[35aab3]209    {
210        // ----------------------
211        //  insert at position 0
212        // ----------------------
213
214        newnode->next = root;
215        root          = newnode;
216    }
217    else if( N==1 )
218    {
219        // ---------------
220        //  insert at end
221        // ---------------
222
223        root->next    = newnode;
224    }
225    else
226    {
227        // ----------------------------
228        //  insert according to weight
229        // ----------------------------
230
231        spectrumPolyNode *actual = root;
232        spectrumPolyNode *next   = root->next;
233
234        while( next!=(spectrumPolyNode*)NULL &&
235               ( newnode->weight>next->weight ||
236               ( newnode->weight==next->weight &&
[9af8d18]237                 p_Cmp( newnode->mon,next->mon, R )<0 ) ) )
[35aab3]238        {
239            actual = next;
240            next   = next->next;
241        }
242
243        actual->next = newnode;
244        newnode->next = next;
245    }
246    N++;
247}
248
249// ----------------------------------------------------------------------------
250//  Delete a node from a  spectrumPolyList
251// ----------------------------------------------------------------------------
252
253void    spectrumPolyList::delete_node( spectrumPolyNode **node )
254{
255    spectrumPolyNode *foo = *node;
256    *node = (*node)->next;
257    delete foo;
258    N--;
259}
260
261// ----------------------------------------------------------------------------
262//  Delete all nodes where   node->mon  is a multiple of  m
263//  In every node delete all instances of  m  in  node->nf
264// ----------------------------------------------------------------------------
265
[9af8d18]266void    spectrumPolyList::delete_monomial( poly m, const ring R )
[35aab3]267{
268    spectrumPolyNode **node = &root;
269    poly              *f;
270
[9af8d18]271    m = p_Copy( m,R );
[35aab3]272
273    while( *node!=(spectrumPolyNode*)NULL )
274    {
[9af8d18]275        if( p_Cmp( m,(*node)->mon,R )>=0 && p_LmDivisibleByNoComp( m,(*node)->mon, R ))
[35aab3]276        {
277            delete_node( node );
278        }
[ee3e1ae]279        else if( (*node)->nf!=NULL )
[35aab3]280        {
281            f = &((*node)->nf);
282
[ee3e1ae]283            while( *f!=NULL )
[35aab3]284            {
[9af8d18]285                if( p_Cmp( m,*f,R )>=0 && p_LmDivisibleByNoComp( m,*f,R ) )
[35aab3]286                {
[9af8d18]287                    p_LmDelete(f,R);
[35aab3]288                }
289                else
[ee3e1ae]290                {
[35aab3]291                    f = &(pNext( *f ));
292                }
293            }
294
[ee3e1ae]295            if( (*node)->nf==NULL )
[35aab3]296            {
297                delete_node( node );
298            }
299            else
300            {
301                node = &((*node)->next);
302            }
303        }
304        else
305        {
306            node = &((*node)->next);
307        }
308    }
[9af8d18]309    p_Delete( &m,R );
[35aab3]310}
311
312// ----------------------------------------------------------------------------
313//  Print a  spectrumPolyList
314// ----------------------------------------------------------------------------
315
316#ifdef SPLIST_PRINT
317ostream & operator << ( ostream &s,const spectrumPolyList &l )
318{
319    #ifdef SPLIST_IOSTREAM
320        s << "elements: " << l.N << endl;
321        s << "{";
322    #else
323        fprintf( stdout,"elements: %d\n",l.N );
324        fprintf( stdout,"{" );
325    #endif
326
327    if( l.root!=(spectrumPolyNode*)NULL )
328    {
329        #ifdef SPLIST_IOSTREAM
330            s << "(";
331            pWrite0( l.root->mon );
332            s << "=>";
333            pWrite0( l.root->nf );
334            cout << "," << l.root->weight << ")" << endl;
335        #else
336            fprintf( stdout,"(" );
337            pWrite0( l.root->mon );
338            fprintf( stdout,"=>" );
339            pWrite0( l.root->nf );
340            fprintf( stdout,"," );
341            cout << l.root->weight;
342            fprintf( stdout,")\n" );
343        #endif
344
345        spectrumPolyNode *node = l.root->next;
346
347        while( node!=(spectrumPolyNode*)NULL )
348        {
349            #ifdef SPLIST_IOSTREAM
350                s << ",(";
351                pWrite0( node->mon );
352                s << "=>";
353                pWrite0( node->nf );
354                cout << "," << node->weight << ")" << endl;
355            #else
356                fprintf( stdout,",(" );
357                pWrite0( node->mon );
358                fprintf( stdout,"=>" );
359                pWrite0( node->nf );
360                fprintf( stdout,"," );
361                cout << node->weight;
362                fprintf( stdout,")\n" );
363            #endif
364
365            node = node->next;
366        }
367    }
368    #ifdef SPLIST_IOSTREAM
369        s << "}";
370    #else
371        fprintf( stdout,"}" );
372    #endif
373
374    return  s;
375}
376#endif
377
378#endif /* HAVE_SPECTRUM */
379// ----------------------------------------------------------------------------
380//  splist.cc
381//  end of file
382// ----------------------------------------------------------------------------
383
Note: See TracBrowser for help on using the repository browser.