1 | #ifndef INTVEC_H |
---|
2 | #define INTVEC_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: intvec.h,v 1.6 2007-02-16 10:52:22 motsak 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(intvec* iv) |
---|
34 | { |
---|
35 | row = iv->rows(); |
---|
36 | col = iv->cols(); |
---|
37 | v = (int *)omAlloc(sizeof(int)*row*col); |
---|
38 | for (int i=row*col-1;i>=0; i--) |
---|
39 | { |
---|
40 | v[i] = (*iv)[i]; |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | void resize(int new_length); |
---|
45 | inline int range(int i) const |
---|
46 | { return ((i<row) && (i>=0) && (col==1)); } |
---|
47 | inline int range(int i, int j) const |
---|
48 | { return ((i<row) && (i>=0) && (j<col) && (j>=0)); } |
---|
49 | inline int& operator[](int i) |
---|
50 | { |
---|
51 | #ifndef NDEBUG |
---|
52 | if((i<0)||(i>=row*col)) |
---|
53 | { |
---|
54 | Werror("wrong intvec index:%d\n",i); |
---|
55 | } |
---|
56 | #endif |
---|
57 | return v[i]; |
---|
58 | } |
---|
59 | inline const int& operator[](int i) const |
---|
60 | { |
---|
61 | #ifndef NDEBUG |
---|
62 | if((i<0)||(i>=row*col)) |
---|
63 | { |
---|
64 | Werror("wrong intvec index:%d\n",i); |
---|
65 | } |
---|
66 | #endif |
---|
67 | return v[i]; |
---|
68 | } |
---|
69 | #define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1] |
---|
70 | void operator+=(int intop); |
---|
71 | void operator-=(int intop); |
---|
72 | void operator*=(int intop); |
---|
73 | void operator/=(int intop); |
---|
74 | void operator%=(int intop); |
---|
75 | // -2: not compatible, -1: <, 0:=, 1: > |
---|
76 | int compare(intvec* o); |
---|
77 | int compare(int o); |
---|
78 | inline int length() const { return col*row; } |
---|
79 | inline int cols() const { return col; } |
---|
80 | inline int rows() const { return row; } |
---|
81 | inline void length(int l) { row = l; col = 1; } |
---|
82 | void show(int mat=0,int spaces=0); |
---|
83 | inline void makeVector() { row*=col;col=1; } |
---|
84 | char * String(int dim = 2); |
---|
85 | char * ivString(int not_mat=1,int spaces=0, int dim=2); |
---|
86 | inline ~intvec() |
---|
87 | { |
---|
88 | if (v!=NULL) |
---|
89 | { |
---|
90 | omFreeSize((ADDRESS)v,sizeof(int)*row*col); |
---|
91 | v=NULL; |
---|
92 | } |
---|
93 | } |
---|
94 | inline void ivTEST() |
---|
95 | { |
---|
96 | omCheckAddrSize((ADDRESS)v,sizeof(int)*row*col); |
---|
97 | } |
---|
98 | inline int min_in() |
---|
99 | { |
---|
100 | int m=v[0]; |
---|
101 | for (int i=row*col-1; i>0; i--) if (v[i]<m) m=v[i]; |
---|
102 | return m; |
---|
103 | } |
---|
104 | #if 0 |
---|
105 | void* operator new ( size_t size ) |
---|
106 | { |
---|
107 | void* addr; |
---|
108 | //omTypeAlloc(void*, addr, size); |
---|
109 | addr=omAlloc0Bin(intvec_bin); |
---|
110 | return addr; |
---|
111 | } |
---|
112 | void operator delete ( void* block ) |
---|
113 | { //omfree( block ); |
---|
114 | omFreeBin((ADDRESS)block, intvec_bin); |
---|
115 | } |
---|
116 | #endif |
---|
117 | // keiner (ausser obachman) darf das folgenden benutzen !!! |
---|
118 | inline int * ivGetVec() { return v; } |
---|
119 | }; |
---|
120 | inline intvec * ivCopy(intvec * o) |
---|
121 | { |
---|
122 | intvec * iv=new intvec(o); |
---|
123 | return iv; |
---|
124 | } |
---|
125 | |
---|
126 | intvec * ivAdd(intvec * a, intvec * b); |
---|
127 | intvec * ivSub(intvec * a, intvec * b); |
---|
128 | intvec * ivTranp(intvec * o); |
---|
129 | int ivTrace(intvec * o); |
---|
130 | intvec * ivMult(intvec * a, intvec * b); |
---|
131 | //void ivTriangMat(intvec * imat); |
---|
132 | void ivTriangIntern(intvec * imat, int &ready, int &all); |
---|
133 | intvec * ivSolveKern(intvec * imat, int ready); |
---|
134 | |
---|
135 | |
---|
136 | #ifdef MDEBUG |
---|
137 | #define ivTest(v) v->ivTEST() |
---|
138 | #else |
---|
139 | #define ivTest(v) ((void)0) |
---|
140 | #endif |
---|
141 | #undef INLINE_THIS |
---|
142 | |
---|
143 | #endif |
---|