| 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 |
int tsiz; /* current table size */ |
| 16 |
LUENT *tabl; /* table, if allocated */ |
| 17 |
} LUTAB; |
| 18 |
|
| 19 |
/* |
| 20 |
* The lu_init routine is called to initialize a table. The number of |
| 21 |
* elements passed is not a limiting factor, as a table can grow to |
| 22 |
* any size permitted by memory. However, access will be more efficient |
| 23 |
* if this number strikes a reasonable balance between default memory use |
| 24 |
* and the expected (minimum) table size. The value returned is the |
| 25 |
* actual allocated table size (or zero if there was insufficient memory). |
| 26 |
* |
| 27 |
* It isn't fully necessary to initialize the LUTAB structure. If it |
| 28 |
* is cleared (tsiz = 0, tabl = NULL), then the first call to lu_find |
| 29 |
* will allocate a minimal table. |
| 30 |
* |
| 31 |
* The lu_find routine returns the entry corresponding to the given |
| 32 |
* key (any nul-terminated string). If the entry does not exist, the |
| 33 |
* corresponding key field will be NULL. It is the caller's responsibility |
| 34 |
* to (allocate and) assign the key field when creating a new entry. |
| 35 |
* If an entry exists, the corresponding data field indicates whether |
| 36 |
* or not it contains data, and this, too, is subject to user control |
| 37 |
* and interpretation. The only case where lu_find returns NULL is |
| 38 |
* when the system has run out of memory. |
| 39 |
* |
| 40 |
* The lu_done routine calls the given free function once for each |
| 41 |
* assigned table entry (i.e. each entry with an assigned key value). |
| 42 |
* The user must define this routine to free the key and the data |
| 43 |
* as appropriate. The final action of lu_done is to free the |
| 44 |
* allocated table itself. |
| 45 |
*/ |
| 46 |
|
| 47 |
#ifdef NOPROTO |
| 48 |
extern int lu_init(); |
| 49 |
extern LUENT *lu_find(); |
| 50 |
extern void lu_done(); |
| 51 |
#else |
| 52 |
extern int lu_init(LUTAB *, int); |
| 53 |
extern LUENT *lu_find(LUTAB *, char *); |
| 54 |
extern void lu_done(LUTAB *, void (*)(LUENT *)); |
| 55 |
#endif |