ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/lookup.h
Revision: 1.2
Committed: Thu Jun 23 07:48:35 1994 UTC (30 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +24 -10 lines
Log Message:
improved table lookup routines with new delete function

File Contents

# Content
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 void (*freek)(); /* free entry key */
16 void (*freed)(); /* free entry data */
17 int tsiz; /* current table size */
18 LUENT *tabl; /* table, if allocated */
19 int ndel; /* number of deleted entries */
20 } LUTAB;
21
22 #define LU_SINIT(fk,fd) {(void (*)())(fk),(void (*)())(fd),0,NULL,0}
23
24 /*
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 * 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 *
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 * 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 *
46 * 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 * 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 * The user must define this routines to free the key and the data
53 * in the LU_TAB structure. The final action of lu_done is to free the
54 * allocated table itself.
55 */
56
57 #ifdef NOPROTO
58 extern int lu_init();
59 extern LUENT *lu_find();
60 extern void lu_delete();
61 extern void lu_done();
62 extern int lu_hash();
63 #else
64 extern int lu_init(LUTAB *, int);
65 extern LUENT *lu_find(LUTAB *, char *);
66 extern void lu_delete(LUTAB *, char *);
67 extern void lu_done(LUTAB *);
68 extern int lu_hash(char *);
69 #endif