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