#include <stdio.h>
#include "extra.h"
Go to the source code of this file.
Data Structures | |
struct | Hash_Int_Entry_t_ |
struct | Hash_Int_t_ |
Defines | |
#define | Hash_IntForEachEntry(pHash, pEntry, bin) |
Typedefs | |
typedef struct Hash_Int_t_ | Hash_Int_t |
typedef struct Hash_Int_Entry_t_ | Hash_Int_Entry_t |
Functions | |
int | Hash_DefaultHashFunc (int key, int nBins) |
static Hash_Int_t * | Hash_IntAlloc (int nBins) |
static int | Hash_IntExists (Hash_Int_t *p, int key) |
static void | Hash_IntWriteEntry (Hash_Int_t *p, int key, int data) |
static int | Hash_IntEntry (Hash_Int_t *p, int key, int fCreate) |
static int * | Hash_IntEntryPtr (Hash_Int_t *p, int key) |
static void | Hash_IntFree (Hash_Int_t *p) |
#define Hash_IntForEachEntry | ( | pHash, | |||
pEntry, | |||||
bin | ) |
typedef struct Hash_Int_Entry_t_ Hash_Int_Entry_t |
typedef struct Hash_Int_t_ Hash_Int_t |
int Hash_DefaultHashFunc | ( | int | key, | |
int | nBins | |||
) |
CFile****************************************************************
FileName [hashInt.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 [
] INCLUDES ///
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 [
] INCLUDES /// PARAMETERS /// BASIC TYPES /// MACRO DEFINITIONS /// FUNCTION DECLARATIONS ///
static Hash_Int_t* Hash_IntAlloc | ( | int | nBins | ) | [inline, static] |
FUNCTION DEFINITIONS ///Function*************************************************************
Synopsis [Allocates a hash map with the given number of bins.]
Description []
SideEffects []
SeeAlso []
Definition at line 84 of file hashInt.h.
00085 { 00086 Hash_Int_t * p; 00087 int i; 00088 assert(nBins > 0); 00089 p = ALLOC( Hash_Int_t, 1); 00090 p->nBins = nBins; 00091 p->fHash = Hash_DefaultHashFunc; 00092 p->nSize = 0; 00093 p->pArray = ALLOC( Hash_Int_Entry_t *, nBins ); 00094 for(i=0; i<nBins; i++) 00095 p->pArray[i] = NULL; 00096 00097 return p; 00098 }
static int Hash_IntEntry | ( | Hash_Int_t * | p, | |
int | key, | |||
int | fCreate | |||
) | [inline, static] |
Function*************************************************************
Synopsis [Finds or creates an entry with a key.]
Description [fCreate specifies whether new entries will be created.]
SideEffects []
SeeAlso []
Definition at line 187 of file hashInt.h.
00188 { 00189 int bin; 00190 Hash_Int_Entry_t *pEntry, **pLast; 00191 00192 // find the bin where this key would live 00193 bin = (*(p->fHash))(key, p->nBins); 00194 00195 // search for key 00196 pLast = &(p->pArray[bin]); 00197 pEntry = p->pArray[bin]; 00198 while(pEntry) { 00199 if (pEntry->key == key) 00200 return pEntry->data; 00201 pLast = &(pEntry->pNext); 00202 pEntry = pEntry->pNext; 00203 } 00204 00205 // this key does not currently exist 00206 if (fCreate) { 00207 // create a new entry and add to bin 00208 p->nSize++; 00209 (*pLast) = pEntry = ALLOC( Hash_Int_Entry_t, 1 ); 00210 pEntry->pNext = NULL; 00211 pEntry->key = key; 00212 pEntry->data = 0; 00213 return pEntry->data; 00214 } 00215 00216 return 0; 00217 }
static int* Hash_IntEntryPtr | ( | Hash_Int_t * | p, | |
int | key | |||
) | [inline, static] |
Function*************************************************************
Synopsis [Finds or creates an entry with a key and returns the pointer to it.]
Description []
SideEffects []
SeeAlso []
Definition at line 231 of file hashInt.h.
00232 { 00233 int bin; 00234 Hash_Int_Entry_t *pEntry, **pLast; 00235 00236 // find the bin where this key would live 00237 bin = (*(p->fHash))(key, p->nBins); 00238 00239 // search for key 00240 pLast = &(p->pArray[bin]); 00241 pEntry = p->pArray[bin]; 00242 while(pEntry) { 00243 if (pEntry->key == key) 00244 return &(pEntry->data); 00245 pLast = &(pEntry->pNext); 00246 pEntry = pEntry->pNext; 00247 } 00248 00249 // this key does not currently exist 00250 // create a new entry and add to bin 00251 p->nSize++; 00252 (*pLast) = pEntry = ALLOC( Hash_Int_Entry_t, 1 ); 00253 pEntry->pNext = NULL; 00254 pEntry->key = key; 00255 pEntry->data = 0; 00256 00257 return &(pEntry->data); 00258 }
static int Hash_IntExists | ( | Hash_Int_t * | p, | |
int | key | |||
) | [inline, static] |
Function*************************************************************
Synopsis [Returns 1 if a key already exists.]
Description []
SideEffects []
SeeAlso []
Definition at line 111 of file hashInt.h.
00112 { 00113 int bin; 00114 Hash_Int_Entry_t *pEntry, **pLast; 00115 00116 // find the bin where this key would live 00117 bin = (*(p->fHash))(key, p->nBins); 00118 00119 // search for key 00120 pLast = &(p->pArray[bin]); 00121 pEntry = p->pArray[bin]; 00122 while(pEntry) { 00123 if (pEntry->key == key) { 00124 return 1; 00125 } 00126 pLast = &(pEntry->pNext); 00127 pEntry = pEntry->pNext; 00128 } 00129 00130 return 0; 00131 }
static void Hash_IntFree | ( | Hash_Int_t * | p | ) | [inline, static] |
Function*************************************************************
Synopsis [Frees the hash.]
Description []
SideEffects []
SeeAlso []
Definition at line 271 of file hashInt.h.
00271 { 00272 int bin; 00273 Hash_Int_Entry_t *pEntry; 00274 00275 // free bins 00276 for(bin = 0; bin < p->nBins; bin++) { 00277 pEntry = p->pArray[bin]; 00278 while(pEntry) { 00279 pEntry = pEntry->pNext; 00280 FREE( pEntry ); 00281 } 00282 } 00283 00284 // free hash 00285 FREE( p->pArray ); 00286 FREE( p ); 00287 }
static void Hash_IntWriteEntry | ( | Hash_Int_t * | p, | |
int | key, | |||
int | data | |||
) | [inline, static] |
Function*************************************************************
Synopsis [Finds or creates an entry with a key and writes value.]
Description []
SideEffects []
SeeAlso []
Definition at line 144 of file hashInt.h.
00145 { 00146 int bin; 00147 Hash_Int_Entry_t *pEntry, **pLast; 00148 00149 // find the bin where this key would live 00150 bin = (*(p->fHash))(key, p->nBins); 00151 00152 // search for key 00153 pLast = &(p->pArray[bin]); 00154 pEntry = p->pArray[bin]; 00155 while(pEntry) { 00156 if (pEntry->key == key) { 00157 pEntry->data = data; 00158 return; 00159 } 00160 pLast = &(pEntry->pNext); 00161 pEntry = pEntry->pNext; 00162 } 00163 00164 // this key does not currently exist 00165 // create a new entry and add to bin 00166 p->nSize++; 00167 (*pLast) = pEntry = ALLOC( Hash_Int_Entry_t, 1 ); 00168 pEntry->pNext = NULL; 00169 pEntry->key = key; 00170 pEntry->data = data; 00171 00172 return; 00173 }