1 | // ---------------------------------------------------------------------------- |
---|
2 | // multicnt.cc |
---|
3 | // begin of file |
---|
4 | // Stephan Endrass, endrass@mathematik.uni-mainz.de |
---|
5 | // 23.7.99 |
---|
6 | // ---------------------------------------------------------------------------- |
---|
7 | |
---|
8 | #define MULTICNT_CC |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "singularconfig.h" |
---|
12 | #endif /* HAVE_CONFIG_H */ |
---|
13 | #include <kernel/mod2.h> |
---|
14 | |
---|
15 | #ifdef HAVE_SPECTRUM |
---|
16 | |
---|
17 | #include <stdlib.h> |
---|
18 | |
---|
19 | #ifdef MULTICNT_PRINT |
---|
20 | #include <iostream.h> |
---|
21 | #ifndef MULTICNT_IOSTREAM |
---|
22 | #include <stdio.h> |
---|
23 | #endif |
---|
24 | #endif |
---|
25 | |
---|
26 | #include <kernel/multicnt.h> |
---|
27 | |
---|
28 | // ---------------------------------------------------------------------------- |
---|
29 | // allocate counter memory |
---|
30 | // ---------------------------------------------------------------------------- |
---|
31 | |
---|
32 | void multiCnt::copy_new( int n ) |
---|
33 | { |
---|
34 | if( n > 0 ) |
---|
35 | { |
---|
36 | cnt = new int[n]; |
---|
37 | |
---|
38 | #ifndef NDEBUG |
---|
39 | if( cnt == (int*)NULL ) |
---|
40 | { |
---|
41 | #ifdef MULTICNT_PRINT |
---|
42 | #ifdef MULTICNT_IOSTREAM |
---|
43 | cerr << "multiCnt::copy_new(" << n << ")" << endl; |
---|
44 | cerr << " returned ZERO!!!" << endl; |
---|
45 | cerr << " exit..." << endl; |
---|
46 | #else |
---|
47 | fprintf( stderr,"multiCnt::copy_new( %d )\n",n ); |
---|
48 | fprintf( stderr," returned ZERO!!!\n" ); |
---|
49 | fprintf( stderr," exit...\n" ); |
---|
50 | #endif |
---|
51 | #endif |
---|
52 | |
---|
53 | exit( 1 ); |
---|
54 | } |
---|
55 | #endif |
---|
56 | } |
---|
57 | else if( n == 0 ) |
---|
58 | { |
---|
59 | cnt = (int*)NULL; |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | #ifdef MULTICNT_PRINT |
---|
64 | #ifdef MULTICNT_IOSTREAM |
---|
65 | cerr << "multiCnt::copy_new(" << n << ")" << endl; |
---|
66 | cerr << " exit..." << endl; |
---|
67 | #else |
---|
68 | fprintf( stderr,"multiCnt::copy_new( %d )\n",n ); |
---|
69 | fprintf( stderr," exit...\n" ); |
---|
70 | #endif |
---|
71 | #endif |
---|
72 | |
---|
73 | exit( 1 ); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | // ---------------------------------------------------------------------------- |
---|
78 | // delete counter memory |
---|
79 | // ---------------------------------------------------------------------------- |
---|
80 | |
---|
81 | void multiCnt::copy_delete( void ) |
---|
82 | { |
---|
83 | if( N>0 && cnt!=(int*)NULL ) delete [] cnt; |
---|
84 | copy_zero( ); |
---|
85 | } |
---|
86 | |
---|
87 | // ---------------------------------------------------------------------------- |
---|
88 | // copy a counter |
---|
89 | // ---------------------------------------------------------------------------- |
---|
90 | |
---|
91 | void multiCnt::copy_deep( const multiCnt &C ) |
---|
92 | { |
---|
93 | copy_new( C.N ); |
---|
94 | |
---|
95 | last_inc = C.last_inc; |
---|
96 | N = C.N; |
---|
97 | |
---|
98 | for( int i=0; i<N; i++ ) |
---|
99 | { |
---|
100 | cnt[i] = C.cnt[i]; |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | // ---------------------------------------------------------------------------- |
---|
105 | // set all counter entries to c |
---|
106 | // ---------------------------------------------------------------------------- |
---|
107 | |
---|
108 | void multiCnt::set( int c ) |
---|
109 | { |
---|
110 | for( int i=0; i<N; i++ ) cnt[i]=c; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | // ---------------------------------------------------------------------------- |
---|
115 | // n entries zero init constructor |
---|
116 | // ---------------------------------------------------------------------------- |
---|
117 | |
---|
118 | multiCnt::multiCnt( int n ) : |
---|
119 | last_inc( 0 ) |
---|
120 | { |
---|
121 | copy_new( n ); |
---|
122 | N = n; |
---|
123 | set( 0 ); |
---|
124 | } |
---|
125 | |
---|
126 | // ---------------------------------------------------------------------------- |
---|
127 | // n entries c init constructor |
---|
128 | // ---------------------------------------------------------------------------- |
---|
129 | |
---|
130 | multiCnt::multiCnt( int n,int c ) : |
---|
131 | last_inc( 0 ) |
---|
132 | { |
---|
133 | copy_new( n ); |
---|
134 | N = n; |
---|
135 | set( c ); |
---|
136 | } |
---|
137 | |
---|
138 | // ---------------------------------------------------------------------------- |
---|
139 | // n entries c* init constructor |
---|
140 | // ---------------------------------------------------------------------------- |
---|
141 | |
---|
142 | multiCnt::multiCnt( int n,int *c ) : |
---|
143 | last_inc( 0 ) |
---|
144 | { |
---|
145 | copy_new( n ); |
---|
146 | N = n; |
---|
147 | for( int i=0; i<N; i++ ) cnt[i] = c[i]; |
---|
148 | } |
---|
149 | |
---|
150 | // ---------------------------------------------------------------------------- |
---|
151 | // increment the counter |
---|
152 | // ---------------------------------------------------------------------------- |
---|
153 | |
---|
154 | void multiCnt::inc( void ) |
---|
155 | { |
---|
156 | cnt[0]++; |
---|
157 | last_inc=0; |
---|
158 | } |
---|
159 | |
---|
160 | // ---------------------------------------------------------------------------- |
---|
161 | // decrement the counter |
---|
162 | // ---------------------------------------------------------------------------- |
---|
163 | |
---|
164 | /* |
---|
165 | void multiCnt::dec( void ) |
---|
166 | { |
---|
167 | cnt[0]--; |
---|
168 | last_inc=0; |
---|
169 | } |
---|
170 | */ |
---|
171 | |
---|
172 | // ---------------------------------------------------------------------------- |
---|
173 | // increment the counter and carry over |
---|
174 | // ---------------------------------------------------------------------------- |
---|
175 | |
---|
176 | void multiCnt::inc_carry( void ) |
---|
177 | { |
---|
178 | for( int i=0; i<=last_inc; i++ ) cnt[i] = 0; |
---|
179 | last_inc++; |
---|
180 | cnt[last_inc]++; |
---|
181 | } |
---|
182 | |
---|
183 | // ---------------------------------------------------------------------------- |
---|
184 | // decrement the counter and carry over |
---|
185 | // ---------------------------------------------------------------------------- |
---|
186 | |
---|
187 | /* |
---|
188 | void multiCnt::dec_carry( void ) |
---|
189 | { |
---|
190 | for( int i=0; i<=last_inc; i++ ) cnt[i] = 0; |
---|
191 | last_inc++; |
---|
192 | cnt[last_inc]--; |
---|
193 | } |
---|
194 | */ |
---|
195 | |
---|
196 | // ---------------------------------------------------------------------------- |
---|
197 | // increment the counter and carry over automatic |
---|
198 | // ---------------------------------------------------------------------------- |
---|
199 | |
---|
200 | int multiCnt::inc( int carry ) |
---|
201 | { |
---|
202 | if( carry==FALSE ) |
---|
203 | { |
---|
204 | inc( ); |
---|
205 | } |
---|
206 | else |
---|
207 | { |
---|
208 | if( last_inc==N-1 ) |
---|
209 | { |
---|
210 | return FALSE; |
---|
211 | } |
---|
212 | |
---|
213 | inc_carry( ); |
---|
214 | } |
---|
215 | |
---|
216 | return TRUE; |
---|
217 | } |
---|
218 | |
---|
219 | // ---------------------------------------------------------------------------- |
---|
220 | // decrement the counter and carry over automatic |
---|
221 | // ---------------------------------------------------------------------------- |
---|
222 | |
---|
223 | /* |
---|
224 | int multiCnt::dec( int carry ) |
---|
225 | { |
---|
226 | if( carry==FALSE ) |
---|
227 | { |
---|
228 | dec( ); |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | if( last_inc==N-1 ) |
---|
233 | { |
---|
234 | return FALSE; |
---|
235 | } |
---|
236 | |
---|
237 | dec_carry( ); |
---|
238 | } |
---|
239 | |
---|
240 | return TRUE; |
---|
241 | } |
---|
242 | */ |
---|
243 | |
---|
244 | #endif /* HAVE_SPECTRUM */ |
---|
245 | // ---------------------------------------------------------------------------- |
---|
246 | // multicnt.cc |
---|
247 | // end of file |
---|
248 | // ---------------------------------------------------------------------------- |
---|