Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
lookup.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  LUENT
struct  LUTAB

Defines

#define LU_SINIT(fk, fd)   {lu_shash,lu_strcmp,fk,fd,0,NULL,0}

Typedefs

typedef void lut_free_t (void *p)
typedef unsigned long lut_hashf_t (const void *)
typedef int lut_keycmpf_t (const void *, const void *)
typedef int lut_doallf_t (const LUENT *e, void *p)

Functions

int lu_init (LUTAB *tbl, int nel)
unsigned long lu_shash (const void *s)
LUENTlu_find (LUTAB *tbl, const char *key)
void lu_delete (LUTAB *tbl, const char *key)
int lu_doall (const LUTAB *tbl, lut_doallf_t *f, void *p)
void lu_done (LUTAB *tbl)

Variables

lut_keycmpf_t lu_strcmp

Class Documentation

struct LUENT

Definition at line 16 of file lookup.h.

Class Members
char * data
unsigned long hval
char * key

Define Documentation

#define LU_SINIT (   fk,
  fd 
)    {lu_shash,lu_strcmp,fk,fd,0,NULL,0}

Definition at line 90 of file lookup.h.


Typedef Documentation

typedef int lut_doallf_t(const LUENT *e, void *p)

Definition at line 80 of file lookup.h.

typedef void lut_free_t(void *p)

Definition at line 12 of file lookup.h.

typedef unsigned long lut_hashf_t(const void *)

Definition at line 13 of file lookup.h.

typedef int lut_keycmpf_t(const void *, const void *)

Definition at line 14 of file lookup.h.


Function Documentation

void lu_delete ( LUTAB tbl,
const char *  key 
)
int lu_doall ( const LUTAB tbl,
lut_doallf_t f,
void *  p 
)
void lu_done ( LUTAB tbl)

Definition at line 174 of file lookup.c.

{
       register LUENT       *tp;

       if (!tbl->tsiz)
              return;
       for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; )
              if (tp->key != NULL) {
                     if (tbl->freek != NULL)
                            (*tbl->freek)(tp->key);
                     if (tp->data != NULL && tbl->freed != NULL)
                            (*tbl->freed)(tp->data);
              }
       free((void *)tbl->tabl);
       tbl->tabl = NULL;
       tbl->tsiz = 0;
       tbl->ndel = 0;
}
LUENT* lu_find ( LUTAB tbl,
const char *  key 
)
int lu_init ( LUTAB tbl,
int  nel 
)

Definition at line 15 of file lookup.c.

{
       static int  hsiztab[] = {
              31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381, 
              32749, 65521, 131071, 262139, 524287, 1048573, 2097143, 
              4194301, 8388593, 0
       };
       register int  *hsp;

       nel += nel>>1;                     /* 66% occupancy */
       for (hsp = hsiztab; *hsp; hsp++)
              if (*hsp > nel)
                     break;
       if (!(tbl->tsiz = *hsp))
              tbl->tsiz = nel*2 + 1;             /* not always prime */
       tbl->tabl = (LUENT *)calloc(tbl->tsiz, sizeof(LUENT));
       if (tbl->tabl == NULL)
              tbl->tsiz = 0;
       tbl->ndel = 0;
       return(tbl->tsiz);
}
unsigned long lu_shash ( const void *  s)

Definition at line 51 of file lookup.c.

{
       static unsigned char shuffle[256] = {
              0, 157, 58, 215, 116, 17, 174, 75, 232, 133, 34,
              191, 92, 249, 150, 51, 208, 109, 10, 167, 68, 225,
              126, 27, 184, 85, 242, 143, 44, 201, 102, 3, 160,
              61, 218, 119, 20, 177, 78, 235, 136, 37, 194, 95,
              252, 153, 54, 211, 112, 13, 170, 71, 228, 129, 30,
              187, 88, 245, 146, 47, 204, 105, 6, 163, 64, 221,
              122, 23, 180, 81, 238, 139, 40, 197, 98, 255, 156,
              57, 214, 115, 16, 173, 74, 231, 132, 33, 190, 91,
              248, 149, 50, 207, 108, 9, 166, 67, 224, 125, 26,
              183, 84, 241, 142, 43, 200, 101, 2, 159, 60, 217,
              118, 19, 176, 77, 234, 135, 36, 193, 94, 251, 152,
              53, 210, 111, 12, 169, 70, 227, 128, 29, 186, 87,
              244, 145, 46, 203, 104, 5, 162, 63, 220, 121, 22,
              179, 80, 237, 138, 39, 196, 97, 254, 155, 56, 213,
              114, 15, 172, 73, 230, 131, 32, 189, 90, 247, 148,
              49, 206, 107, 8, 165, 66, 223, 124, 25, 182, 83,
              240, 141, 42, 199, 100, 1, 158, 59, 216, 117, 18,
              175, 76, 233, 134, 35, 192, 93, 250, 151, 52, 209,
              110, 11, 168, 69, 226, 127, 28, 185, 86, 243, 144,
              45, 202, 103, 4, 161, 62, 219, 120, 21, 178, 79,
              236, 137, 38, 195, 96, 253, 154, 55, 212, 113, 14,
              171, 72, 229, 130, 31, 188, 89, 246, 147, 48, 205,
              106, 7, 164, 65, 222, 123, 24, 181, 82, 239, 140,
              41, 198, 99
       };
       register int  i = 0;
       register unsigned long      h = 0;
       register unsigned const char *t = (unsigned const char *)s;

       while (*t)
              h ^= (unsigned long)shuffle[*t++] << ((i+=11) & 0xf);

       return(h);
}

Variable Documentation