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);
intvec(const intvec * iv)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);
range(int i)59   inline int range(int i) const
60     //{ return ((i<row) && (i>=0) && (col==1)); }
61     { return ((((unsigned)i)<((unsigned)row)) && (col==1)); }
range(int i,int j)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;
length()94   inline int  length() const { return col*row; }
cols()95   inline int  cols() const { return col; }
rows()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 
makeVector()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;
~intvec()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     }
ivTEST()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     }
min_in()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 !!!
ivGetVec()133   inline int * ivGetVec() { return v; }
134 };
ivCopy(const intvec * o)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
ivTest(intvec * v)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
164