51 {bucketUnsignedHash, bucketUnsignedCompare,
bidtUnsigned},
52 {bucketPointerHash, bucketPointerCompare,
bidtPointer},
53 {bucketStringHash, bucketStringCompare,
bidtString}
57 const void *pId,
const void *pApp);
58 static void *bucketLookupItem(
BUCKET *pb,
bucketSET *pBSET,
const void *pId);
65 #define BUCKETID_BIT_WIDTH (sizeof(BUCKETID)*CHAR_BIT) 70 #define BUCKET_MAX_WIDTH 12 76 static ITEM **bucketUnsignedCompare (
ITEM **ppi,
const void *pId)
82 id = * (
unsigned *) pId;
83 while ( (pi = *ppi) ) {
85 pItemId = (
unsigned *) pi->
pId;
99 static ITEM **bucketPointerCompare (
ITEM **ppi,
const void *pId)
105 ptr = * (
void **) pId;
106 while ( (pi = *ppi) ) {
108 pItemId = (
void **) pi->
pId;
109 if (ptr == *pItemId) {
122 static ITEM **bucketStringCompare (
ITEM **ppi,
const void *pId)
124 const char *pStr = pId;
128 while ( (pi = *ppi) ) {
130 status = strcmp (pStr, (
char *)pi->
pId);
131 if (status ==
'\0') {
146 const unsigned *pUId = (
const unsigned *) pId;
154 hashid = hashid ^ src;
168 void *
const *ppId = (
void *
const *) pId;
178 src = (size_t) *ppId;
182 hashid = hashid ^ src;
196 const char *pStr = (
const char *) pId;
227 if (nHashTableEntries<=1) {
228 fprintf (
stderr,
"Tiny bucket create failed\n");
237 mask = (1<<nbits) - 1;
238 if ( ((nHashTableEntries-1) & ~mask) == 0){
255 "%s at %d: Requested index width=%d to large. max=%ld\n",
263 pb = (
BUCKET *) calloc(1,
sizeof(*pb));
307 LIBCOM_API
int epicsStdCall
310 return bucketAddItem(prb, &BSET[
bidtUnsigned], pId, pApp);
312 LIBCOM_API
int epicsStdCall
315 return bucketAddItem(prb, &BSET[
bidtPointer], pId, pApp);
317 LIBCOM_API
int epicsStdCall
320 return bucketAddItem(prb, &BSET[
bidtString], pId, pApp);
322 static int bucketAddItem(
BUCKET *prb,
bucketSET *pBSET,
const void *pId,
const void *pApp)
341 hashid = (*pBSET->
pHash) (prb, pId);
347 ppi = &prb->
pTable[hashid];
351 ppiExists = (*pBSET->
pCompare) (ppi, pId);
366 static void *bucketLookupAndRemoveItem (
BUCKET *prb,
bucketSET *pBSET,
const void *pId)
376 hashid = (*pBSET->
pHash) (prb, pId);
379 ppi = &prb->
pTable[hashid];
380 ppi = (*pBSET->
pCompare) (ppi, pId);
388 pApp = (
void *) pi->
pApp;
399 return bucketLookupAndRemoveItem(prb, &BSET[
bidtUnsigned], pId);
403 return bucketLookupAndRemoveItem(prb, &BSET[
bidtPointer], pId);
407 return bucketLookupAndRemoveItem(prb, &BSET[
bidtString], pId);
414 LIBCOM_API
int epicsStdCall
419 LIBCOM_API
int epicsStdCall
424 LIBCOM_API
int epicsStdCall
434 LIBCOM_API
void * epicsStdCall
439 LIBCOM_API
void * epicsStdCall
442 return bucketLookupItem(prb, &BSET[
bidtPointer], pId);
444 LIBCOM_API
void * epicsStdCall
447 return bucketLookupItem(prb, &BSET[
bidtString], pId);
449 static void *bucketLookupItem (
BUCKET *pb,
bucketSET *pBSET,
const void *pId)
457 hashid = (*pBSET->
pHash) (pb, pId);
466 return (
void *) (*ppi)->
pApp;
488 printf(
" Bucket entries in use = %d bytes in use = %ld\n",
498 while (ppi < &pb->pTable[nElem]) {
507 if (count > maxEntries) maxEntries = count;
512 stdDev = sqrt(XX/nElem - mean*mean);
513 printf(
" Bucket entries/hash id - mean = %f std dev = %f max = %d\n",
LIBCOM_API int epicsStdCall bucketFree(BUCKET *prb)
Release memory used by a hash table.
LIBCOM_API int epicsStdCall bucketAddItemStringId(BUCKET *prb, const char *pId, const void *pApp)
Add an item identified by a string to the table.
#define assert(exp)
Declare that a condition should be true.
An EPICS-specific replacement for ANSI C's assert.
LIBCOM_API void *epicsStdCall bucketLookupItemUnsignedId(BUCKET *prb, const unsigned *pId)
Find an item identified by an unsigned int in the table.
Internal: bucket item structure.
LIBCOM_API int epicsStdCall bucketShow(BUCKET *pb)
Display information about a hash table.
#define BUCKETID_BIT_WIDTH
LIBCOM_API void epicsStdCall freeListInitPvt(void **ppvt, int size, int nmalloc)
buckTypeOfId
Internal: bucket key type.
LIBCOM_API int epicsStdCall bucketAddItemUnsignedId(BUCKET *prb, const unsigned *pId, const void *pApp)
Add an item identified by an unsigned int to the table.
LIBCOM_API void *epicsStdCall bucketLookupAndRemoveItemPointerId(BUCKET *prb, void *const *pId)
Find and delete an item identified by a pointer from the table.
#define S_bucket_uknId
Unknown identifier.
BUCKETID bucketHash(BUCKET *pb, const void *pId)
LIBCOM_API void epicsStdCall freeListCleanup(void *pvt)
LIBCOM_API void epicsStdCall freeListFree(void *pvt, void *pmem)
unsigned BUCKETID
Internal: bucket identifier.
LIBCOM_API int epicsStdCall bucketRemoveItemUnsignedId(BUCKET *prb, const unsigned *pId)
Remove an item identified by a string from the table.
LIBCOM_API void *epicsStdCall bucketLookupAndRemoveItemUnsignedId(BUCKET *prb, const unsigned *pId)
Find and delete an item identified by an unsigned int from the table.
LIBCOM_API void *epicsStdCall bucketLookupItemPointerId(BUCKET *prb, void *const *pId)
Find an item identified by a pointer in the table.
#define S_bucket_noMemory
Memory allocation failed.
LIBCOM_API void *epicsStdCall bucketLookupItemStringId(BUCKET *prb, const char *pId)
Find an item identified by a string in the table.
LIBCOM_API int epicsStdCall bucketRemoveItemPointerId(BUCKET *prb, void *const *pId)
Remove an item identified by a pointer from the table.
LIBCOM_API void *epicsStdCall bucketLookupAndRemoveItemStringId(BUCKET *prb, const char *pId)
Find and delete an item identified by a string from the table.
A hash table. Do not use for new code.
LIBCOM_API BUCKET *epicsStdCall bucketCreate(unsigned nHashTableEntries)
Creates a new hash table.
#define S_bucket_idInUse
Identifier already in use.
LIBCOM_API int epicsStdCall bucketAddItemPointerId(BUCKET *prb, void *const *pId, const void *pApp)
Add an item identified by a pointer to the table.
#define S_bucket_success
Success, must be 0.
ITEM ** bucketCompare(ITEM **ppi, const void *pId)
Internal: Hash table structure.
LIBCOM_API int epicsStdCall bucketRemoveItemStringId(BUCKET *prb, const char *pId)
Remove an item identified by a string from the table.
LIBCOM_API void *epicsStdCall freeListMalloc(void *pvt)