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 <omalloc/omallocClass.h>
11 #include <reporter/reporter.h>
12 
13 
14 class intvec :public omallocClass
15 {
16 private:
17  int *v;
18  int row;
19  int col;
20 public:
21 
22  inline intvec(int l = 1)
23  {
24  assume(l >= 0);
25  if (l>0) v = (int *)omAlloc0(sizeof(int)*l);
26  else v = NULL;
27  row = l;
28  col = 1;
29  }
30  intvec(int s, int e);
31  intvec(int r, int c, int init);
32  intvec(const intvec* iv)
33  {
34  assume( iv != NULL );
35  row = iv->rows();
36  col = iv->cols();
37  assume(row >= 0);
38  assume(col >= 0);
39  if (row*col>0)
40  {
41  v = (int *)omAlloc(sizeof(int)*row*col);
42  for (int i=row*col-1;i>=0; i--)
43  {
44  v[i] = (*iv)[i];
45  }
46  }
47  else v=NULL;
48  }
49 
50  void resize(int new_length);
51  inline int range(int i) const
52  //{ return ((i<row) && (i>=0) && (col==1)); }
53  { return ((((unsigned)i)<((unsigned)row)) && (col==1)); }
54  inline int range(int i, int j) const
55  //{ return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
56  { return ((((unsigned)i)<((unsigned)row)) && (((unsigned)j)<((unsigned)col))); }
57  inline int& operator[](int i)
58  {
59 #ifndef SING_NDEBUG
60  if((i<0)||(i>=row*col))
61  {
62  Werror("wrong intvec index:%d\n",i);
63  }
64 #endif
65  return v[i];
66  }
67  inline const int& operator[](int i) const
68  {
69 #ifndef SING_NDEBUG
70  if((i<0)||(i>=row*col))
71  {
72  Werror("wrong intvec index:%d\n",i);
73  }
74 #endif
75  return v[i];
76  }
77 #define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
78  void operator+=(int intop);
79  void operator-=(int intop);
80  void operator*=(int intop);
81  void operator/=(int intop);
82  void operator%=(int intop);
83  // -2: not compatible, -1: <, 0:=, 1: >
84  int compare(const intvec* o) const;
85  int compare(int o) const;
86  inline int length() const { return col*row; }
87  inline int cols() const { return col; }
88  inline int rows() const { return row; }
89  void show(int mat=0,int spaces=0) const;
90  #ifndef SING_NDEBUG
91  void view() const;
92  #endif
93 
94  inline void makeVector() { row*=col;col=1; }
95  char * String(int dim = 2) const;
96  char * ivString(int not_mat=1,int spaces=0, int dim=2) const;
97  inline ~intvec()
98  {
99  assume(row>=0);
100  assume(col>=0);
101  if (v!=NULL)
102  {
103  omFreeSize((ADDRESS)v,sizeof(int)*row*col);
104  v=NULL;
105  }
106  }
107  inline void ivTEST() const
108  {
109  assume(row>=0);
110  assume(col>=0);
111  if (row>0) omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
112  }
113  inline int min_in()
114  {
115  int m=0;
116  if (row>0)
117  {
118  m=v[0];
119  for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
120  }
121  return m;
122  }
123  // keiner (ausser obachman) darf das folgenden benutzen !!!
124  inline int * ivGetVec() { return v; }
125 };
126 inline intvec * ivCopy(const intvec * o)
127 {
128  if( o != NULL )
129  return new intvec(o);
130  return NULL;
131 }
132 
133 intvec * ivAdd(intvec * a, intvec * b);
134 intvec * ivSub(intvec * a, intvec * b);
135 intvec * ivTranp(intvec * o);
136 int ivTrace(intvec * o);
137 intvec * ivMult(intvec * a, intvec * b);
138 //void ivTriangMat(intvec * imat);
139 void ivTriangIntern(intvec * imat, int &ready, int &all);
140 intvec * ivSolveKern(intvec * imat, int ready);
141 intvec * ivConcat(intvec * a, intvec * b);
142 
143 #ifdef MDEBUG
144 inline void ivTest(intvec * v)
145 {
146  v->ivTEST();
147 }
148 #else
149 #define ivTest(v) do {} while (0)
150 #endif
151 
152 #undef INLINE_THIS
153 
154 #endif
intvec * ivConcat(intvec *a, intvec *b)
Definition: intvec.cc:805
int compare(const intvec *o) const
Definition: intvec.cc:207
int range(int i, int j) const
Definition: intvec.h:54
void operator-=(int intop)
Definition: intvec.cc:170
const CanonicalForm int s
Definition: facAbsFact.cc:55
int ivTrace(intvec *o)
Definition: intvec.cc:322
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327
void resize(int new_length)
Definition: intvec.cc:107
const poly a
Definition: syzextra.cc:212
char * ivString(int not_mat=1, int spaces=0, int dim=2) const
Definition: intvec.cc:59
void view() const
Definition: intvec.cc:135
intvec * ivAdd(intvec *a, intvec *b)
Definition: intvec.cc:250
intvec(int l=1)
Definition: intvec.h:22
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
int rows() const
Definition: intvec.h:88
intvec * ivCopy(const intvec *o)
Definition: intvec.h:126
void operator/=(int intop)
Definition: intvec.cc:180
void * ADDRESS
Definition: auxiliary.h:116
int min_in()
Definition: intvec.h:113
void ivTriangIntern(intvec *imat, int &ready, int &all)
Definition: intvec.cc:387
intvec * ivSub(intvec *a, intvec *b)
Definition: intvec.cc:280
#define omAlloc(size)
Definition: omAllocDecl.h:210
void operator+=(int intop)
Definition: intvec.cc:165
#define ivTest(v)
Definition: intvec.h:149
int * v
Definition: intvec.h:17
const ring r
Definition: syzextra.cc:208
int & operator[](int i)
Definition: intvec.h:57
int row
Definition: intvec.h:18
Definition: intvec.h:14
void operator%=(int intop)
Definition: intvec.cc:194
int j
Definition: myNF.cc:70
void ivTEST() const
Definition: intvec.h:107
#define assume(x)
Definition: mod2.h:403
void operator*=(int intop)
Definition: intvec.cc:175
const int & operator[](int i) const
Definition: intvec.h:67
void makeVector()
Definition: intvec.h:94
int m
Definition: cfEzgcd.cc:119
int dim(ideal I, ring r)
intvec(const intvec *iv)
Definition: intvec.h:32
int i
Definition: cfEzgcd.cc:123
int range(int i) const
Definition: intvec.h:51
char * String(int dim=2) const
Definition: intvec.cc:128
int * ivGetVec()
Definition: intvec.h:124
int col
Definition: intvec.h:19
intvec * ivTranp(intvec *o)
Definition: intvec.cc:310
#define NULL
Definition: omList.c:10
int length() const
Definition: intvec.h:86
intvec * ivSolveKern(intvec *imat, int ready)
Definition: intvec.cc:425
void show(int mat=0, int spaces=0) const
Definition: intvec.cc:150
int cols() const
Definition: intvec.h:87
intvec * ivMult(intvec *a, intvec *b)
Definition: intvec.cc:332
const poly b
Definition: syzextra.cc:213
~intvec()
Definition: intvec.h:97
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94