abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nmInt.h File Reference
#include "misc/extra/extra.h"
#include "misc/vec/vec.h"
#include "nm.h"

Go to the source code of this file.

Data Structures

struct  Nm_Entry_t_
 
struct  Nm_Man_t_
 

Typedefs

typedef
typedefABC_NAMESPACE_HEADER_START
struct Nm_Entry_t_ 
Nm_Entry_t
 INCLUDES ///. More...
 

Functions

int Nm_ManTableAdd (Nm_Man_t *p, Nm_Entry_t *pEntry)
 MACRO DEFINITIONS ///. More...
 
int Nm_ManTableDelete (Nm_Man_t *p, int ObjId)
 
Nm_Entry_tNm_ManTableLookupId (Nm_Man_t *p, int ObjId)
 
Nm_Entry_tNm_ManTableLookupName (Nm_Man_t *p, char *pName, int Type)
 

Typedef Documentation

typedef typedefABC_NAMESPACE_HEADER_START struct Nm_Entry_t_ Nm_Entry_t

INCLUDES ///.

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

FileName [nmInt.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Name manager.]

Synopsis [Internal declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]PARAMETERS ///BASIC TYPES ///

Definition at line 46 of file nmInt.h.

Function Documentation

int Nm_ManTableAdd ( Nm_Man_t p,
Nm_Entry_t pEntry 
)

MACRO DEFINITIONS ///.

FUNCTION DECLARATIONS ///

MACRO DEFINITIONS ///.

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

Synopsis [Adds an entry to two hash tables.]

Description []

SideEffects []

SeeAlso []

Definition at line 71 of file nmTable.c.

72 {
73  Nm_Entry_t ** ppSpot, * pOther;
74  // resize the tables if needed
75  if ( p->nEntries > p->nBins * p->nSizeFactor )
76  Nm_ManResize( p );
77  // add the entry to the table Id->Name
78  assert( Nm_ManTableLookupId(p, pEntry->ObjId) == NULL );
79  ppSpot = p->pBinsI2N + Nm_HashNumber(pEntry->ObjId, p->nBins);
80  pEntry->pNextI2N = *ppSpot;
81  *ppSpot = pEntry;
82  // check if an entry with the same name already exists
83  if ( (pOther = Nm_ManTableLookupName(p, pEntry->Name, -1)) )
84  {
85  // entry with the same name already exists - add it to the ring
86  pEntry->pNameSake = pOther->pNameSake? pOther->pNameSake : pOther;
87  pOther->pNameSake = pEntry;
88  }
89  else
90  {
91  // entry with the same name does not exist - add it to the table
92  ppSpot = p->pBinsN2I + Nm_HashString(pEntry->Name, p->nBins);
93  pEntry->pNextN2I = *ppSpot;
94  *ppSpot = pEntry;
95  }
96  // report successfully added entry
97  p->nEntries++;
98  return 1;
99 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Nm_Entry_t * Nm_ManTableLookupName(Nm_Man_t *p, char *pName, int Type)
Definition: nmTable.c:191
typedefABC_NAMESPACE_HEADER_START struct Nm_Entry_t_ Nm_Entry_t
INCLUDES ///.
Definition: nmInt.h:46
Nm_Entry_t * Nm_ManTableLookupId(Nm_Man_t *p, int ObjId)
Definition: nmTable.c:171
static void Nm_ManResize(Nm_Man_t *p)
Definition: nmTable.c:256
static unsigned Nm_HashString(char *pName, int TableSize)
Definition: nmTable.c:42
#define assert(ex)
Definition: util_old.h:213
static ABC_NAMESPACE_IMPL_START unsigned Nm_HashNumber(int Num, int TableSize)
DECLARATIONS ///.
Definition: nmTable.c:31
int Nm_ManTableDelete ( Nm_Man_t p,
int  ObjId 
)

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

Synopsis [Deletes the entry from two hash tables.]

Description []

SideEffects []

SeeAlso []

Definition at line 112 of file nmTable.c.

113 {
114  Nm_Entry_t ** ppSpot, * pEntry, * pPrev;
115  int fRemoved;
116  p->nEntries--;
117  // remove the entry from the table Id->Name
118  assert( Nm_ManTableLookupId(p, ObjId) != NULL );
119  ppSpot = p->pBinsI2N + Nm_HashNumber(ObjId, p->nBins);
120  while ( (*ppSpot)->ObjId != (unsigned)ObjId )
121  ppSpot = &(*ppSpot)->pNextI2N;
122  pEntry = *ppSpot;
123  *ppSpot = (*ppSpot)->pNextI2N;
124  // remove the entry from the table Name->Id
125  ppSpot = p->pBinsN2I + Nm_HashString(pEntry->Name, p->nBins);
126  while ( *ppSpot && *ppSpot != pEntry )
127  ppSpot = &(*ppSpot)->pNextN2I;
128  // remember if we found this one in the list
129  fRemoved = (*ppSpot != NULL);
130  if ( *ppSpot )
131  {
132  assert( *ppSpot == pEntry );
133  *ppSpot = (*ppSpot)->pNextN2I;
134  }
135  // quit if this entry has no namesakes
136  if ( pEntry->pNameSake == NULL )
137  {
138  assert( fRemoved );
139  return 1;
140  }
141  // remove entry from the ring of namesakes
142  assert( pEntry->pNameSake != pEntry );
143  for ( pPrev = pEntry; pPrev->pNameSake != pEntry; pPrev = pPrev->pNameSake );
144  assert( !strcmp(pPrev->Name, pEntry->Name) );
145  assert( pPrev->pNameSake == pEntry );
146  if ( pEntry->pNameSake == pPrev ) // two entries in the ring
147  pPrev->pNameSake = NULL;
148  else
149  pPrev->pNameSake = pEntry->pNameSake;
150  // reinsert the ring back if we removed its connection with the list in the table
151  if ( fRemoved )
152  {
153  assert( pPrev->pNextN2I == NULL );
154  pPrev->pNextN2I = *ppSpot;
155  *ppSpot = pPrev;
156  }
157  return 1;
158 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_HEADER_START struct Nm_Entry_t_ Nm_Entry_t
INCLUDES ///.
Definition: nmInt.h:46
Nm_Entry_t * Nm_ManTableLookupId(Nm_Man_t *p, int ObjId)
Definition: nmTable.c:171
int strcmp()
static unsigned Nm_HashString(char *pName, int TableSize)
Definition: nmTable.c:42
#define assert(ex)
Definition: util_old.h:213
static ABC_NAMESPACE_IMPL_START unsigned Nm_HashNumber(int Num, int TableSize)
DECLARATIONS ///.
Definition: nmTable.c:31
Nm_Entry_t* Nm_ManTableLookupId ( Nm_Man_t p,
int  ObjId 
)

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

Synopsis [Looks up the entry by ID.]

Description []

SideEffects []

SeeAlso []

Definition at line 171 of file nmTable.c.

172 {
173  Nm_Entry_t * pEntry;
174  for ( pEntry = p->pBinsI2N[ Nm_HashNumber(ObjId, p->nBins) ]; pEntry; pEntry = pEntry->pNextI2N )
175  if ( pEntry->ObjId == (unsigned)ObjId )
176  return pEntry;
177  return NULL;
178 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_HEADER_START struct Nm_Entry_t_ Nm_Entry_t
INCLUDES ///.
Definition: nmInt.h:46
static ABC_NAMESPACE_IMPL_START unsigned Nm_HashNumber(int Num, int TableSize)
DECLARATIONS ///.
Definition: nmTable.c:31
Nm_Entry_t* Nm_ManTableLookupName ( Nm_Man_t p,
char *  pName,
int  Type 
)

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

Synopsis [Looks up the entry by name and type.]

Description []

SideEffects []

SeeAlso []

Definition at line 191 of file nmTable.c.

192 {
193  Nm_Entry_t * pEntry, * pTemp;
194  for ( pEntry = p->pBinsN2I[ Nm_HashString(pName, p->nBins) ]; pEntry; pEntry = pEntry->pNextN2I )
195  {
196  // check the entry itself
197  if ( !strcmp(pEntry->Name, pName) && (Type == -1 || pEntry->Type == (unsigned)Type) )
198  return pEntry;
199  // if there is no namesakes, continue
200  if ( pEntry->pNameSake == NULL )
201  continue;
202  // check the list of namesakes
203  for ( pTemp = pEntry->pNameSake; pTemp != pEntry; pTemp = pTemp->pNameSake )
204  if ( !strcmp(pTemp->Name, pName) && (Type == -1 || pTemp->Type == (unsigned)Type) )
205  return pTemp;
206  }
207  return NULL;
208 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_HEADER_START struct Nm_Entry_t_ Nm_Entry_t
INCLUDES ///.
Definition: nmInt.h:46
int strcmp()
static unsigned Nm_HashString(char *pName, int TableSize)
Definition: nmTable.c:42