My Project
Loading...
Searching...
No Matches
multicnt.cc
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// multicnt.cc
3// begin of file
4// Stephan Endrass, [email protected]
5// 23.7.99
6// ----------------------------------------------------------------------------
7
8#define MULTICNT_CC
9
10
11
12
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
27
28// ----------------------------------------------------------------------------
29// allocate counter memory
30// ----------------------------------------------------------------------------
31
32void multiCnt::copy_new( int n )
33{
34 if( n > 0 )
35 {
36 cnt = new int[n];
37
38 #ifndef SING_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
82{
83 if( N>0 && cnt!=(int*)NULL ) delete [] cnt;
84 copy_zero( );
85}
86
87// ----------------------------------------------------------------------------
88// copy a counter
89// ----------------------------------------------------------------------------
90
92{
93 copy_new( C.N );
94
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
108void 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
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
130multiCnt::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
142multiCnt::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
154void multiCnt::inc( void )
155{
156 cnt[0]++;
157 last_inc=0;
158}
159
160// ----------------------------------------------------------------------------
161// decrement the counter
162// ----------------------------------------------------------------------------
163
164/*
165void multiCnt::dec( void )
166{
167 cnt[0]--;
168 last_inc=0;
169}
170*/
171
172// ----------------------------------------------------------------------------
173// increment the counter and carry over
174// ----------------------------------------------------------------------------
175
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/*
188void 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
200int 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/*
224int 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// ----------------------------------------------------------------------------
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int i
Definition: cfEzgcd.cc:132
void copy_zero(void)
Definition: multicnt.h:51
void copy_new(int)
Definition: multicnt.cc:32
int * cnt
Definition: multicnt.h:21
void set(int)
Definition: multicnt.cc:108
void copy_deep(const multiCnt &)
Definition: multicnt.cc:91
int last_inc
Definition: multicnt.h:23
void inc_carry(void)
Definition: multicnt.cc:176
void copy_delete(void)
Definition: multicnt.cc:81
multiCnt()
Definition: multicnt.h:73
void inc(void)
Definition: multicnt.cc:154
int N
Definition: multicnt.h:22
#define NULL
Definition: omList.c:12