abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cuddZddCount.c File Reference
#include "misc/util/util_hack.h"
#include "cuddInt.h"

Go to the source code of this file.

Functions

static int cuddZddCountStep (DdNode *P, st__table *table, DdNode *base, DdNode *empty)
 
static double cuddZddCountDoubleStep (DdNode *P, st__table *table, DdNode *base, DdNode *empty)
 
static enum st__retval st__zdd_countfree (char *key, char *value, char *arg)
 
static enum st__retval st__zdd_count_dbl_free (char *key, char *value, char *arg)
 
int Cudd_zddCount (DdManager *zdd, DdNode *P)
 
double Cudd_zddCountDouble (DdManager *zdd, DdNode *P)
 

Variables

static
ABC_NAMESPACE_IMPL_START char
rcsid[] 
DD_UNUSED = "$Id: cuddZddCount.c,v 1.14 2004/08/13 18:04:53 fabio Exp $"
 

Function Documentation

int Cudd_zddCount ( DdManager zdd,
DdNode P 
)

AutomaticEnd Function********************************************************************

Synopsis [Counts the number of minterms in a ZDD.]

Description [Returns an integer representing the number of minterms in a ZDD.]

SideEffects [None]

SeeAlso [Cudd_zddCountDouble]

Definition at line 137 of file cuddZddCount.c.

140 {
141  st__table *table;
142  int res;
143  DdNode *base, *empty;
144 
145  base = DD_ONE(zdd);
146  empty = DD_ZERO(zdd);
148  if (table == NULL) return(CUDD_OUT_OF_MEM);
149  res = cuddZddCountStep(P, table, base, empty);
150  if (res == CUDD_OUT_OF_MEM) {
151  zdd->errorCode = CUDD_MEMORY_OUT;
152  }
153  st__foreach(table, st__zdd_countfree, NIL(char));
154  st__free_table(table);
155 
156  return(res);
157 
158 } /* end of Cudd_zddCount */
void st__free_table(st__table *table)
Definition: st.c:81
#define CUDD_OUT_OF_MEM
Definition: cudd.h:95
Definition: cudd.h:278
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
static enum st__retval st__zdd_countfree(char *key, char *value, char *arg)
Definition: cuddZddCount.c:323
static int cuddZddCountStep(DdNode *P, st__table *table, DdNode *base, DdNode *empty)
Definition: cuddZddCount.c:222
#define NIL(type)
Definition: avl.h:25
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
Definition: st.h:52
int st__foreach(st__table *table, enum st__retval(*func)(char *, char *, char *), char *arg)
Definition: st.c:421
static DdNode * empty
Definition: cuddZddLin.c:98
#define DD_ONE(dd)
Definition: cuddInt.h:911
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
int st__ptrhash(const char *, int)
Definition: st.c:468
#define DD_ZERO(dd)
Definition: cuddInt.h:927
double Cudd_zddCountDouble ( DdManager zdd,
DdNode P 
)

Function********************************************************************

Synopsis [Counts the number of minterms of a ZDD.]

Description [Counts the number of minterms of a ZDD. The result is returned as a double. If the procedure runs out of memory, it returns (double) CUDD_OUT_OF_MEM. This procedure is used in Cudd_zddCountMinterm.]

SideEffects [None]

SeeAlso [Cudd_zddCountMinterm Cudd_zddCount]

Definition at line 176 of file cuddZddCount.c.

179 {
180  st__table *table;
181  double res;
182  DdNode *base, *empty;
183 
184  base = DD_ONE(zdd);
185  empty = DD_ZERO(zdd);
187  if (table == NULL) return((double)CUDD_OUT_OF_MEM);
188  res = cuddZddCountDoubleStep(P, table, base, empty);
189  if (res == (double)CUDD_OUT_OF_MEM) {
190  zdd->errorCode = CUDD_MEMORY_OUT;
191  }
192  st__foreach(table, st__zdd_count_dbl_free, NIL(char));
193  st__free_table(table);
194 
195  return(res);
196 
197 } /* end of Cudd_zddCountDouble */
void st__free_table(st__table *table)
Definition: st.c:81
#define CUDD_OUT_OF_MEM
Definition: cudd.h:95
Definition: cudd.h:278
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
#define NIL(type)
Definition: avl.h:25
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
Definition: st.h:52
int st__foreach(st__table *table, enum st__retval(*func)(char *, char *, char *), char *arg)
Definition: st.c:421
static DdNode * empty
Definition: cuddZddLin.c:98
#define DD_ONE(dd)
Definition: cuddInt.h:911
static double cuddZddCountDoubleStep(DdNode *P, st__table *table, DdNode *base, DdNode *empty)
Definition: cuddZddCount.c:272
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
int st__ptrhash(const char *, int)
Definition: st.c:468
static enum st__retval st__zdd_count_dbl_free(char *key, char *value, char *arg)
Definition: cuddZddCount.c:350
#define DD_ZERO(dd)
Definition: cuddInt.h:927
static double cuddZddCountDoubleStep ( DdNode P,
st__table table,
DdNode base,
DdNode empty 
)
static

Function********************************************************************

Synopsis [Performs the recursive step of Cudd_zddCountDouble.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 272 of file cuddZddCount.c.

277 {
278  double res;
279  double *dummy;
280 
281  if (P == empty)
282  return((double)0.0);
283  if (P == base)
284  return((double)1.0);
285 
286  /* Check cache */
287  if ( st__lookup(table, (const char *)P, (char **)&dummy)) {
288  res = *dummy;
289  return(res);
290  }
291 
292  res = cuddZddCountDoubleStep(cuddE(P), table, base, empty) +
293  cuddZddCountDoubleStep(cuddT(P), table, base, empty);
294 
295  dummy = ABC_ALLOC(double, 1);
296  if (dummy == NULL) {
297  return((double)CUDD_OUT_OF_MEM);
298  }
299  *dummy = res;
300  if ( st__insert(table, (char *)P, (char *)dummy) == st__OUT_OF_MEM) {
301  ABC_FREE(dummy);
302  return((double)CUDD_OUT_OF_MEM);
303  }
304 
305  return(res);
306 
307 } /* end of cuddZddCountDoubleStep */
#define CUDD_OUT_OF_MEM
Definition: cudd.h:95
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define cuddT(node)
Definition: cuddInt.h:636
#define st__OUT_OF_MEM
Definition: st.h:113
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define cuddE(node)
Definition: cuddInt.h:652
static double cuddZddCountDoubleStep(DdNode *P, st__table *table, DdNode *base, DdNode *empty)
Definition: cuddZddCount.c:272
static int cuddZddCountStep ( DdNode P,
st__table table,
DdNode base,
DdNode empty 
)
static

AutomaticStart

Function********************************************************************

Synopsis [Performs the recursive step of Cudd_zddCount.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 222 of file cuddZddCount.c.

227 {
228  int res;
229  int *dummy;
230 
231  if (P == empty)
232  return(0);
233  if (P == base)
234  return(1);
235 
236  /* Check cache. */
237  if ( st__lookup(table, (const char *)P, (char **)&dummy)) {
238  res = *dummy;
239  return(res);
240  }
241 
242  res = cuddZddCountStep(cuddE(P), table, base, empty) +
243  cuddZddCountStep(cuddT(P), table, base, empty);
244 
245  dummy = ABC_ALLOC(int, 1);
246  if (dummy == NULL) {
247  return(CUDD_OUT_OF_MEM);
248  }
249  *dummy = res;
250  if ( st__insert(table, (char *)P, (char *)dummy) == st__OUT_OF_MEM) {
251  ABC_FREE(dummy);
252  return(CUDD_OUT_OF_MEM);
253  }
254 
255  return(res);
256 
257 } /* end of cuddZddCountStep */
#define CUDD_OUT_OF_MEM
Definition: cudd.h:95
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int cuddZddCountStep(DdNode *P, st__table *table, DdNode *base, DdNode *empty)
Definition: cuddZddCount.c:222
#define cuddT(node)
Definition: cuddInt.h:636
#define st__OUT_OF_MEM
Definition: st.h:113
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define cuddE(node)
Definition: cuddInt.h:652
static enum st__retval st__zdd_count_dbl_free ( char *  key,
char *  value,
char *  arg 
)
static

Function********************************************************************

Synopsis [Frees the memory associated with the computed table of Cudd_zddCountDouble.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 350 of file cuddZddCount.c.

354 {
355  double *d;
356 
357  d = (double *)value;
358  ABC_FREE(d);
359  return( st__CONTINUE);
360 
361 } /* end of st__zdd_count_dbl_free */
#define ABC_FREE(obj)
Definition: abc_global.h:232
int value
static enum st__retval st__zdd_countfree ( char *  key,
char *  value,
char *  arg 
)
static

Function********************************************************************

Synopsis [Frees the memory associated with the computed table of Cudd_zddCount.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 323 of file cuddZddCount.c.

327 {
328  int *d;
329 
330  d = (int *)value;
331  ABC_FREE(d);
332  return( st__CONTINUE);
333 
334 } /* end of st__zdd_countfree */
#define ABC_FREE(obj)
Definition: abc_global.h:232
int value

Variable Documentation

ABC_NAMESPACE_IMPL_START char rcsid [] DD_UNUSED = "$Id: cuddZddCount.c,v 1.14 2004/08/13 18:04:53 fabio Exp $"
static

CFile***********************************************************************

FileName [cuddZddCount.c]

PackageName [cudd]

Synopsis [Procedures to count the number of minterms of a ZDD.]

Description [External procedures included in this module:

Internal procedures included in this module:

Static procedures included in this module:

]

SeeAlso []

Author [Hyong-Kyoon Shin, In-Ho Moon]

Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the University of Colorado nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.]

Definition at line 91 of file cuddZddCount.c.