abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hashPtr.h File Reference
#include <stdio.h>
#include "misc/extra/extra.h"

Go to the source code of this file.

Data Structures

struct  Hash_Ptr_Entry_t_
 
struct  Hash_Ptr_t_
 

Macros

#define Hash_PtrForEachEntry(pHash, pEntry, bin)
 MACRO DEFINITIONS ///. More...
 

Typedefs

typedef struct Hash_Ptr_t_ Hash_Ptr_t
 PARAMETERS ///. More...
 
typedef struct Hash_Ptr_Entry_t_ Hash_Ptr_Entry_t
 

Functions

ABC_NAMESPACE_HEADER_START int Hash_DefaultHashFunc (int key, int nBins)
 INCLUDES ///. More...
 
static Hash_Ptr_tHash_PtrAlloc (int nBins)
 FUNCTION DEFINITIONS ///. More...
 
static int Hash_PtrExists (Hash_Ptr_t *p, int key)
 
static void Hash_PtrWriteEntry (Hash_Ptr_t *p, int key, void *data)
 
static void * Hash_PtrEntry (Hash_Ptr_t *p, int key, int fCreate)
 
static void ** Hash_PtrEntryPtr (Hash_Ptr_t *p, int key)
 
static void * Hash_PtrRemove (Hash_Ptr_t *p, int key)
 
static void Hash_PtrFree (Hash_Ptr_t *p)
 

Macro Definition Documentation

#define Hash_PtrForEachEntry (   pHash,
  pEntry,
  bin 
)
Value:
for(bin=-1, pEntry=NULL; bin < pHash->nBins; (!pEntry)?(pEntry=pHash->pArray[++bin]):(pEntry=pEntry->pNext)) \
if (pEntry)
if(last==0)
Definition: sparse_int.h:34

MACRO DEFINITIONS ///.

Definition at line 69 of file hashPtr.h.

Typedef Documentation

Definition at line 46 of file hashPtr.h.

typedef struct Hash_Ptr_t_ Hash_Ptr_t

PARAMETERS ///.

BASIC TYPES ///

Definition at line 45 of file hashPtr.h.

Function Documentation

ABC_NAMESPACE_HEADER_START int Hash_DefaultHashFunc ( int  key,
int  nBins 
)

INCLUDES ///.

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

FileName [hashFlt.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Hash maps.]

Synopsis [Hash maps.]

Author [Aaron P. Hurst]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - May 16, 2006.]

Revision [

Id:
vecInt.h,v 1.00 2005/06/20 00:00:00 ahurst Exp

]

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

FileName [hash.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Hash map.]

Synopsis [External declarations.]

Author [Aaron P. Hurst]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - May 16, 2005.]

Revision [

Id:
vec.h,v 1.00 2005/06/20 00:00:00 ahurst Exp

]PARAMETERS ///BASIC TYPES ///MACRO DEFINITIONS ///FUNCTION DECLARATIONS ///

Definition at line 57 of file hash.h.

57  {
58  return Abc_AbsInt( ( (key+11)*(key)*7+3 ) % nBins );
59 }
static int Abc_AbsInt(int a)
Definition: abc_global.h:237
enum keys key
static Hash_Ptr_t* Hash_PtrAlloc ( int  nBins)
inlinestatic

FUNCTION DEFINITIONS ///.

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

Synopsis [Allocates a hash map with the given number of bins.]

Description []

SideEffects []

SeeAlso []

Definition at line 88 of file hashPtr.h.

89 {
90  Hash_Ptr_t * p;
91  int i;
92  assert(nBins > 0);
93  p = ABC_ALLOC( Hash_Ptr_t, 1);
94  p->nBins = nBins;
96  p->nSize = 0;
97  p->pArray = ABC_ALLOC( Hash_Ptr_Entry_t *, nBins );
98  for(i=0; i<nBins; i++)
99  p->pArray[i] = NULL;
100 
101  return p;
102 }
int nBins
Definition: hashPtr.h:58
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nSize
Definition: hashPtr.h:57
Definition: hashPtr.h:48
ABC_NAMESPACE_HEADER_START int Hash_DefaultHashFunc(int key, int nBins)
INCLUDES ///.
Definition: hash.h:57
int(* fHash)(int key, int nBins)
Definition: hashPtr.h:59
#define assert(ex)
Definition: util_old.h:213
Hash_Ptr_Entry_t ** pArray
Definition: hashPtr.h:60
static void* Hash_PtrEntry ( Hash_Ptr_t p,
int  key,
int  fCreate 
)
inlinestatic

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

Synopsis [Finds or creates an entry with a key.]

Description [fCreate specifies whether a new entry should be created.]

SideEffects []

SeeAlso []

Definition at line 189 of file hashPtr.h.

190 {
191  int bin;
192  Hash_Ptr_Entry_t *pEntry, **pLast;
193 
194  // find the bin where this key would live
195  bin = (*(p->fHash))(key, p->nBins);
196 
197  // search for key
198  pLast = &(p->pArray[bin]);
199  pEntry = p->pArray[bin];
200  while(pEntry) {
201  if (pEntry->key == key)
202  return pEntry->data;
203  pLast = &(pEntry->pNext);
204  pEntry = pEntry->pNext;
205  }
206 
207  // this key does not currently exist
208  if (fCreate) {
209  // create a new entry and add to bin
210  p->nSize++;
211  (*pLast) = pEntry = ABC_ALLOC( Hash_Ptr_Entry_t, 1 );
212  pEntry->pNext = NULL;
213  pEntry->key = key;
214  pEntry->data = NULL;
215  return pEntry->data;
216  }
217 
218  return NULL;
219 }
int nBins
Definition: hashPtr.h:58
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nSize
Definition: hashPtr.h:57
Definition: hashPtr.h:48
struct Hash_Ptr_Entry_t_ * pNext
Definition: hashPtr.h:52
int key
Definition: hashPtr.h:50
void * data
Definition: hashPtr.h:51
int(* fHash)(int key, int nBins)
Definition: hashPtr.h:59
enum keys key
Hash_Ptr_Entry_t ** pArray
Definition: hashPtr.h:60
static void** Hash_PtrEntryPtr ( Hash_Ptr_t p,
int  key 
)
inlinestatic

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

Synopsis [Finds or creates an entry with a key and returns the pointer to it.]

Description []

SideEffects []

SeeAlso []

Definition at line 233 of file hashPtr.h.

234 {
235  int bin;
236  Hash_Ptr_Entry_t *pEntry, **pLast;
237 
238  // find the bin where this key would live
239  bin = (*(p->fHash))(key, p->nBins);
240 
241  // search for key
242  pLast = &(p->pArray[bin]);
243  pEntry = p->pArray[bin];
244  while(pEntry) {
245  if (pEntry->key == key)
246  return &(pEntry->data);
247  pLast = &(pEntry->pNext);
248  pEntry = pEntry->pNext;
249  }
250 
251  // this key does not currently exist
252  // create a new entry and add to bin
253  p->nSize++;
254  (*pLast) = pEntry = ABC_ALLOC( Hash_Ptr_Entry_t, 1 );
255  pEntry->pNext = NULL;
256  pEntry->key = key;
257  pEntry->data = NULL;
258 
259  return &(pEntry->data);
260 }
int nBins
Definition: hashPtr.h:58
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nSize
Definition: hashPtr.h:57
Definition: hashPtr.h:48
struct Hash_Ptr_Entry_t_ * pNext
Definition: hashPtr.h:52
int key
Definition: hashPtr.h:50
void * data
Definition: hashPtr.h:51
int(* fHash)(int key, int nBins)
Definition: hashPtr.h:59
enum keys key
Hash_Ptr_Entry_t ** pArray
Definition: hashPtr.h:60
static int Hash_PtrExists ( Hash_Ptr_t p,
int  key 
)
inlinestatic

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

Synopsis [Returns 1 if a key already exists.]

Description []

SideEffects []

SeeAlso []

Definition at line 115 of file hashPtr.h.

116 {
117  int bin;
118  Hash_Ptr_Entry_t *pEntry;
119 
120  // find the bin where this key would live
121  bin = (*(p->fHash))(key, p->nBins);
122 
123  // search for key
124  pEntry = p->pArray[bin];
125  while(pEntry) {
126  if (pEntry->key == key) {
127  return 1;
128  }
129  pEntry = pEntry->pNext;
130  }
131 
132  return 0;
133 }
int nBins
Definition: hashPtr.h:58
Definition: hashPtr.h:48
struct Hash_Ptr_Entry_t_ * pNext
Definition: hashPtr.h:52
int key
Definition: hashPtr.h:50
int(* fHash)(int key, int nBins)
Definition: hashPtr.h:59
enum keys key
Hash_Ptr_Entry_t ** pArray
Definition: hashPtr.h:60
static void Hash_PtrFree ( Hash_Ptr_t p)
inlinestatic

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

Synopsis [Frees the hash.]

Description []

SideEffects []

SeeAlso []

Definition at line 311 of file hashPtr.h.

312 {
313  int bin;
314  Hash_Ptr_Entry_t *pEntry, *pTemp;
315 
316  // free bins
317  for(bin = 0; bin < p->nBins; bin++) {
318  pEntry = p->pArray[bin];
319  while(pEntry) {
320  pTemp = pEntry;
321  pEntry = pEntry->pNext;
322  ABC_FREE( pTemp );
323  }
324  }
325 
326  // free hash
327  ABC_FREE( p->pArray );
328  ABC_FREE( p );
329 }
int nBins
Definition: hashPtr.h:58
Definition: hashPtr.h:48
struct Hash_Ptr_Entry_t_ * pNext
Definition: hashPtr.h:52
#define ABC_FREE(obj)
Definition: abc_global.h:232
Hash_Ptr_Entry_t ** pArray
Definition: hashPtr.h:60
static void* Hash_PtrRemove ( Hash_Ptr_t p,
int  key 
)
inlinestatic

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

Synopsis [Deletes an entry.]

Description [Returns data, if there was any.]

SideEffects []

SeeAlso []

Definition at line 273 of file hashPtr.h.

274 {
275  int bin;
276  void * data;
277  Hash_Ptr_Entry_t *pEntry, **pLast;
278 
279  // find the bin where this key would live
280  bin = (*(p->fHash))(key, p->nBins);
281 
282  // search for key
283  pLast = &(p->pArray[bin]);
284  pEntry = p->pArray[bin];
285  while(pEntry) {
286  if (pEntry->key == key) {
287  p->nSize--;
288  data = pEntry->data;
289  *pLast = pEntry->pNext;
290  return data;
291  }
292  pLast = &(pEntry->pNext);
293  pEntry = pEntry->pNext;
294  }
295 
296  // could not find key
297  return NULL;
298 }
int nBins
Definition: hashPtr.h:58
int nSize
Definition: hashPtr.h:57
Definition: hashPtr.h:48
struct Hash_Ptr_Entry_t_ * pNext
Definition: hashPtr.h:52
int key
Definition: hashPtr.h:50
void * data
Definition: hashPtr.h:51
int(* fHash)(int key, int nBins)
Definition: hashPtr.h:59
enum keys key
Hash_Ptr_Entry_t ** pArray
Definition: hashPtr.h:60
static void Hash_PtrWriteEntry ( Hash_Ptr_t p,
int  key,
void *  data 
)
inlinestatic

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

Synopsis [Finds or creates an entry with a key and writes value.]

Description []

SideEffects []

SeeAlso []

Definition at line 146 of file hashPtr.h.

147 {
148  int bin;
149  Hash_Ptr_Entry_t *pEntry, **pLast;
150 
151  // find the bin where this key would live
152  bin = (*(p->fHash))(key, p->nBins);
153 
154  // search for key
155  pLast = &(p->pArray[bin]);
156  pEntry = p->pArray[bin];
157  while(pEntry) {
158  if (pEntry->key == key) {
159  pEntry->data = data;
160  return;
161  }
162  pLast = &(pEntry->pNext);
163  pEntry = pEntry->pNext;
164  }
165 
166  // this key does not currently exist
167  // create a new entry and add to bin
168  p->nSize++;
169  (*pLast) = pEntry = ABC_ALLOC( Hash_Ptr_Entry_t, 1 );
170  pEntry->pNext = NULL;
171  pEntry->key = key;
172  pEntry->data = data;
173 
174  return;
175 }
int nBins
Definition: hashPtr.h:58
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nSize
Definition: hashPtr.h:57
Definition: hashPtr.h:48
struct Hash_Ptr_Entry_t_ * pNext
Definition: hashPtr.h:52
int key
Definition: hashPtr.h:50
void * data
Definition: hashPtr.h:51
int(* fHash)(int key, int nBins)
Definition: hashPtr.h:59
enum keys key
Hash_Ptr_Entry_t ** pArray
Definition: hashPtr.h:60