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/omalloc.h>
11 #include <reporter/reporter.h>
12 
13 
14 //extern omBin intvec_bin;
15 
16 class intvec
17 {
18 private:
19  int *v;
20  int row;
21  int col;
22 public:
23 
24  inline intvec(int l = 1)
25  {
26  assume(l >= 0);
27  if (l>0) v = (int *)omAlloc0(sizeof(int)*l);
28  else v = NULL;
29  row = l;
30  col = 1;
31  }
32  intvec(int s, int e);
33  intvec(int r, int c, int init);
34  intvec(const intvec* iv)
35  {
36  assume( iv != NULL );
37  row = iv->rows();
38  col = iv->cols();
39  assume(row >= 0);
40  assume(col >= 0);
41  if (row*col>0)
42  {
43  v = (int *)omAlloc(sizeof(int)*row*col);
44  for (int i=row*col-1;i>=0; i--)
45  {
46  v[i] = (*iv)[i];
47  }
48  }
49  else v=NULL;
50  }
51 
52  void resize(int new_length);
53  inline int range(int i) const
54  { return ((i<row) && (i>=0) && (col==1)); }
55  inline int range(int i, int j) const
56  { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
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  inline void length(int l) { row = l; col = 1; }
90  void show(int mat=0,int spaces=0) const;
91  #ifndef SING_NDEBUG
92  void view() const;
93  #endif
94 
95  inline void makeVector() { row*=col;col=1; }
96  char * String(int dim = 2) const;
97  char * ivString(int not_mat=1,int spaces=0, int dim=2) const;
98  inline ~intvec()
99  {
100  assume(row>=0);
101  assume(col>=0);
102  if (v!=NULL)
103  {
104  omFreeSize((ADDRESS)v,sizeof(int)*row*col);
105  v=NULL;
106  }
107  }
108  inline void ivTEST() const
109  {
110  assume(row>=0);
111  assume(col>=0);
112  if (row>0) omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
113  }
114  inline int min_in()
115  {
116  int m=0;
117  if (row>0)
118  {
119  m=v[0];
120  for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
121  }
122  return m;
123  }
124 #if 0
125  // TODO: no omalloc Bin (de-)/allocation?
126  void* operator new ( size_t size )
127  {
128  void* addr;
129  //omTypeAlloc(void*, addr, size);
130  addr=omAlloc0Bin(intvec_bin);
131  return addr;
132  }
133  void operator delete ( void* block )
134  { //omfree( block );
135  omFreeBin((ADDRESS)block, intvec_bin);
136  }
137 #endif
138  // keiner (ausser obachman) darf das folgenden benutzen !!!
139  inline int * ivGetVec() { return v; }
140 };
141 inline intvec * ivCopy(const intvec * o)
142 {
143  if( o != NULL )
144  return new intvec(o);
145 
146  return NULL;
147 }
148 
149 intvec * ivAdd(intvec * a, intvec * b);
150 intvec * ivSub(intvec * a, intvec * b);
151 intvec * ivTranp(intvec * o);
152 int ivTrace(intvec * o);
153 intvec * ivMult(intvec * a, intvec * b);
154 //void ivTriangMat(intvec * imat);
155 void ivTriangIntern(intvec * imat, int &ready, int &all);
156 intvec * ivSolveKern(intvec * imat, int ready);
157 intvec * ivConcat(intvec * a, intvec * b);
158 
159 #ifdef MDEBUG
160 inline void ivTest(intvec * v)
161 {
162  v->ivTEST();
163 }
164 #else
165 #define ivTest(v) do {} while (0)
166 #endif
167 
168 #undef INLINE_THIS
169 
170 #endif
intvec * ivConcat(intvec *a, intvec *b)
Definition: intvec.cc:831
void ivTEST() const
Definition: intvec.h:108
void operator-=(int intop)
Definition: intvec.cc:188
void length(int l)
Definition: intvec.h:89
const CanonicalForm int s
Definition: facAbsFact.cc:55
int ivTrace(intvec *o)
Definition: intvec.cc:348
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327
void resize(int new_length)
Definition: intvec.cc:125
const poly a
Definition: syzextra.cc:212
#define block
Definition: scanner.cc:662
int range(int i, int j) const
Definition: intvec.h:55
intvec * ivAdd(intvec *a, intvec *b)
Definition: intvec.cc:276
intvec(int l=1)
Definition: intvec.h:24
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
intvec * ivCopy(const intvec *o)
Definition: intvec.h:141
void operator/=(int intop)
Definition: intvec.cc:198
int length() const
Definition: intvec.h:86
void * ADDRESS
Definition: auxiliary.h:161
int min_in()
Definition: intvec.h:114
void ivTriangIntern(intvec *imat, int &ready, int &all)
Definition: intvec.cc:413
intvec * ivSub(intvec *a, intvec *b)
Definition: intvec.cc:306
#define omAlloc(size)
Definition: omAllocDecl.h:210
void operator+=(int intop)
Definition: intvec.cc:183
#define ivTest(v)
Definition: intvec.h:165
char * String(int dim=2) const
Definition: intvec.cc:146
int * v
Definition: intvec.h:19
const ring r
Definition: syzextra.cc:208
int & operator[](int i)
Definition: intvec.h:57
int row
Definition: intvec.h:20
Definition: intvec.h:16
void operator%=(int intop)
Definition: intvec.cc:212
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:405
void operator*=(int intop)
Definition: intvec.cc:193
int compare(const intvec *o) const
Definition: intvec.cc:225
void makeVector()
Definition: intvec.h:95
int m
Definition: cfEzgcd.cc:119
const int & operator[](int i) const
Definition: intvec.h:67
int dim(ideal I, ring r)
intvec(const intvec *iv)
Definition: intvec.h:34
int i
Definition: cfEzgcd.cc:123
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
int * ivGetVec()
Definition: intvec.h:139
int col
Definition: intvec.h:21
int range(int i) const
Definition: intvec.h:53
intvec * ivTranp(intvec *o)
Definition: intvec.cc:336
#define NULL
Definition: omList.c:10
int cols() const
Definition: intvec.h:87
char * ivString(int not_mat=1, int spaces=0, int dim=2) const
Definition: intvec.cc:77
int rows() const
Definition: intvec.h:88
intvec * ivSolveKern(intvec *imat, int ready)
Definition: intvec.cc:451
intvec * ivMult(intvec *a, intvec *b)
Definition: intvec.cc:358
void show(int mat=0, int spaces=0) const
Definition: intvec.cc:168
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
const poly b
Definition: syzextra.cc:213
~intvec()
Definition: intvec.h:98
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
void view() const
Definition: intvec.cc:153