My Project
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
intvec Class Reference

#include <intvec.h>

Public Member Functions

 intvec (int l=1)
 
 intvec (int s, int e)
 
 intvec (int r, int c, int init)
 
 intvec (const intvec *iv)
 
void resize (int new_length)
 
int range (int i) const
 
int range (int i, int j) const
 
int & operator[] (int i)
 
const int & operator[] (int i) const
 
void operator+= (int intop)
 
void operator-= (int intop)
 
void operator*= (int intop)
 
void operator/= (int intop)
 
void operator%= (int intop)
 
int compare (const intvec *o) const
 
int compare (int o) const
 
int length () const
 
int cols () const
 
int rows () const
 
void show (int mat=0, int spaces=0) const
 
void view () const
 
void makeVector ()
 
char * String (int dim=2) const
 
char * ivString (int not_mat=1, int spaces=0, int dim=2) const
 
 ~intvec ()
 
void ivTEST () const
 
int min_in ()
 
int max_in ()
 
intvecdelete_pos (int p)
 
int * ivGetVec () const
 
- Public Member Functions inherited from omallocClass
void * operator new (size_t size) throw (std::bad_alloc)
 
void operator delete (void *block) throw ()
 
void * operator new[] (size_t size) throw (std::bad_alloc)
 
void operator delete[] (void *block) throw ()
 
void * operator new (size_t size, const std::nothrow_t &) throw ()
 
void * operator new[] (size_t size, const std::nothrow_t &) throw ()
 

Private Attributes

int * v
 
int row
 
int col
 

Detailed Description

Definition at line 19 of file intvec.h.

Constructor & Destructor Documentation

◆ intvec() [1/4]

intvec::intvec ( int  l = 1)
inline

Definition at line 30 of file intvec.h.

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 }
int l
Definition: cfEzgcd.cc:100
int col
Definition: intvec.h:27
int row
Definition: intvec.h:26
int * v
Definition: intvec.h:25
#define assume(x)
Definition: mod2.h:389
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:12

◆ intvec() [2/4]

intvec::intvec ( int  s,
int  e 
)

Definition at line 21 of file intvec.cc.

22{
23 int inc;
24 col = 1;
25 if (s<e)
26 {
27 row = e-s+1;
28 inc = 1;
29 }
30 else
31 {
32 row = s-e+1;
33 inc = -1;
34 }
35 v = (int *)omAlloc(sizeof(int)*row);
36 for (int i=0; i<row; i++)
37 {
38 v[i] = s;
39 s+=inc;
40 }
41}
int i
Definition: cfEzgcd.cc:132
const CanonicalForm int s
Definition: facAbsFact.cc:51
#define omAlloc(size)
Definition: omAllocDecl.h:210

◆ intvec() [3/4]

intvec::intvec ( int  r,
int  c,
int  init 
)

Definition at line 43 of file intvec.cc.

44{
45 row = r;
46 col = c;
47 int l = r*c;
48 if (l>0) /*(r>0) && (c>0) */
49 v = (int *)omAlloc(sizeof(int)*l);
50 else
51 v = NULL;
52 for (int i=0; i<l; i++)
53 {
54 v[i] = init;
55 }
56}
void init()
Definition: lintree.cc:864

◆ intvec() [4/4]

intvec::intvec ( const intvec iv)
inline

Definition at line 40 of file intvec.h.

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 }
int cols() const
Definition: intvec.h:95
int rows() const
Definition: intvec.h:96

◆ ~intvec()

intvec::~intvec ( )
inline

Definition at line 105 of file intvec.h.

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 }
void * ADDRESS
Definition: auxiliary.h:119
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260

Member Function Documentation

◆ cols()

int intvec::cols ( ) const
inline

Definition at line 95 of file intvec.h.

95{ return col; }

◆ compare() [1/2]

int intvec::compare ( const intvec o) const

Definition at line 206 of file intvec.cc.

207{
208 if ((col!=1) ||(op->cols()!=1))
209 {
210 if((col!=op->cols())
211 || (row!=op->rows()))
212 return -2;
213 }
214 int i;
215 for (i=0; i<si_min(length(),op->length()); i++)
216 {
217 if (v[i] > (*op)[i])
218 return 1;
219 if (v[i] < (*op)[i])
220 return -1;
221 }
222 // this can only happen for intvec: (i.e. col==1)
223 for (; i<row; i++)
224 {
225 if (v[i] > 0)
226 return 1;
227 if (v[i] < 0)
228 return -1;
229 }
230 for (; i<op->rows(); i++)
231 {
232 if (0 > (*op)[i])
233 return 1;
234 if (0 < (*op)[i])
235 return -1;
236 }
237 return 0;
238}
static int si_min(const int a, const int b)
Definition: auxiliary.h:125
int length() const
Definition: intvec.h:94

◆ compare() [2/2]

int intvec::compare ( int  o) const

Definition at line 239 of file intvec.cc.

240{
241 for (int i=0; i<row*col; i++)
242 {
243 if (v[i] <o) return -1;
244 if (v[i] >o) return 1;
245 }
246 return 0;
247}

◆ delete_pos()

intvec * intvec::delete_pos ( int  p)

Definition at line 842 of file intvec.cc.

843{
844 if (!range(p)) return NULL;
845 intvec *iv=new intvec(rows()-1);
846 for(int i=0;i<p;i++) (*iv)[i]=v[i];
847 for(int i=p+1;i<rows();i++) (*iv)[i-1]=v[i];
848 return iv;
849}
int p
Definition: cfModGcd.cc:4078
Definition: intvec.h:23
int range(int i) const
Definition: intvec.h:59

◆ ivGetVec()

int * intvec::ivGetVec ( ) const
inline

Definition at line 143 of file intvec.h.

143{ return v; }

◆ ivString()

char * intvec::ivString ( int  not_mat = 1,
int  spaces = 0,
int  dim = 2 
) const

Definition at line 58 of file intvec.cc.

59{
60 //Print("ivString:this=%x,v=%x,row=%d\n",this,v,row);
61#ifndef OM_NDEBUG
62 omCheckAddr((void *)this);
63 if (v!=NULL) omCheckAddr((void *)v);
64#endif
65 StringSetS("");
66 if ((col == 1)&&(not_mat))
67 {
68 int i=0;
69 for (; i<row-1; i++)
70 {
71 StringAppend("%d,",v[i]);
72 }
73 if (i<row)
74 {
75 StringAppend("%d",v[i]);
76 }
77 }
78 else
79 {
80 for (int j=0; j<row; j++)
81 {
82 if (j<row-1)
83 {
84 for (int i=0; i<col; i++)
85 {
86 StringAppend("%d%c",v[j*col+i],',');
87 }
88 }
89 else
90 {
91 for (int i=0; i<col; i++)
92 {
93 StringAppend("%d%c",v[j*col+i],i<col-1 ? ',' : ' ');
94 }
95 }
96 if (j+1<row)
97 {
98 if (dim > 1) StringAppendS("\n");
99 if (spaces>0) StringAppend("%-*.*s",spaces,spaces," ");
100 }
101 }
102 }
103 return StringEndS();
104}
#define StringAppend
Definition: emacs.cc:79
int j
Definition: facHensel.cc:110
#define omCheckAddr(addr)
Definition: omAllocDecl.h:328
void StringSetS(const char *st)
Definition: reporter.cc:128
void StringAppendS(const char *st)
Definition: reporter.cc:107
char * StringEndS()
Definition: reporter.cc:151
int dim(ideal I, ring r)

◆ ivTEST()

void intvec::ivTEST ( ) const
inline

Definition at line 115 of file intvec.h.

116 {
117 assume(row>=0);
118 assume(col>=0);
119 if (row>0) omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col);
120 }
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327

◆ length()

int intvec::length ( ) const
inline

Definition at line 94 of file intvec.h.

94{ return col*row; }

◆ makeVector()

void intvec::makeVector ( )
inline

Definition at line 102 of file intvec.h.

102{ row*=col;col=1; }

◆ max_in()

int intvec::max_in ( )
inline

Definition at line 131 of file intvec.h.

132 {
133 int m=0;
134 if (row>0)
135 {
136 m=v[0];
137 for (int i=row*col-1; i>0; i--) if (v[i]>m) m=v[i];
138 }
139 return m;
140 }
int m
Definition: cfEzgcd.cc:128

◆ min_in()

int intvec::min_in ( )
inline

Definition at line 121 of file intvec.h.

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 }

◆ operator%=()

void intvec::operator%= ( int  intop)

Definition at line 193 of file intvec.cc.

194{
195 if (intop == 0) return;
196 int bb=ABS(intop);
197 for (int i=0; i<row*col; i++)
198 {
199 int r=v[i];
200 int c=r%bb;
201 if (c<0) c+=bb;
202 v[i]=c;
203 }
204}
static int ABS(int v)
Definition: auxiliary.h:112

◆ operator*=()

void intvec::operator*= ( int  intop)

Definition at line 174 of file intvec.cc.

175{
176 for (int i=0; i<row*col; i++) { v[i] *= intop; }
177}

◆ operator+=()

void intvec::operator+= ( int  intop)

Definition at line 164 of file intvec.cc.

165{
166 for (int i=0; i<row*col; i++) { v[i] += intop; }
167}

◆ operator-=()

void intvec::operator-= ( int  intop)

Definition at line 169 of file intvec.cc.

170{
171 for (int i=0; i<row*col; i++) { v[i] -= intop; }
172}

◆ operator/=()

void intvec::operator/= ( int  intop)

Definition at line 179 of file intvec.cc.

180{
181 if (intop == 0) return;
182 int bb=ABS(intop);
183 for (int i=0; i<row*col; i++)
184 {
185 int r=v[i];
186 int c=r%bb;
187 if (c<0) c+=bb;
188 r=(r-c)/intop;
189 v[i]=r;
190 }
191}

◆ operator[]() [1/2]

int & intvec::operator[] ( int  i)
inline

Definition at line 65 of file intvec.h.

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 }
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ operator[]() [2/2]

const int & intvec::operator[] ( int  i) const
inline

Definition at line 75 of file intvec.h.

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 }

◆ range() [1/2]

int intvec::range ( int  i) const
inline

Definition at line 59 of file intvec.h.

61 { return ((((unsigned)i)<((unsigned)row)) && (col==1)); }

◆ range() [2/2]

int intvec::range ( int  i,
int  j 
) const
inline

Definition at line 62 of file intvec.h.

64 { return ((((unsigned)i)<((unsigned)row)) && (((unsigned)j)<((unsigned)col))); }

◆ resize()

void intvec::resize ( int  new_length)

Definition at line 106 of file intvec.cc.

107{
108 assume(new_length >= 0 && col == 1);
109 if (new_length==0)
110 {
111 if (v!=NULL)
112 {
113 omFreeSize(v, row*sizeof(int));
114 v=NULL;
115 }
116 }
117 else
118 {
119 if (v!=NULL)
120 v = (int*) omRealloc0Size(v, row*sizeof(int), new_length*sizeof(int));
121 else
122 v = (int*) omAlloc0(new_length*sizeof(int));
123 }
124 row = new_length;
125}
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221

◆ rows()

int intvec::rows ( ) const
inline

Definition at line 96 of file intvec.h.

96{ return row; }

◆ show()

void intvec::show ( int  mat = 0,
int  spaces = 0 
) const

Definition at line 149 of file intvec.cc.

150{
151 char *s=ivString(notmat,spaces);
152 if (spaces>0)
153 {
154 PrintNSpaces(spaces);
155 PrintS(s);
156 }
157 else
158 {
159 PrintS(s);
160 }
161 omFree(s);
162}
char * ivString(int not_mat=1, int spaces=0, int dim=2) const
Definition: intvec.cc:58
#define omFree(addr)
Definition: omAllocDecl.h:261
void PrintNSpaces(const int n)
Definition: reporter.cc:364
void PrintS(const char *s)
Definition: reporter.cc:284

◆ String()

char * intvec::String ( int  dim = 2) const

Definition at line 127 of file intvec.cc.

128{
129 return ivString(1, 0, dim);
130}

◆ view()

void intvec::view ( ) const

Definition at line 134 of file intvec.cc.

135{
136 Print ("intvec: {rows: %d, cols: %d, length: %d, Values: \n", rows(), cols(), length());
137
138 for (int i = 0; i < rows(); i++)
139 {
140 Print ("Row[%3d]:", i);
141 for (int j = 0; j < cols(); j++)
142 Print (" %5d", this->operator[]((i)*cols()+j) );
143 PrintLn ();
144 }
145 PrintS ("}\n");
146}
#define Print
Definition: emacs.cc:80
void PrintLn()
Definition: reporter.cc:310

Field Documentation

◆ col

int intvec::col
private

Definition at line 27 of file intvec.h.

◆ row

int intvec::row
private

Definition at line 26 of file intvec.h.

◆ v

int* intvec::v
private

Definition at line 25 of file intvec.h.


The documentation for this class was generated from the following files: