1 | #ifndef INTVEC_H |
---|
2 | #define INTVEC_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: intvec.h,v 1.9 2009-10-23 09:58:49 Singular Exp $ */ |
---|
7 | /* |
---|
8 | * ABSTRACT: class intvec: lists/vectors of integers |
---|
9 | */ |
---|
10 | #include <string.h> |
---|
11 | #include "omalloc.h" |
---|
12 | #include "febase.h" |
---|
13 | |
---|
14 | |
---|
15 | //extern omBin intvec_bin; |
---|
16 | |
---|
17 | class intvec |
---|
18 | { |
---|
19 | private: |
---|
20 | int *v; |
---|
21 | int row; |
---|
22 | int col; |
---|
23 | public: |
---|
24 | |
---|
25 | inline intvec(int l = 1) |
---|
26 | { |
---|
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 | if (row*col>0) |
---|
39 | { |
---|
40 | v = (int *)omAlloc(sizeof(int)*row*col); |
---|
41 | for (int i=row*col-1;i>=0; i--) |
---|
42 | { |
---|
43 | v[i] = (*iv)[i]; |
---|
44 | } |
---|
45 | } |
---|
46 | else v=NULL; |
---|
47 | } |
---|
48 | |
---|
49 | void resize(int new_length); |
---|
50 | inline int range(int i) const |
---|
51 | { return ((i<row) && (i>=0) && (col==1)); } |
---|
52 | inline int range(int i, int j) const |
---|
53 | { return ((i<row) && (i>=0) && (j<col) && (j>=0)); } |
---|
54 | inline int& operator[](int i) |
---|
55 | { |
---|
56 | #ifndef NDEBUG |
---|
57 | if((i<0)||(i>=row*col)) |
---|
58 | { |
---|
59 | Werror("wrong intvec index:%d\n",i); |
---|
60 | } |
---|
61 | #endif |
---|
62 | return v[i]; |
---|
63 | } |
---|
64 | inline const int& operator[](int i) const |
---|
65 | { |
---|
66 | #ifndef NDEBUG |
---|
67 | if((i<0)||(i>=row*col)) |
---|
68 | { |
---|
69 | Werror("wrong intvec index:%d\n",i); |
---|
70 | } |
---|
71 | #endif |
---|
72 | return v[i]; |
---|
73 | } |
---|
74 | #define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1] |
---|
75 | void operator+=(int intop); |
---|
76 | void operator-=(int intop); |
---|
77 | void operator*=(int intop); |
---|
78 | void operator/=(int intop); |
---|
79 | void operator%=(int intop); |
---|
80 | // -2: not compatible, -1: <, 0:=, 1: > |
---|
81 | int compare(intvec* o); |
---|
82 | int compare(int o); |
---|
83 | inline int length() const { return col*row; } |
---|
84 | inline int cols() const { return col; } |
---|
85 | inline int rows() const { return row; } |
---|
86 | inline void length(int l) { row = l; col = 1; } |
---|
87 | void show(int mat=0,int spaces=0) const; |
---|
88 | inline void makeVector() { row*=col;col=1; } |
---|
89 | char * String(int dim = 2) const; |
---|
90 | char * ivString(int not_mat=1,int spaces=0, int dim=2) const; |
---|
91 | inline ~intvec() |
---|
92 | { |
---|
93 | if (v!=NULL) |
---|
94 | { |
---|
95 | omFreeSize((ADDRESS)v,sizeof(int)*row*col); |
---|
96 | v=NULL; |
---|
97 | } |
---|
98 | } |
---|
99 | inline void ivTEST() |
---|
100 | { |
---|
101 | omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col); |
---|
102 | } |
---|
103 | inline int min_in() |
---|
104 | { |
---|
105 | int m=v[0]; |
---|
106 | for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i]; |
---|
107 | return m; |
---|
108 | } |
---|
109 | #if 0 |
---|
110 | void* operator new ( size_t size ) |
---|
111 | { |
---|
112 | void* addr; |
---|
113 | //omTypeAlloc(void*, addr, size); |
---|
114 | addr=omAlloc0Bin(intvec_bin); |
---|
115 | return addr; |
---|
116 | } |
---|
117 | void operator delete ( void* block ) |
---|
118 | { //omfree( block ); |
---|
119 | omFreeBin((ADDRESS)block, intvec_bin); |
---|
120 | } |
---|
121 | #endif |
---|
122 | // keiner (ausser obachman) darf das folgenden benutzen !!! |
---|
123 | inline int * ivGetVec() { return v; } |
---|
124 | }; |
---|
125 | inline intvec * ivCopy(const intvec * o) |
---|
126 | { |
---|
127 | if( o != NULL ) |
---|
128 | return new intvec(o); |
---|
129 | |
---|
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 | |
---|
142 | |
---|
143 | #ifdef MDEBUG |
---|
144 | #define ivTest(v) v->ivTEST() |
---|
145 | #else |
---|
146 | #define ivTest(v) ((void)0) |
---|
147 | #endif |
---|
148 | #undef INLINE_THIS |
---|
149 | |
---|
150 | #endif |
---|