abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
utilNam.h File Reference

Go to the source code of this file.

Macros

#define Abc_NamManForEachObj(p, pStr, i)   for ( i = 1; (i < Abc_NamObjNumMax(p)) && ((pStr) = Abc_NamStr(p, i)); i++ )
 MACRO DEFINITIONS ///. More...
 

Typedefs

typedef
typedefABC_NAMESPACE_HEADER_START
struct Abc_Nam_t_ 
Abc_Nam_t
 INCLUDES ///. More...
 

Functions

Abc_Nam_tAbc_NamStart (int nObjs, int nAveSize)
 FUNCTION DECLARATIONS ///. More...
 
void Abc_NamStop (Abc_Nam_t *p)
 
void Abc_NamPrint (Abc_Nam_t *p)
 
Abc_Nam_tAbc_NamRef (Abc_Nam_t *p)
 
void Abc_NamDeref (Abc_Nam_t *p)
 
int Abc_NamObjNumMax (Abc_Nam_t *p)
 
int Abc_NamMemUsed (Abc_Nam_t *p)
 
int Abc_NamMemAlloc (Abc_Nam_t *p)
 
int Abc_NamStrFind (Abc_Nam_t *p, char *pStr)
 
int Abc_NamStrFindLim (Abc_Nam_t *p, char *pStr, char *pLim)
 
int Abc_NamStrFindOrAdd (Abc_Nam_t *p, char *pStr, int *pfFound)
 
int Abc_NamStrFindOrAddLim (Abc_Nam_t *p, char *pStr, char *pLim, int *pfFound)
 
char * Abc_NamStr (Abc_Nam_t *p, int id)
 
Vec_Int_tAbc_NamComputeIdMap (Abc_Nam_t *p1, Abc_Nam_t *p2)
 
int Abc_NamReportCommon (Vec_Int_t *vNameIds1, Abc_Nam_t *p1, Abc_Nam_t *p2)
 
char * Abc_NamReportUnique (Vec_Int_t *vNameIds1, Abc_Nam_t *p1, Abc_Nam_t *p2)
 

Macro Definition Documentation

#define Abc_NamManForEachObj (   p,
  pStr,
 
)    for ( i = 1; (i < Abc_NamObjNumMax(p)) && ((pStr) = Abc_NamStr(p, i)); i++ )

MACRO DEFINITIONS ///.

Definition at line 45 of file utilNam.h.

Typedef Documentation

typedef typedefABC_NAMESPACE_HEADER_START struct Abc_Nam_t_ Abc_Nam_t

INCLUDES ///.

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

FileName [utilNam.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Memory recycling utilities.]

Synopsis [Internal declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
utilNam.h,v 1.00 2005/06/20 00:00:00 alanmi Exp

]PARAMETERS ///BASIC TYPES ///

Definition at line 39 of file utilNam.h.

Function Documentation

Vec_Int_t* Abc_NamComputeIdMap ( Abc_Nam_t p1,
Abc_Nam_t p2 
)

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

Synopsis [For each ID of the first manager, gives ID of the second one.]

Description []

SideEffects []

SeeAlso []

Definition at line 495 of file utilNam.c.

496 {
497  Vec_Int_t * vMap;
498  char * pThis;
499  int * piPlace, iHandle1, i;
500  if ( p1 == p2 )
502  vMap = Vec_IntStart( Abc_NamObjNumMax(p1) );
503  Vec_IntForEachEntryStart( p1->vInt2Handle, iHandle1, i, 1 )
504  {
505  pThis = Abc_NamHandleToStr( p1, iHandle1 );
506  piPlace = Abc_NamStrHashFind( p2, pThis, NULL );
507  Vec_IntWriteEntry( vMap, i, *piPlace );
508 // Abc_Print( 1, "%d->%d ", i, *piPlace );
509  }
510  return vMap;
511 }
static int * Abc_NamStrHashFind(Abc_Nam_t *p, const char *pStr, const char *pLim)
Definition: utilNam.c:305
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int Abc_NamObjNumMax(Abc_Nam_t *p)
Definition: utilNam.c:186
static Vec_Int_t * Vec_IntStartNatural(int nSize)
Definition: bblif.c:192
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition: vecInt.h:56
static char * Abc_NamHandleToStr(Abc_Nam_t *p, int h)
Definition: utilNam.c:57
void Abc_NamDeref ( Abc_Nam_t p)

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

Synopsis [Dereferences the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 167 of file utilNam.c.

168 {
169  if ( p == NULL )
170  return;
171  if ( --p->nRefs == 0 )
172  Abc_NamStop( p );
173 }
void Abc_NamStop(Abc_Nam_t *p)
Definition: utilNam.c:110
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Abc_NamMemAlloc ( Abc_Nam_t p)

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

Synopsis [Reports memory usage of the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 221 of file utilNam.c.

222 {
223  if ( p == NULL )
224  return 0;
225  return sizeof(Abc_Nam_t) + p->nStore + sizeof(int) * p->nBins +
226  sizeof(int) * (p->vInt2Handle->nCap + p->vInt2Next->nCap);
227 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_HEADER_START struct Abc_Nam_t_ Abc_Nam_t
INCLUDES ///.
Definition: utilNam.h:39
int Abc_NamMemUsed ( Abc_Nam_t p)

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

Synopsis [Reports memory usage of the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 202 of file utilNam.c.

203 {
204  if ( p == NULL )
205  return 0;
206  return sizeof(Abc_Nam_t) + p->iHandle + sizeof(int) * p->nBins +
207  sizeof(int) * (p->vInt2Handle->nSize + p->vInt2Next->nSize);
208 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_HEADER_START struct Abc_Nam_t_ Abc_Nam_t
INCLUDES ///.
Definition: utilNam.h:39
int Abc_NamObjNumMax ( Abc_Nam_t p)

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

Synopsis [Returns the number of used entries.]

Description []

SideEffects []

SeeAlso []

Definition at line 186 of file utilNam.c.

187 {
188  return Vec_IntSize(p->vInt2Handle);
189 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
void Abc_NamPrint ( Abc_Nam_t p)

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

Synopsis [Prints manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 131 of file utilNam.c.

132 {
133  int h, i;
134  Vec_IntForEachEntryStart( p->vInt2Handle, h, i, 1 )
135  Abc_Print( 1, "%d=\n%s\n", i, Abc_NamHandleToStr(p, h) );
136 // Abc_Print( 1, "\n" );
137 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition: vecInt.h:56
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
static char * Abc_NamHandleToStr(Abc_Nam_t *p, int h)
Definition: utilNam.c:57
Abc_Nam_t* Abc_NamRef ( Abc_Nam_t p)

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

Synopsis [References the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 150 of file utilNam.c.

151 {
152  p->nRefs++;
153  return p;
154 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Abc_NamReportCommon ( Vec_Int_t vNameIds1,
Abc_Nam_t p1,
Abc_Nam_t p2 
)

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

Synopsis [Returns the number of common names in the array.]

Description [The array contains name IDs in the first manager. The procedure returns the number of entries that correspond to names in the first manager that appear in the second manager.]

SideEffects []

SeeAlso []

Definition at line 526 of file utilNam.c.

527 {
528  int i, Entry, Counter = 0;
529  Vec_IntForEachEntry( vNameIds1, Entry, i )
530  {
531  assert( Entry > 0 && Entry < Abc_NamObjNumMax(p1) );
532  Counter += (Abc_NamStrFind(p2, Abc_NamStr(p1, Entry)) > 0);
533 // if ( Abc_NamStrFind(p2, Abc_NamStr(p1, Entry)) == 0 )
534 // Abc_Print( 1, "unique name <%s>\n", Abc_NamStr(p1, Entry) );
535  }
536  return Counter;
537 }
int Abc_NamObjNumMax(Abc_Nam_t *p)
Definition: utilNam.c:186
static int Counter
int Abc_NamStrFind(Abc_Nam_t *p, char *pStr)
Definition: utilNam.c:372
char * Abc_NamStr(Abc_Nam_t *p, int NameId)
Definition: utilNam.c:479
#define assert(ex)
Definition: util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
char* Abc_NamReportUnique ( Vec_Int_t vNameIds1,
Abc_Nam_t p1,
Abc_Nam_t p2 
)

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

Synopsis [Returns the name that appears in p1 does not appear in p2.]

Description []

SideEffects []

SeeAlso []

Definition at line 550 of file utilNam.c.

551 {
552  int i, Entry;
553  Vec_IntForEachEntry( vNameIds1, Entry, i )
554  {
555  assert( Entry > 0 && Entry < Abc_NamObjNumMax(p1) );
556  if ( Abc_NamStrFind(p2, Abc_NamStr(p1, Entry)) == 0 )
557  return Abc_NamStr(p1, Entry);
558  }
559  return NULL;
560 }
int Abc_NamObjNumMax(Abc_Nam_t *p)
Definition: utilNam.c:186
int Abc_NamStrFind(Abc_Nam_t *p, char *pStr)
Definition: utilNam.c:372
char * Abc_NamStr(Abc_Nam_t *p, int NameId)
Definition: utilNam.c:479
#define assert(ex)
Definition: util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
Abc_Nam_t* Abc_NamStart ( int  nObjs,
int  nAveSize 
)

FUNCTION DECLARATIONS ///.

FUNCTION DECLARATIONS ///.

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

Synopsis [Creates manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 78 of file utilNam.c.

79 {
80  Abc_Nam_t * p;
81  if ( nObjs == 0 )
82  nObjs = 16;
83  p = ABC_CALLOC( Abc_Nam_t, 1 );
84  p->nStore = ((nObjs * (nAveSize + 1) + 16) / 4) * 4;
85  p->pStore = ABC_ALLOC( char, p->nStore );
86  p->nBins = Abc_PrimeCudd( nObjs );
87  p->pBins = ABC_CALLOC( int, p->nBins );
88  // 0th object is unused
89  p->vInt2Handle = Vec_IntAlloc( nObjs ); Vec_IntPush( p->vInt2Handle, -1 );
90  p->vInt2Next = Vec_IntAlloc( nObjs ); Vec_IntPush( p->vInt2Next, -1 );
91  p->iHandle = 4;
92  memset( p->pStore, 0, 4 );
93 //Abc_Print( 1, "Starting nam with %d bins.\n", p->nBins );
94  // start reference counting
95  p->nRefs = 1;
96  return p;
97 }
char * memset()
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
typedefABC_NAMESPACE_HEADER_START struct Abc_Nam_t_ Abc_Nam_t
INCLUDES ///.
Definition: utilNam.h:39
void Abc_NamStop ( Abc_Nam_t p)

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

Synopsis [Deletes manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 110 of file utilNam.c.

111 {
112 //Abc_Print( 1, "Starting nam with %d bins.\n", p->nBins );
113  Vec_IntFree( p->vInt2Handle );
114  Vec_IntFree( p->vInt2Next );
115  ABC_FREE( p->pStore );
116  ABC_FREE( p->pBins );
117  ABC_FREE( p );
118 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_FREE(obj)
Definition: abc_global.h:232
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
char* Abc_NamStr ( Abc_Nam_t p,
int  NameId 
)

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

Synopsis [Returns name from name ID.]

Description []

SideEffects []

SeeAlso []

Definition at line 479 of file utilNam.c.

480 {
481  return NameId? Abc_NamIntToStr(p, NameId) : NULL;
482 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static char * Abc_NamIntToStr(Abc_Nam_t *p, int i)
Definition: utilNam.c:59
int Abc_NamStrFind ( Abc_Nam_t p,
char *  pStr 
)

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

Synopsis [Returns the index of the string in the table.]

Description []

SideEffects []

SeeAlso []

Definition at line 372 of file utilNam.c.

373 {
374  return *Abc_NamStrHashFind( p, pStr, NULL );
375 }
static int * Abc_NamStrHashFind(Abc_Nam_t *p, const char *pStr, const char *pLim)
Definition: utilNam.c:305
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Abc_NamStrFindLim ( Abc_Nam_t p,
char *  pStr,
char *  pLim 
)

Definition at line 376 of file utilNam.c.

377 {
378  return *Abc_NamStrHashFind( p, pStr, pLim );
379 }
static int * Abc_NamStrHashFind(Abc_Nam_t *p, const char *pStr, const char *pLim)
Definition: utilNam.c:305
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Abc_NamStrFindOrAdd ( Abc_Nam_t p,
char *  pStr,
int *  pfFound 
)

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

Synopsis [Finds or adds the given name to storage.]

Description []

SideEffects []

SeeAlso []

Definition at line 392 of file utilNam.c.

393 {
394  int i, iHandleNew;
395  int *piPlace;
396  if ( !(pStr[0] != '\\' || pStr[strlen(pStr)-1] == ' ') )
397  {
398  for ( i = strlen(pStr) - 1; i >= 0; i-- )
399  if ( *pStr == ' ' )
400  break;
401  assert( i < (int)strlen(pStr) );
402  }
403  piPlace = Abc_NamStrHashFind( p, pStr, NULL );
404  if ( *piPlace )
405  {
406  if ( pfFound )
407  *pfFound = 1;
408  return *piPlace;
409  }
410  if ( pfFound )
411  *pfFound = 0;
412  iHandleNew = p->iHandle + strlen(pStr) + 1;
413  while ( p->nStore < iHandleNew )
414  {
415  p->nStore *= 3;
416  p->nStore /= 2;
417  p->pStore = ABC_REALLOC( char, p->pStore, p->nStore );
418  }
419  assert( p->nStore >= iHandleNew );
420  // create new handle
421  *piPlace = Vec_IntSize( p->vInt2Handle );
422  strcpy( Abc_NamHandleToStr( p, p->iHandle ), pStr );
423  Vec_IntPush( p->vInt2Handle, p->iHandle );
424  Vec_IntPush( p->vInt2Next, 0 );
425  p->iHandle = iHandleNew;
426  // extend the hash table
427  if ( Vec_IntSize(p->vInt2Handle) > 2 * p->nBins )
429  return Vec_IntSize(p->vInt2Handle) - 1;
430 }
void Abc_NamStrHashResize(Abc_Nam_t *p)
Definition: utilNam.c:329
static int * Abc_NamStrHashFind(Abc_Nam_t *p, const char *pStr, const char *pLim)
Definition: utilNam.c:305
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
char * strcpy()
static char * Abc_NamHandleToStr(Abc_Nam_t *p, int h)
Definition: utilNam.c:57
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define assert(ex)
Definition: util_old.h:213
int strlen()
int Abc_NamStrFindOrAddLim ( Abc_Nam_t p,
char *  pStr,
char *  pLim,
int *  pfFound 
)

Definition at line 431 of file utilNam.c.

432 {
433  int iHandleNew;
434  int *piPlace;
435  char * pStore;
436  assert( pStr < pLim );
437  piPlace = Abc_NamStrHashFind( p, pStr, pLim );
438  if ( *piPlace )
439  {
440  if ( pfFound )
441  *pfFound = 1;
442  return *piPlace;
443  }
444  if ( pfFound )
445  *pfFound = 0;
446  iHandleNew = p->iHandle + (pLim - pStr) + 1;
447  while ( p->nStore < iHandleNew )
448  {
449  p->nStore *= 3;
450  p->nStore /= 2;
451  p->pStore = ABC_REALLOC( char, p->pStore, p->nStore );
452  }
453  assert( p->nStore >= iHandleNew );
454  // create new handle
455  *piPlace = Vec_IntSize( p->vInt2Handle );
456  pStore = Abc_NamHandleToStr( p, p->iHandle );
457  strncpy( pStore, pStr, pLim - pStr );
458  pStore[pLim - pStr] = 0;
459  Vec_IntPush( p->vInt2Handle, p->iHandle );
460  Vec_IntPush( p->vInt2Next, 0 );
461  p->iHandle = iHandleNew;
462  // extend the hash table
463  if ( Vec_IntSize(p->vInt2Handle) > 2 * p->nBins )
465  return Vec_IntSize(p->vInt2Handle) - 1;
466 }
void Abc_NamStrHashResize(Abc_Nam_t *p)
Definition: utilNam.c:329
static int * Abc_NamStrHashFind(Abc_Nam_t *p, const char *pStr, const char *pLim)
Definition: utilNam.c:305
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
char * strncpy()
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static char * Abc_NamHandleToStr(Abc_Nam_t *p, int h)
Definition: utilNam.c:57
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define assert(ex)
Definition: util_old.h:213