source: git/Singular/lists.cc @ f6b5f0

spielwiese
Last change on this file since f6b5f0 was f6b5f0, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: change Log: and Header: to Id: git-svn-id: file:///usr/local/Singular/svn/trunk@73 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT: handling of the list type
6*/
7/* $Id: lists.cc,v 1.2 1997-03-24 14:25:11 Singular Exp $ */
8#include "mod2.h"
9#include "tok.h"
10#include "febase.h"
11#include "ipid.h"
12#include "polys.h"
13#include "ideals.h"
14#include "attrib.h"
15#include "lists.h"
16
17lists lCopy(lists L)
18{
19  lists N=(lists)Alloc0(sizeof(slists));
20  int n=L->nr;
21  if (L->nr>=0)
22    N->Init(n+1);
23  else
24    N->Init();
25  for(;n>=0;n--)
26  {
27    N->m[n].Copy(&L->m[n]);
28  }
29  //Print("copy list with %d -> %d elems\n",L->nr,N->nr);
30  return N;
31}
32
33/*2
34* concat 2 lists
35*/
36BOOLEAN lAdd(leftv res, leftv u, leftv v)
37{
38  lists l=(lists) Alloc(sizeof(slists));
39  lists ul=(lists)u->CopyD();
40  lists vl=(lists)v->CopyD();
41  l->Init(ul->nr+vl->nr+2);
42  int i;
43
44  for(i=0;i<=ul->nr;i++)
45  {
46    //Print("u[%d]->r[%d]\n",i,i);
47    l->m[i].rtyp=ul->m[i].rtyp;
48    l->m[i].data=ul->m[i].data;
49  }
50  for(i=0;i<=vl->nr;i++)
51  {
52    //Print("v[%d]->r[%d]\n",i,i+ul->nr+1);
53    l->m[i+ul->nr+1].rtyp=vl->m[i].rtyp;
54    l->m[i+ul->nr+1].data=vl->m[i].data;
55  }
56  Free((ADDRESS)ul->m,(ul->nr+1)*sizeof(sleftv));
57  Free((ADDRESS)ul,sizeof(slists));
58  Free((ADDRESS)vl->m,(vl->nr+1)*sizeof(sleftv));
59  Free((ADDRESS)vl,sizeof(slists));
60  memset(u,0,sizeof(*u));
61  memset(v,0,sizeof(*v));
62  res->data = (char *)l;
63  //res->Print();
64  return FALSE;
65}
66
67/*2
68* insert v into list u, destroys u
69*/
70lists lInsert0(lists ul, leftv v, int pos)
71{
72  lists l=(lists) Alloc(sizeof(slists));
73  if (pos<0) return NULL;
74  l->Init(max(ul->nr+2,pos+1));
75  int i,j;
76
77  for(i=j=0;i<=ul->nr;i++,j++)
78  {
79    if(j==pos) j++;
80    l->m[j].Copy(&ul->m[i]);
81  }
82  for(j=ul->nr+1;j<pos;j++)
83    l->m[j].rtyp=DEF_CMD;
84  memset(&(l->m[pos]),0,sizeof(sleftv));
85  l->m[pos].rtyp=v->Typ();
86  l->m[pos].data=v->CopyD();
87  l->m[pos].flag=v->flag;
88  l->m[pos].attribute=v->CopyA();
89  Free((ADDRESS)ul->m,(ul->nr+1)*sizeof(sleftv));
90  Free((ADDRESS)ul,sizeof(slists));
91  return l;
92}
93
94/*2
95* insert v into list u, at the beginning
96*/
97BOOLEAN lInsert(leftv res, leftv u, leftv v)
98{
99  lists ul=(lists)u->CopyD();
100  res->data=(char *)lInsert0(ul,v,0);
101  return FALSE;
102}
103
104/*2
105* insert v into list u at pos w
106*/
107BOOLEAN lInsert3(leftv res, leftv u, leftv v, leftv w)
108{
109  lists ul=(lists)u->CopyD();
110  res->data=(char *)lInsert0(ul,v,(int)w->Data());
111  return FALSE;
112}
113
114/*2
115* append v to list u
116*/
117BOOLEAN lAppend(leftv res, leftv u, leftv v)
118{
119  lists ul=(lists)u->CopyD();
120  res->data=(char *)lInsert0(ul,v,ul->nr+1);
121  return FALSE;
122}
123
124/*2
125* delete v-th element from list u
126*/
127BOOLEAN lDelete(leftv res, leftv u, leftv v)
128{
129  lists ul=(lists)u->Data();
130  int VIndex=(int)v->Data()-1;
131
132  if((0<=VIndex)&&(VIndex<=ul->nr))
133  {
134    int i,j;
135    lists l=(lists) Alloc(sizeof(slists));
136    l->Init(ul->nr);
137
138    ul=(lists)u->CopyD();
139    for(i=j=0;i<=ul->nr;i++,j++)
140    {
141      if (i!=VIndex)
142      {
143        l->m[j].Copy(&(ul->m[i]));
144      }
145      else
146      {
147        j--;
148        ul->m[i].CleanUp();
149      }
150    }
151    Free((ADDRESS)ul->m,(ul->nr+1)*sizeof(sleftv));
152    Free((ADDRESS)ul,sizeof(slists));
153    res->data = (char *)l;
154    return FALSE;
155  }
156  Werror("wrong index %d in list(%d)",VIndex+1,ul->nr+1);
157  return TRUE;
158}
159
160/*2
161* check, if a list contains any ring dependend data
162*/
163BOOLEAN lRingDependend(lists L)
164{
165  if (L==NULL) return TRUE;
166  int i=0;
167  while (i<=L->nr)
168  {
169    if ((L->m[i].rtyp!=QRING_CMD)
170    && (BEGIN_RING<L->m[i].rtyp)
171    && (L->m[i].rtyp<END_RING))
172      return TRUE;
173    if ((L->m[i].rtyp==LIST_CMD)&&lRingDependend((lists)L->m[i].data))
174      return TRUE;
175    i++;
176  }
177  return FALSE;
178}
179
180lists liMakeResolv(resolvente r, int length, int reallen,
181  int typ0, intvec ** weights)
182{
183  lists L=(lists)Alloc0(sizeof(slists));
184  int oldlength=length;
185  while (r[length-1]==NULL) length--;
186  if (reallen<=0) reallen=pVariables;
187  reallen=max(reallen,length);
188  L->Init(reallen);
189  int i=0;
190
191  while (i<length)
192  {
193    if (r[i]!=NULL)
194    {
195      if (i==0)
196      {
197        L->m[i].rtyp=typ0;
198      }
199      else
200      {
201        L->m[i].rtyp=MODUL_CMD;
202        int rank=IDELEMS(r[i-1]);
203        if (idIs0(r[i-1]))
204        {
205          idDelete(&(r[i]));
206          r[i]=idFreeModule(rank);
207        }
208        else
209        {
210          r[i]->rank=max(rank,idRankFreeModule(r[i]));
211        }
212        idSkipZeroes(r[i]);
213      }
214      L->m[i].data=(void *)r[i];
215      if ((weights!=NULL) && (weights[i]!=NULL))
216      {
217        atSet((idhdl)&L->m[i],mstrdup("isHomog"),weights[i],INTVEC_CMD);
218        weights[i] = NULL;
219      }
220    }
221    else
222    {
223      // should not happen:
224      Warn("internal NULL in resolvente");
225      L->m[i].data=(void *)idInit(1,1);
226    }
227    i++;
228  }
229  Free((ADDRESS)r,oldlength*sizeof(ideal));
230  if (i==0)
231  {
232    L->m[0].rtyp=typ0;
233    L->m[0].data=(char *)idInit(1,1);
234    i=1;
235  }
236  while (i<reallen)
237  {
238    L->m[i].rtyp=MODUL_CMD;
239    ideal I=(ideal)L->m[i-1].data;
240    ideal J;
241    int rank=IDELEMS(I);
242    if (idIs0(I))
243    {
244      J=idFreeModule(rank);
245    }
246    else
247    {
248      J=idInit(1,rank);
249    }
250    L->m[i].data=(void *)J;
251    i++;
252  }
253  //Print("make res of length %d (0..%d) L:%d\n",length,length-1,L->nr);
254  return L;
255}
256
257resolvente liFindRes(lists L, int * len, int *typ0)
258{
259  resolvente r;
260
261  *len=L->nr+1;
262  if (*len<=0)
263  {
264    WerrorS("empty list");
265    return NULL;
266  }
267  r=(ideal *)Alloc0((*len)*sizeof(ideal));
268  int i=0;
269  *typ0=MODUL_CMD;
270  while (i<(*len))
271  {
272    if (L->m[i].rtyp != MODUL_CMD)
273    {
274      if (L->m[i].rtyp!=IDEAL_CMD)
275      {
276        Werror("element %d is not of type module",i+1);
277        Free((ADDRESS)r,(*len)*sizeof(ideal));
278        return NULL;
279      }
280      *typ0=IDEAL_CMD;
281    }
282    if ((i>0) && (idIs0(r[i-1])))
283    {
284      //*len=i-1;
285      break;
286    }
287    r[i]=(ideal)L->m[i].data;
288    i++;
289  }
290  //Print("find res of length %d (0..%d) L:%d\n",*len,(*len)-1,L->nr);
291  return r;
292}
293
Note: See TracBrowser for help on using the repository browser.