| 1 |
greg |
1.1 |
/* Copyright (c) 1994 Regents of the University of California */
|
| 2 |
|
|
|
| 3 |
|
|
/* SCCSid "$SunId$ LBL" */
|
| 4 |
|
|
|
| 5 |
|
|
/*
|
| 6 |
|
|
* Header file for table lookup routines
|
| 7 |
|
|
*/
|
| 8 |
|
|
|
| 9 |
|
|
typedef struct {
|
| 10 |
|
|
char *key; /* key name (dynamically allocated) */
|
| 11 |
|
|
char *data; /* pointer to client data */
|
| 12 |
|
|
} LUENT;
|
| 13 |
|
|
|
| 14 |
|
|
typedef struct {
|
| 15 |
greg |
1.2 |
void (*freek)(); /* free entry key */
|
| 16 |
|
|
void (*freed)(); /* free entry data */
|
| 17 |
greg |
1.1 |
int tsiz; /* current table size */
|
| 18 |
|
|
LUENT *tabl; /* table, if allocated */
|
| 19 |
greg |
1.2 |
int ndel; /* number of deleted entries */
|
| 20 |
greg |
1.1 |
} LUTAB;
|
| 21 |
|
|
|
| 22 |
greg |
1.2 |
#define LU_SINIT(fk,fd) {(void (*)())(fk),(void (*)())(fd),0,NULL,0}
|
| 23 |
|
|
|
| 24 |
greg |
1.1 |
/*
|
| 25 |
|
|
* The lu_init routine is called to initialize a table. The number of
|
| 26 |
|
|
* elements passed is not a limiting factor, as a table can grow to
|
| 27 |
|
|
* any size permitted by memory. However, access will be more efficient
|
| 28 |
|
|
* if this number strikes a reasonable balance between default memory use
|
| 29 |
|
|
* and the expected (minimum) table size. The value returned is the
|
| 30 |
|
|
* actual allocated table size (or zero if there was insufficient memory).
|
| 31 |
|
|
*
|
| 32 |
|
|
* It isn't fully necessary to initialize the LUTAB structure. If it
|
| 33 |
|
|
* is cleared (tsiz = 0, tabl = NULL), then the first call to lu_find
|
| 34 |
greg |
1.2 |
* will allocate a minimal table. If key and data free functions are
|
| 35 |
|
|
* to be used, the LU_SINIT macro provides a convenient declaration.
|
| 36 |
greg |
1.1 |
*
|
| 37 |
|
|
* The lu_find routine returns the entry corresponding to the given
|
| 38 |
|
|
* key (any nul-terminated string). If the entry does not exist, the
|
| 39 |
greg |
1.2 |
* corresponding key field will be NULL. If the entry has been
|
| 40 |
|
|
* previously deleted but not yet freed, then only the data field
|
| 41 |
|
|
* will be NULL. It is the caller's responsibility to (allocate and)
|
| 42 |
|
|
* assign the key and data fields when creating a new entry.
|
| 43 |
|
|
* The only case where lu_find returns NULL is when the system
|
| 44 |
|
|
* has run out of memory.
|
| 45 |
greg |
1.1 |
*
|
| 46 |
greg |
1.2 |
* The lu_delete routine frees an entry's data (if any) by calling
|
| 47 |
|
|
* the freed member function, but does not free the key field. This
|
| 48 |
|
|
* will be freed later during (or instead of) table reallocation.
|
| 49 |
|
|
*
|
| 50 |
greg |
1.1 |
* The lu_done routine calls the given free function once for each
|
| 51 |
|
|
* assigned table entry (i.e. each entry with an assigned key value).
|
| 52 |
greg |
1.3 |
* The user must define these routines to free the key and the data
|
| 53 |
greg |
1.2 |
* in the LU_TAB structure. The final action of lu_done is to free the
|
| 54 |
greg |
1.1 |
* allocated table itself.
|
| 55 |
|
|
*/
|
| 56 |
|
|
|
| 57 |
|
|
#ifdef NOPROTO
|
| 58 |
|
|
extern int lu_init();
|
| 59 |
|
|
extern LUENT *lu_find();
|
| 60 |
greg |
1.2 |
extern void lu_delete();
|
| 61 |
greg |
1.1 |
extern void lu_done();
|
| 62 |
greg |
1.2 |
extern int lu_hash();
|
| 63 |
greg |
1.1 |
#else
|
| 64 |
|
|
extern int lu_init(LUTAB *, int);
|
| 65 |
|
|
extern LUENT *lu_find(LUTAB *, char *);
|
| 66 |
greg |
1.2 |
extern void lu_delete(LUTAB *, char *);
|
| 67 |
|
|
extern void lu_done(LUTAB *);
|
| 68 |
|
|
extern int lu_hash(char *);
|
| 69 |
greg |
1.1 |
#endif
|