intvec.h
Go to the documentation of this file.
1 #ifndef INTVEC_H
2 #define INTVEC_H
3 /****************************************
4 * Computer Algebra System SINGULAR *
5 ****************************************/
6 /*
7 * ABSTRACT: class intvec: lists/vectors of integers
8 */
9 #include <string.h>
10 #include "misc/auxiliary.h"
11 #include "omalloc/omalloc.h"
12 #ifdef HAVE_OMALLOC
13 #include "omalloc/omallocClass.h"
14 #endif
15 
16 #include "reporter/reporter.h"
17 
18 
19 class intvec
20 #ifdef HAVE_OMALLOC
21  :public omallocClass
22 #endif
23 {
24 private:
25  int *v;
26  int row;
27  int col;
28 public:
29 
30  inline intvec(int l = 1)
31  {
32  assume(l >= 0);
33  if (l>0) v = (int *)omAlloc0(sizeof(int)*l);
34  else v = NULL;
35  row = l;
36  col = 1;
37  }
38  intvec(int s, int e);
39  intvec(int r, int c, int init);
40  intvec(const intvec* iv)
41  {
42  assume( iv != NULL );
43  row = iv->rows();
44  col = iv->cols();
45  assume(row >= 0);
46  assume(col >= 0);
47  if (row*col>0)
48  {
49  v = (int *)omAlloc(sizeof(int)*row*col);
50  for (int i=row*col-1;i>=0; i--)
51  {
52  v[i] = (*iv)[i];
53  }
54  }
55  else v=NULL;
56  }
57 
58  void resize(int new_length);
59  inline int range(int i) const
60  //{ return ((i<row) && (i>=0) && (col==1)); }
61  { return ((((unsigned)i)<((unsigned)row)) && (col==1)); }
62  inline int range(int i, int j) const
63  //{ return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
64  { return ((((unsigned)i)<((unsigned)row)) && (((unsigned)j)<((unsigned)col))); }
65  inline int& operator[](int i)
66  {
67 #ifndef SING_NDEBUG
68  if((i<0)||(i>=row*col))
69  {
70  Werror("wrong intvec index:%d\n",i);
71  }
72 #endif
73  return v[i];
74  }
75  inline const int& operator[](int i) const
76  {
77 #ifndef SING_NDEBUG
78  if((i<0)||(i>=row*col))
79  {
80  Werror("wrong intvec index:%d\n",i);
81  }
82 #endif
83  return v[i];
84  }
85 #define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
86  void operator+=(int intop);
87  void operator-=(int intop);
88  void operator*=(int intop);
89  void operator/=(int intop);
90  void operator%=(int intop);
91  // -2: not compatible, -1: <, 0:=, 1: >
92  int compare(const intvec* o) const;
93  int compare(int o) const;
94  inline int length() const { return col*row; }
95  inline int cols() const { return col; }
96  inline int rows() const { return row; }
97  void show(int mat=0,int spaces=0) const;
98  #ifndef SING_NDEBUG
99  void view() const;
100  #endif
101 
102  inline void makeVector() { row*=col;col=1; }
103  char * String(int dim = 2) const;
104  char * ivString(int not_mat=1,int spaces=0, int dim=2) const;
105  inline ~intvec()
106  {
107  assume(row>=0);
108  assume(col>=0);
109  if (v!=NULL)
110  {
111  omFreeSize((ADDRESS)v,sizeof(int)*row*col);
112  v=NULL;
113  }
114  }
115  inline void ivTEST() const
116  {
117  assume(row>=0);
118  assume(col>=0);
119  if (row>0) omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
120  }
121  inline int min_in()
122  {
123  int m=0;
124  if (row>0)
125  {
126  m=v[0];
127  for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
128  }
129  return m;
130  }
131  intvec* delete_pos(int p);
132  // keiner (ausser obachman) darf das folgenden benutzen !!!
133  inline int * ivGetVec() { return v; }
134 };
135 inline intvec * ivCopy(const intvec * o)
136 {
137  if( o != NULL )
138  return new intvec(o);
139  return NULL;
140 }
141 
142 intvec * ivAdd(intvec * a, intvec * b);
143 intvec * ivSub(intvec * a, intvec * b);
144 intvec * ivTranp(intvec * o);
145 int ivTrace(intvec * o);
146 intvec * ivMult(intvec * a, intvec * b);
147 //void ivTriangMat(intvec * imat);
148 void ivTriangIntern(intvec * imat, int &ready, int &all);
149 intvec * ivSolveKern(intvec * imat, int ready);
150 intvec * ivConcat(intvec * a, intvec * b);
151 
152 #ifdef MDEBUG
153 inline void ivTest(intvec * v)
154 {
155  v->ivTEST();
156 }
157 #else
158 #define ivTest(v) do {} while (0)
159 #endif
160 
161 #undef INLINE_THIS
162 
163 #endif
intvec * ivConcat(intvec *a, intvec *b)
Definition: intvec.cc:804
int compare(const intvec *o) const
Definition: intvec.cc:206
int range(int i, int j) const
Definition: intvec.h:62
void operator-=(int intop)
Definition: intvec.cc:169
const CanonicalForm int s
Definition: facAbsFact.cc:55
int ivTrace(intvec *o)
Definition: intvec.cc:321
int j
Definition: facHensel.cc:105
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327
void resize(int new_length)
Definition: intvec.cc:106
char * ivString(int not_mat=1, int spaces=0, int dim=2) const
Definition: intvec.cc:58
void view() const
Definition: intvec.cc:134
intvec * ivAdd(intvec *a, intvec *b)
Definition: intvec.cc:249
intvec(int l=1)
Definition: intvec.h:30
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
int rows() const
Definition: intvec.h:96
intvec * ivCopy(const intvec *o)
Definition: intvec.h:135
void operator/=(int intop)
Definition: intvec.cc:179
void * ADDRESS
Definition: auxiliary.h:135
int min_in()
Definition: intvec.h:121
void ivTriangIntern(intvec *imat, int &ready, int &all)
Definition: intvec.cc:386
intvec * ivSub(intvec *a, intvec *b)
Definition: intvec.cc:279
#define omAlloc(size)
Definition: omAllocDecl.h:210
void operator+=(int intop)
Definition: intvec.cc:164
#define ivTest(v)
Definition: intvec.h:158
int * v
Definition: intvec.h:25
CanonicalForm b
Definition: cfModGcd.cc:4044
int & operator[](int i)
Definition: intvec.h:65
int row
Definition: intvec.h:26
Definition: intvec.h:19
void operator%=(int intop)
Definition: intvec.cc:193
void ivTEST() const
Definition: intvec.h:115
#define assume(x)
Definition: mod2.h:390
void operator*=(int intop)
Definition: intvec.cc:174
const int & operator[](int i) const
Definition: intvec.h:75
void makeVector()
Definition: intvec.h:102
All the auxiliary stuff.
int m
Definition: cfEzgcd.cc:121
int dim(ideal I, ring r)
intvec(const intvec *iv)
Definition: intvec.h:40
int i
Definition: cfEzgcd.cc:125
int range(int i) const
Definition: intvec.h:59
char * String(int dim=2) const
Definition: intvec.cc:127
int * ivGetVec()
Definition: intvec.h:133
int col
Definition: intvec.h:27
intvec * ivTranp(intvec *o)
Definition: intvec.cc:309
#define NULL
Definition: omList.c:12
int length() const
Definition: intvec.h:94
intvec * ivSolveKern(intvec *imat, int ready)
Definition: intvec.cc:424
void show(int mat=0, int spaces=0) const
Definition: intvec.cc:149
int cols() const
Definition: intvec.h:95
intvec * ivMult(intvec *a, intvec *b)
Definition: intvec.cc:331
intvec * delete_pos(int p)
Definition: intvec.cc:824
int p
Definition: cfModGcd.cc:4019
~intvec()
Definition: intvec.h:105
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93