ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/lookup.h
Revision: 1.10
Committed: Fri Feb 28 20:11:29 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 1.9: +1 -4 lines
Log Message:
Updates for 3.5 release

File Contents

# Content
1 /* RCSid: $Id$ */
2 /*
3 * Header file for general associative table lookup routines
4 */
5
6 typedef struct {
7 char *key; /* key name */
8 long hval; /* key hash value (for efficiency) */
9 char *data; /* pointer to client data */
10 } LUENT;
11
12 #ifdef NOPROTO
13 typedef struct {
14 unsigned long (*hashf)(); /* key hash function */
15 int (*keycmp)(); /* key comparison function */
16 void (*freek)(); /* free a key */
17 void (*freed)(); /* free the data */
18 int tsiz; /* current table size */
19 LUENT *tabl; /* table, if allocated */
20 int ndel; /* number of deleted entries */
21 } LUTAB;
22 #else
23 typedef struct {
24 unsigned long (*hashf)(char *); /* key hash function */
25 int (*keycmp)(const char *, const char *); /* key comparison function */
26 void (*freek)(char *); /* free a key */
27 void (*freed)(char *); /* free the data */
28 int tsiz; /* current table size */
29 LUENT *tabl; /* table, if allocated */
30 int ndel; /* number of deleted entries */
31 } LUTAB;
32 #endif
33
34 #define LU_SINIT(fk,fd) {lu_shash,strcmp,(void (*)())(fk),\
35 (void (*)())(fd),0,NULL,0}
36
37 /*
38 * The lu_init routine is called to initialize a table. The number of
39 * elements passed is not a limiting factor, as a table can grow to
40 * any size permitted by memory. However, access will be more efficient
41 * if this number strikes a reasonable balance between default memory use
42 * and the expected (minimum) table size. The value returned is the
43 * actual allocated table size (or zero if there was insufficient memory).
44 *
45 * The hashf, keycmp, freek and freed member functions must be assigned
46 * separately. If the hash value is sufficient to guarantee equality
47 * between keys, then the keycmp pointer may be NULL. Otherwise, it
48 * should return 0 if the two passed keys match. If it is not necessary
49 * (or possible) to free the key and/or data values, then the freek and/or
50 * freed member functions may be NULL.
51 *
52 * It isn't fully necessary to call lu_init to initialize the LUTAB structure.
53 * If tsiz is 0, then the first call to lu_find will allocate a minimal table.
54 * The LU_SINIT macro provides a convenient static declaration for character
55 * string keys.
56 *
57 * The lu_find routine returns the entry corresponding to the given
58 * key. If the entry does not exist, the corresponding key field will
59 * be NULL. If the entry has been previously deleted but not yet freed,
60 * then only the data field will be NULL. It is the caller's
61 * responsibility to (allocate and) assign the key and data fields when
62 * creating a new entry. The only case where lu_find returns NULL is when
63 * the system has run out of memory.
64 *
65 * The lu_delete routine frees an entry's data (if any) by calling
66 * the freed member function, but does not free the key field. This
67 * will be freed later during (or instead of) table reallocation.
68 * It is therefore an error to reuse or do anything with the key
69 * field after calling lu_delete.
70 *
71 * The lu_done routine calls the given free function once for each
72 * assigned table entry (i.e. each entry with an assigned key value).
73 * The user must define these routines to free the key and the data
74 * in the LU_TAB structure. The final action of lu_done is to free the
75 * allocated table itself.
76 */
77
78 #ifdef NOPROTO
79 extern int lu_init();
80 extern LUENT *lu_find();
81 extern void lu_delete();
82 extern void lu_done();
83 extern unsigned long lu_shash();
84 #else
85 extern int lu_init(LUTAB *, int);
86 extern LUENT *lu_find(LUTAB *, char *);
87 extern void lu_delete(LUTAB *, char *);
88 extern void lu_done(LUTAB *);
89 extern unsigned long lu_shash(char *);
90 #endif