--- ray/src/common/lookup.h 2003/02/25 02:47:21 2.7 +++ ray/src/common/lookup.h 2004/05/25 22:04:13 2.14 @@ -1,10 +1,18 @@ -/* RCSid $Id: lookup.h,v 2.7 2003/02/25 02:47:21 greg Exp $ */ +/* RCSid $Id: lookup.h,v 2.14 2004/05/25 22:04:13 greg Exp $ */ /* * Header file for general associative table lookup routines */ +#ifndef _RAD_LOOKUP_H_ +#define _RAD_LOOKUP_H_ -#include "copyright.h" +#ifdef __cplusplus +extern "C" { +#endif +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 struct { char *key; /* key name */ unsigned long hval; /* key hash value (for efficiency) */ @@ -12,18 +20,15 @@ typedef struct { } LUENT; typedef struct { - unsigned long (*hashf)(); /* key hash function */ - int (*keycmp)(); /* key comparison function */ - void (*freek)(); /* free a key */ - void (*freed)(); /* free the data */ + lut_hashf_t *hashf; /* key hash function */ + lut_keycmpf_t *keycmp; /* key comparison function */ + lut_free_t *freek; /* free a key */ + lut_free_t *freed; /* free the data */ int tsiz; /* current table size */ LUENT *tabl; /* table, if allocated */ int ndel; /* number of deleted entries */ } LUTAB; -#undef strcmp -#define LU_SINIT(fk,fd) {lu_shash,strcmp,(void (*)())(fk),\ - (void (*)())(fd),0,NULL,0} /* * The lu_init routine is called to initialize a table. The number of @@ -72,24 +77,20 @@ typedef struct { * allocated table itself. */ -extern int strcmp(); +typedef int lut_doallf_t(const LUENT *e, void *p); -#ifdef NOPROTO - -extern int lu_init(); -extern LUENT *lu_find(); -extern void lu_delete(); -extern int lu_doall(); -extern void lu_done(); -extern unsigned long lu_shash(); - -#else - +extern lut_keycmpf_t lu_strcmp; extern int lu_init(LUTAB *tbl, int nel); -extern unsigned long lu_shash(char *s); -extern LUENT *lu_find(LUTAB *tbl, char *key); -extern void lu_delete(LUTAB *tbl, char *key); -extern int lu_doall(LUTAB *tbl, int (*f)()); +extern unsigned long lu_shash(const void *s); +extern LUENT *lu_find(LUTAB *tbl, const char *key); +extern void lu_delete(LUTAB *tbl, const char *key); +extern int lu_doall(const LUTAB *tbl, lut_doallf_t *f, void *p); extern void lu_done(LUTAB *tbl); +#define LU_SINIT(fk,fd) {lu_shash,lu_strcmp,fk,fd,0,NULL,0} + +#ifdef __cplusplus +} #endif +#endif /* _RAD_LOOKUP_H_ */ +