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