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  v = (int *)omAlloc0(sizeof(int)*l);
28  row = l;
29  col = 1;
30  }
31  intvec(int s, int e);
32  intvec(int r, int c, int init);
33  intvec(const intvec* iv)
34  {
35  assume( iv != NULL );
36  row = iv->rows();
37  col = iv->cols();
38  assume(row > 0);
39  assume(col > 0);
40  if (row*col>0)
41  {
42  v = (int *)omAlloc(sizeof(int)*row*col);
43  for (int i=row*col-1;i>=0; i--)
44  {
45  v[i] = (*iv)[i];
46  }
47  }
48  else v=NULL;
49  }
50 
51  void resize(int new_length);
52  inline int range(int i) const
53  { return ((i<row) && (i>=0) && (col==1)); }
54  inline int range(int i, int j) const
55  { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
56  inline int& operator[](int i)
57  {
58 #ifndef SING_NDEBUG
59  if((i<0)||(i>=row*col))
60  {
61  Werror("wrong intvec index:%d\n",i);
62  }
63 #endif
64  return v[i];
65  }
66  inline const int& operator[](int i) const
67  {
68 #ifndef SING_NDEBUG
69  if((i<0)||(i>=row*col))
70  {
71  Werror("wrong intvec index:%d\n",i);
72  }
73 #endif
74  return v[i];
75  }
76 #define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
77  void operator+=(int intop);
78  void operator-=(int intop);
79  void operator*=(int intop);
80  void operator/=(int intop);
81  void operator%=(int intop);
82  // -2: not compatible, -1: <, 0:=, 1: >
83  int compare(const intvec* o) const;
84  int compare(int o) const;
85  inline int length() const { return col*row; }
86  inline int cols() const { return col; }
87  inline int rows() const { return row; }
88  inline void length(int l) { row = l; col = 1; }
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  if (v!=NULL)
100  {
101  omFreeSize((ADDRESS)v,sizeof(int)*row*col);
102  v=NULL;
103  }
104  }
105  inline void ivTEST() const
106  {
107  omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
108  }
109  inline int min_in()
110  {
111  int m=v[0];
112  for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i];
113  return m;
114  }
115 #if 0
116  // TODO: no omalloc Bin (de-)/allocation?
117  void* operator new ( size_t size )
118  {
119  void* addr;
120  //omTypeAlloc(void*, addr, size);
121  addr=omAlloc0Bin(intvec_bin);
122  return addr;
123  }
124  void operator delete ( void* block )
125  { //omfree( block );
126  omFreeBin((ADDRESS)block, intvec_bin);
127  }
128 #endif
129  // keiner (ausser obachman) darf das folgenden benutzen !!!
130  inline int * ivGetVec() { return v; }
131 };
132 inline intvec * ivCopy(const intvec * o)
133 {
134  if( o != NULL )
135  return new intvec(o);
136 
137  return NULL;
138 }
139 
140 intvec * ivAdd(intvec * a, intvec * b);
141 intvec * ivSub(intvec * a, intvec * b);
142 intvec * ivTranp(intvec * o);
143 int ivTrace(intvec * o);
144 intvec * ivMult(intvec * a, intvec * b);
145 //void ivTriangMat(intvec * imat);
146 void ivTriangIntern(intvec * imat, int &ready, int &all);
147 intvec * ivSolveKern(intvec * imat, int ready);
148 intvec * ivConcat(intvec * a, intvec * b);
149 
150 #ifdef MDEBUG
151 inline void ivTest(intvec * v)
152 {
153  v->ivTEST();
154 }
155 #else
156 #define ivTest(v) do {} while (0)
157 #endif
158 
159 #undef INLINE_THIS
160 
161 #endif
intvec * ivConcat(intvec *a, intvec *b)
Definition: intvec.cc:817
void ivTEST() const
Definition: intvec.h:105
void operator-=(int intop)
Definition: intvec.cc:174
void length(int l)
Definition: intvec.h:88
const CanonicalForm int s
Definition: facAbsFact.cc:55
int ivTrace(intvec *o)
Definition: intvec.cc:334
#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:54
intvec * ivAdd(intvec *a, intvec *b)
Definition: intvec.cc:262
intvec(int l=1)
Definition: intvec.h:24
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
intvec * ivCopy(const intvec *o)
Definition: intvec.h:132
void operator/=(int intop)
Definition: intvec.cc:184
int length() const
Definition: intvec.h:85
void * ADDRESS
Definition: auxiliary.h:161
int min_in()
Definition: intvec.h:109
void ivTriangIntern(intvec *imat, int &ready, int &all)
Definition: intvec.cc:399
intvec * ivSub(intvec *a, intvec *b)
Definition: intvec.cc:292
#define omAlloc(size)
Definition: omAllocDecl.h:210
void operator+=(int intop)
Definition: intvec.cc:169
#define ivTest(v)
Definition: intvec.h:156
char * String(int dim=2) const
Definition: intvec.cc:132
int * v
Definition: intvec.h:19
const ring r
Definition: syzextra.cc:208
int & operator[](int i)
Definition: intvec.h:56
int row
Definition: intvec.h:20
Definition: intvec.h:16
void operator%=(int intop)
Definition: intvec.cc:198
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:405
void operator*=(int intop)
Definition: intvec.cc:179
int compare(const intvec *o) const
Definition: intvec.cc:211
void makeVector()
Definition: intvec.h:94
int m
Definition: cfEzgcd.cc:119
const int & operator[](int i) const
Definition: intvec.h:66
int dim(ideal I, ring r)
intvec(const intvec *iv)
Definition: intvec.h:33
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:130
int col
Definition: intvec.h:21
int range(int i) const
Definition: intvec.h:52
intvec * ivTranp(intvec *o)
Definition: intvec.cc:322
#define NULL
Definition: omList.c:10
int cols() const
Definition: intvec.h:86
char * ivString(int not_mat=1, int spaces=0, int dim=2) const
Definition: intvec.cc:77
int rows() const
Definition: intvec.h:87
intvec * ivSolveKern(intvec *imat, int ready)
Definition: intvec.cc:437
intvec * ivMult(intvec *a, intvec *b)
Definition: intvec.cc:344
void show(int mat=0, int spaces=0) const
Definition: intvec.cc:154
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
const poly b
Definition: syzextra.cc:213
~intvec()
Definition: intvec.h:97
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:139