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