ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/lookup.h
Revision: 1.8
Committed: Tue Mar 18 11:05:34 1997 UTC (27 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.7: +0 -2 lines
Log Message:
added fh entity and general cleanup

File Contents

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