summaryrefslogtreecommitdiffstats
path: root/src/misc/hash
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2009-02-15 08:01:00 -0800
committerAlan Mishchenko <alanmi@berkeley.edu>2009-02-15 08:01:00 -0800
commit0871bffae307e0553e0c5186336189e8b55cf6a6 (patch)
tree4571d1563fe33a53a57fea1c35fb668b9d33265f /src/misc/hash
parentf936cc0680c98ffe51b3a1716c996072d5dbf76c (diff)
downloadabc-0871bffae307e0553e0c5186336189e8b55cf6a6.tar.gz
abc-0871bffae307e0553e0c5186336189e8b55cf6a6.tar.bz2
abc-0871bffae307e0553e0c5186336189e8b55cf6a6.zip
Version abc90215
Diffstat (limited to 'src/misc/hash')
-rw-r--r--src/misc/hash/hash.h13
-rw-r--r--src/misc/hash/hashFlt.h22
-rw-r--r--src/misc/hash/hashInt.h20
-rw-r--r--src/misc/hash/hashPtr.h20
4 files changed, 36 insertions, 39 deletions
diff --git a/src/misc/hash/hash.h b/src/misc/hash/hash.h
index 90e72868..dad4db18 100644
--- a/src/misc/hash/hash.h
+++ b/src/misc/hash/hash.h
@@ -21,13 +21,14 @@
#ifndef __HASH_H__
#define __HASH_H__
+#ifdef _WIN32
+#define inline __inline // compatible with MS VS 6.0
+#endif
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
-#ifdef _WIN32
-#define inline __inline // compatible with MS VS 6.0
-#endif
+#include "abc_global.h"
#include "hashInt.h"
#include "hashFlt.h"
@@ -45,16 +46,12 @@
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
-#ifndef ABS
-#define ABS(a) ((a) < 0 ? -(a) : (a))
-#endif
-
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
int Hash_DefaultHashFunc(int key, int nBins) {
- return ABS( ( (key+11)*(key)*7+3 ) % nBins );
+ return ABC_ABS( ( (key+11)*(key)*7+3 ) % nBins );
}
////////////////////////////////////////////////////////////////////////
diff --git a/src/misc/hash/hashFlt.h b/src/misc/hash/hashFlt.h
index da20ee28..43b9dd7f 100644
--- a/src/misc/hash/hashFlt.h
+++ b/src/misc/hash/hashFlt.h
@@ -86,11 +86,11 @@ static inline Hash_Flt_t * Hash_FltAlloc( int nBins )
Hash_Flt_t * p;
int i;
assert(nBins > 0);
- p = ALLOC( Hash_Flt_t, 1);
+ p = ABC_ALLOC( Hash_Flt_t, 1);
p->nBins = nBins;
p->fHash = Hash_DefaultHashFunc;
p->nSize = 0;
- p->pArray = ALLOC( Hash_Flt_Entry_t *, nBins );
+ p->pArray = ABC_ALLOC( Hash_Flt_Entry_t *, nBins );
for(i=0; i<nBins; i++)
p->pArray[i] = NULL;
@@ -164,7 +164,7 @@ static inline void Hash_FltWriteEntry( Hash_Flt_t *p, int key, float data )
// this key does not currently exist
// create a new entry and add to bin
p->nSize++;
- (*pLast) = pEntry = ALLOC( Hash_Flt_Entry_t, 1 );
+ (*pLast) = pEntry = ABC_ALLOC( Hash_Flt_Entry_t, 1 );
pEntry->pNext = NULL;
pEntry->key = key;
pEntry->data = data;
@@ -206,7 +206,7 @@ static inline float Hash_FltEntry( Hash_Flt_t *p, int key, int fCreate )
if (fCreate) {
// create a new entry and add to bin
p->nSize++;
- (*pLast) = pEntry = ALLOC( Hash_Flt_Entry_t, 1 );
+ (*pLast) = pEntry = ABC_ALLOC( Hash_Flt_Entry_t, 1 );
pEntry->pNext = NULL;
pEntry->key = key;
pEntry->data = 0.0;
@@ -249,7 +249,7 @@ static inline float* Hash_FltEntryPtr( Hash_Flt_t *p, int key )
// this key does not currently exist
// create a new entry and add to bin
p->nSize++;
- (*pLast) = pEntry = ALLOC( Hash_Flt_Entry_t, 1 );
+ (*pLast) = pEntry = ABC_ALLOC( Hash_Flt_Entry_t, 1 );
pEntry->pNext = NULL;
pEntry->key = key;
pEntry->data = 0.0;
@@ -283,7 +283,7 @@ static inline void Hash_FltRemove( Hash_Flt_t *p, int key )
if (pEntry->key == key) {
p->nSize--;
*pLast = pEntry->pNext;
- FREE( pEntry );
+ ABC_FREE( pEntry );
return;
}
pLast = &(pEntry->pNext);
@@ -309,18 +309,18 @@ static inline void Hash_FltFree( Hash_Flt_t *p ) {
int bin;
Hash_Flt_Entry_t *pEntry;
- // free bins
+ // ABC_FREE bins
for(bin = 0; bin < p->nBins; bin++) {
pEntry = p->pArray[bin];
while(pEntry) {
pEntry = pEntry->pNext;
- FREE( pEntry );
+ ABC_FREE( pEntry );
}
}
- // free hash
- FREE( p->pArray );
- FREE( p );
+ // ABC_FREE hash
+ ABC_FREE( p->pArray );
+ ABC_FREE( p );
}
////////////////////////////////////////////////////////////////////////
diff --git a/src/misc/hash/hashInt.h b/src/misc/hash/hashInt.h
index b7ec8a8c..7993e562 100644
--- a/src/misc/hash/hashInt.h
+++ b/src/misc/hash/hashInt.h
@@ -86,11 +86,11 @@ static inline Hash_Int_t * Hash_IntAlloc( int nBins )
Hash_Int_t * p;
int i;
assert(nBins > 0);
- p = ALLOC( Hash_Int_t, 1);
+ p = ABC_ALLOC( Hash_Int_t, 1);
p->nBins = nBins;
p->fHash = Hash_DefaultHashFunc;
p->nSize = 0;
- p->pArray = ALLOC( Hash_Int_Entry_t *, nBins+1 );
+ p->pArray = ABC_ALLOC( Hash_Int_Entry_t *, nBins+1 );
for(i=0; i<nBins; i++)
p->pArray[i] = NULL;
@@ -164,7 +164,7 @@ static inline void Hash_IntWriteEntry( Hash_Int_t *p, int key, int data )
// this key does not currently exist
// create a new entry and add to bin
p->nSize++;
- (*pLast) = pEntry = ALLOC( Hash_Int_Entry_t, 1 );
+ (*pLast) = pEntry = ABC_ALLOC( Hash_Int_Entry_t, 1 );
pEntry->pNext = NULL;
pEntry->key = key;
pEntry->data = data;
@@ -206,7 +206,7 @@ static inline int Hash_IntEntry( Hash_Int_t *p, int key, int fCreate )
if (fCreate) {
// create a new entry and add to bin
p->nSize++;
- (*pLast) = pEntry = ALLOC( Hash_Int_Entry_t, 1 );
+ (*pLast) = pEntry = ABC_ALLOC( Hash_Int_Entry_t, 1 );
pEntry->pNext = NULL;
pEntry->key = key;
pEntry->data = 0;
@@ -249,7 +249,7 @@ static inline int* Hash_IntEntryPtr( Hash_Int_t *p, int key )
// this key does not currently exist
// create a new entry and add to bin
p->nSize++;
- (*pLast) = pEntry = ALLOC( Hash_Int_Entry_t, 1 );
+ (*pLast) = pEntry = ABC_ALLOC( Hash_Int_Entry_t, 1 );
pEntry->pNext = NULL;
pEntry->key = key;
pEntry->data = 0;
@@ -272,19 +272,19 @@ static inline void Hash_IntFree( Hash_Int_t *p ) {
int bin;
Hash_Int_Entry_t *pEntry, *pTemp;
- // free bins
+ // ABC_FREE bins
for(bin = 0; bin < p->nBins; bin++) {
pEntry = p->pArray[bin];
while(pEntry) {
pTemp = pEntry;
pEntry = pEntry->pNext;
- FREE( pTemp );
+ ABC_FREE( pTemp );
}
}
- // free hash
- FREE( p->pArray );
- FREE( p );
+ // ABC_FREE hash
+ ABC_FREE( p->pArray );
+ ABC_FREE( p );
}
////////////////////////////////////////////////////////////////////////
diff --git a/src/misc/hash/hashPtr.h b/src/misc/hash/hashPtr.h
index 15398a8a..224e5c84 100644
--- a/src/misc/hash/hashPtr.h
+++ b/src/misc/hash/hashPtr.h
@@ -86,11 +86,11 @@ static inline Hash_Ptr_t * Hash_PtrAlloc( int nBins )
Hash_Ptr_t * p;
int i;
assert(nBins > 0);
- p = ALLOC( Hash_Ptr_t, 1);
+ p = ABC_ALLOC( Hash_Ptr_t, 1);
p->nBins = nBins;
p->fHash = Hash_DefaultHashFunc;
p->nSize = 0;
- p->pArray = ALLOC( Hash_Ptr_Entry_t *, nBins );
+ p->pArray = ABC_ALLOC( Hash_Ptr_Entry_t *, nBins );
for(i=0; i<nBins; i++)
p->pArray[i] = NULL;
@@ -164,7 +164,7 @@ static inline void Hash_PtrWriteEntry( Hash_Ptr_t *p, int key, void * data )
// this key does not currently exist
// create a new entry and add to bin
p->nSize++;
- (*pLast) = pEntry = ALLOC( Hash_Ptr_Entry_t, 1 );
+ (*pLast) = pEntry = ABC_ALLOC( Hash_Ptr_Entry_t, 1 );
pEntry->pNext = NULL;
pEntry->key = key;
pEntry->data = data;
@@ -206,7 +206,7 @@ static inline void * Hash_PtrEntry( Hash_Ptr_t *p, int key, int fCreate )
if (fCreate) {
// create a new entry and add to bin
p->nSize++;
- (*pLast) = pEntry = ALLOC( Hash_Ptr_Entry_t, 1 );
+ (*pLast) = pEntry = ABC_ALLOC( Hash_Ptr_Entry_t, 1 );
pEntry->pNext = NULL;
pEntry->key = key;
pEntry->data = NULL;
@@ -249,7 +249,7 @@ static inline void** Hash_PtrEntryPtr( Hash_Ptr_t *p, int key )
// this key does not currently exist
// create a new entry and add to bin
p->nSize++;
- (*pLast) = pEntry = ALLOC( Hash_Ptr_Entry_t, 1 );
+ (*pLast) = pEntry = ABC_ALLOC( Hash_Ptr_Entry_t, 1 );
pEntry->pNext = NULL;
pEntry->key = key;
pEntry->data = NULL;
@@ -310,18 +310,18 @@ static inline void Hash_PtrFree( Hash_Ptr_t *p ) {
int bin;
Hash_Ptr_Entry_t *pEntry;
- // free bins
+ // ABC_FREE bins
for(bin = 0; bin < p->nBins; bin++) {
pEntry = p->pArray[bin];
while(pEntry) {
pEntry = pEntry->pNext;
- FREE( pEntry );
+ ABC_FREE( pEntry );
}
}
- // free hash
- FREE( p->pArray );
- FREE( p );
+ // ABC_FREE hash
+ ABC_FREE( p->pArray );
+ ABC_FREE( p );
}
////////////////////////////////////////////////////////////////////////