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

Go to the source code of this file.

Data Structures

struct  Hash_Flt_Entry_t_
 
struct  Hash_Flt_t_
 

Macros

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

Typedefs

typedef struct Hash_Flt_t_ Hash_Flt_t
 PARAMETERS ///. More...
 
typedef struct Hash_Flt_Entry_t_ Hash_Flt_Entry_t
 

Functions

ABC_NAMESPACE_HEADER_START int Hash_DefaultHashFunc (int key, int nBins)
 INCLUDES ///. More...
 
static Hash_Flt_tHash_FltAlloc (int nBins)
 FUNCTION DEFINITIONS ///. More...
 
static int Hash_FltExists (Hash_Flt_t *p, int key)
 
static void Hash_FltWriteEntry (Hash_Flt_t *p, int key, float data)
 
static float Hash_FltEntry (Hash_Flt_t *p, int key, int fCreate)
 
static float * Hash_FltEntryPtr (Hash_Flt_t *p, int key)
 
static void Hash_FltRemove (Hash_Flt_t *p, int key)
 
static void Hash_FltFree (Hash_Flt_t *p)
 

Macro Definition Documentation

#define Hash_FltForEachEntry (   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 hashFlt.h.

Typedef Documentation

Definition at line 46 of file hashFlt.h.

typedef struct Hash_Flt_t_ Hash_Flt_t

PARAMETERS ///.

BASIC TYPES ///

Definition at line 45 of file hashFlt.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_Flt_t* Hash_FltAlloc ( 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 hashFlt.h.

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

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

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

Description [fCreate specifies whether new entries should be created.]

SideEffects []

SeeAlso []

Definition at line 191 of file hashFlt.h.

192 {
193  int bin;
194  Hash_Flt_Entry_t *pEntry, **pLast;
195 
196  // find the bin where this key would live
197  bin = (*(p->fHash))(key, p->nBins);
198 
199  // search for key
200  pLast = &(p->pArray[bin]);
201  pEntry = p->pArray[bin];
202  while(pEntry) {
203  if (pEntry->key == key)
204  return pEntry->data;
205  pLast = &(pEntry->pNext);
206  pEntry = pEntry->pNext;
207  }
208 
209  // this key does not currently exist
210  if (fCreate) {
211  // create a new entry and add to bin
212  p->nSize++;
213  (*pLast) = pEntry = ABC_ALLOC( Hash_Flt_Entry_t, 1 );
214  pEntry->pNext = NULL;
215  pEntry->key = key;
216  pEntry->data = 0.0;
217  return pEntry->data;
218  }
219 
220  return 0.0;
221 }
struct Hash_Flt_Entry_t_ * pNext
Definition: hashFlt.h:52
int key
Definition: hashFlt.h:50
int nBins
Definition: hashFlt.h:58
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
float data
Definition: hashFlt.h:51
Definition: hashFlt.h:48
int nSize
Definition: hashFlt.h:57
enum keys key
int(* fHash)(int key, int nBins)
Definition: hashFlt.h:59
Hash_Flt_Entry_t ** pArray
Definition: hashFlt.h:60
static float* Hash_FltEntryPtr ( Hash_Flt_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 235 of file hashFlt.h.

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

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

Synopsis [Returns 1 if a key already exists.]

Description []

SideEffects []

SeeAlso []

Definition at line 115 of file hashFlt.h.

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

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

Synopsis [Frees the hash.]

Description []

SideEffects []

SeeAlso []

Definition at line 312 of file hashFlt.h.

312  {
313  int bin;
314  Hash_Flt_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 }
struct Hash_Flt_Entry_t_ * pNext
Definition: hashFlt.h:52
int nBins
Definition: hashFlt.h:58
Definition: hashFlt.h:48
#define ABC_FREE(obj)
Definition: abc_global.h:232
Hash_Flt_Entry_t ** pArray
Definition: hashFlt.h:60
static void Hash_FltRemove ( Hash_Flt_t p,
int  key 
)
inlinestatic

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

Synopsis [Deletes an entry.]

Description []

SideEffects []

SeeAlso []

Definition at line 275 of file hashFlt.h.

276 {
277  int bin;
278  Hash_Flt_Entry_t *pEntry, **pLast;
279 
280  // find the bin where this key would live
281  bin = (*(p->fHash))(key, p->nBins);
282 
283  // search for key
284  pLast = &(p->pArray[bin]);
285  pEntry = p->pArray[bin];
286  while(pEntry) {
287  if (pEntry->key == key) {
288  p->nSize--;
289  *pLast = pEntry->pNext;
290  ABC_FREE( pEntry );
291  return;
292  }
293  pLast = &(pEntry->pNext);
294  pEntry = pEntry->pNext;
295  }
296 
297  // could not find key
298  return;
299 }
struct Hash_Flt_Entry_t_ * pNext
Definition: hashFlt.h:52
int key
Definition: hashFlt.h:50
int nBins
Definition: hashFlt.h:58
Definition: hashFlt.h:48
int nSize
Definition: hashFlt.h:57
#define ABC_FREE(obj)
Definition: abc_global.h:232
enum keys key
int(* fHash)(int key, int nBins)
Definition: hashFlt.h:59
Hash_Flt_Entry_t ** pArray
Definition: hashFlt.h:60
static void Hash_FltWriteEntry ( Hash_Flt_t p,
int  key,
float  data 
)
inlinestatic

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 148 of file hashFlt.h.

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