1 /**CFile***********************************************************************
3 FileName [cuddZddCount.c]
7 Synopsis [Procedures to count the number of minterms of a ZDD.]
9 Description [External procedures included in this module:
12 <li> Cudd_zddCountDouble();
14 Internal procedures included in this module:
17 Static procedures included in this module:
19 <li> cuddZddCountStep();
20 <li> cuddZddCountDoubleStep();
21 <li> st_zdd_count_dbl_free()
22 <li> st_zdd_countfree()
28 Author [Hyong-Kyoon Shin, In-Ho Moon]
30 Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
34 Redistribution and use in source and binary forms, with or without
35 modification, are permitted provided that the following conditions
38 Redistributions of source code must retain the above copyright
39 notice, this list of conditions and the following disclaimer.
41 Redistributions in binary form must reproduce the above copyright
42 notice, this list of conditions and the following disclaimer in the
43 documentation and/or other materials provided with the distribution.
45 Neither the name of the University of Colorado nor the names of its
46 contributors may be used to endorse or promote products derived from
47 this software without specific prior written permission.
49 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
52 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
53 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
56 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
59 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60 POSSIBILITY OF SUCH DAMAGE.]
62 ******************************************************************************/
67 /*---------------------------------------------------------------------------*/
68 /* Constant declarations */
69 /*---------------------------------------------------------------------------*/
72 /*---------------------------------------------------------------------------*/
73 /* Stucture declarations */
74 /*---------------------------------------------------------------------------*/
77 /*---------------------------------------------------------------------------*/
78 /* Type declarations */
79 /*---------------------------------------------------------------------------*/
82 /*---------------------------------------------------------------------------*/
83 /* Variable declarations */
84 /*---------------------------------------------------------------------------*/
87 static char rcsid
[] DD_UNUSED
= "$Id: cuddZddCount.c,v 1.14 2004/08/13 18:04:53 fabio Exp $";
90 /*---------------------------------------------------------------------------*/
91 /* Macro declarations */
92 /*---------------------------------------------------------------------------*/
98 /**AutomaticStart*************************************************************/
100 /*---------------------------------------------------------------------------*/
101 /* Static function prototypes */
102 /*---------------------------------------------------------------------------*/
104 static int cuddZddCountStep (DdNode
*P
, st_table
*table
, DdNode
*base
, DdNode
*empty
);
105 static double cuddZddCountDoubleStep (DdNode
*P
, st_table
*table
, DdNode
*base
, DdNode
*empty
);
106 static enum st_retval
st_zdd_countfree (char *key
, char *value
, char *arg
);
107 static enum st_retval
st_zdd_count_dbl_free (char *key
, char *value
, char *arg
);
109 /**AutomaticEnd***************************************************************/
115 /*---------------------------------------------------------------------------*/
116 /* Definition of exported functions */
117 /*---------------------------------------------------------------------------*/
120 /**Function********************************************************************
122 Synopsis [Counts the number of minterms in a ZDD.]
124 Description [Returns an integer representing the number of minterms
129 SeeAlso [Cudd_zddCountDouble]
131 ******************************************************************************/
139 DdNode
*base
, *empty
;
142 empty
= DD_ZERO(zdd
);
143 table
= st_init_table(st_ptrcmp
, st_ptrhash
);
144 if (table
== NULL
) return(CUDD_OUT_OF_MEM
);
145 res
= cuddZddCountStep(P
, table
, base
, empty
);
146 if (res
== CUDD_OUT_OF_MEM
) {
147 zdd
->errorCode
= CUDD_MEMORY_OUT
;
149 st_foreach(table
, st_zdd_countfree
, NIL(char));
150 st_free_table(table
);
154 } /* end of Cudd_zddCount */
157 /**Function********************************************************************
159 Synopsis [Counts the number of minterms of a ZDD.]
161 Description [Counts the number of minterms of a ZDD. The result is
162 returned as a double. If the procedure runs out of memory, it
163 returns (double) CUDD_OUT_OF_MEM. This procedure is used in
164 Cudd_zddCountMinterm.]
168 SeeAlso [Cudd_zddCountMinterm Cudd_zddCount]
170 ******************************************************************************/
178 DdNode
*base
, *empty
;
181 empty
= DD_ZERO(zdd
);
182 table
= st_init_table(st_ptrcmp
, st_ptrhash
);
183 if (table
== NULL
) return((double)CUDD_OUT_OF_MEM
);
184 res
= cuddZddCountDoubleStep(P
, table
, base
, empty
);
185 if (res
== (double)CUDD_OUT_OF_MEM
) {
186 zdd
->errorCode
= CUDD_MEMORY_OUT
;
188 st_foreach(table
, st_zdd_count_dbl_free
, NIL(char));
189 st_free_table(table
);
193 } /* end of Cudd_zddCountDouble */
196 /*---------------------------------------------------------------------------*/
197 /* Definition of internal functions */
198 /*---------------------------------------------------------------------------*/
201 /*---------------------------------------------------------------------------*/
202 /* Definition of static functions */
203 /*---------------------------------------------------------------------------*/
206 /**Function********************************************************************
208 Synopsis [Performs the recursive step of Cudd_zddCount.]
216 ******************************************************************************/
233 if (st_lookup(table
, P
, &dummy
)) {
238 res
= cuddZddCountStep(cuddE(P
), table
, base
, empty
) +
239 cuddZddCountStep(cuddT(P
), table
, base
, empty
);
241 dummy
= ALLOC(int, 1);
243 return(CUDD_OUT_OF_MEM
);
246 if (st_insert(table
, (char *)P
, (char *)dummy
) == ST_OUT_OF_MEM
) {
248 return(CUDD_OUT_OF_MEM
);
253 } /* end of cuddZddCountStep */
256 /**Function********************************************************************
258 Synopsis [Performs the recursive step of Cudd_zddCountDouble.]
266 ******************************************************************************/
268 cuddZddCountDoubleStep(
283 if (st_lookup(table
, P
, &dummy
)) {
288 res
= cuddZddCountDoubleStep(cuddE(P
), table
, base
, empty
) +
289 cuddZddCountDoubleStep(cuddT(P
), table
, base
, empty
);
291 dummy
= ALLOC(double, 1);
293 return((double)CUDD_OUT_OF_MEM
);
296 if (st_insert(table
, (char *)P
, (char *)dummy
) == ST_OUT_OF_MEM
) {
298 return((double)CUDD_OUT_OF_MEM
);
303 } /* end of cuddZddCountDoubleStep */
306 /**Function********************************************************************
308 Synopsis [Frees the memory associated with the computed table of
317 ******************************************************************************/
318 static enum st_retval
330 } /* end of st_zdd_countfree */
333 /**Function********************************************************************
335 Synopsis [Frees the memory associated with the computed table of
336 Cudd_zddCountDouble.]
344 ******************************************************************************/
345 static enum st_retval
346 st_zdd_count_dbl_free(
357 } /* end of st_zdd_count_dbl_free */