ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/lookup.h
Revision: 1.4
Committed: Sat Jun 25 16:34:50 1994 UTC (29 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +30 -18 lines
Log Message:
enhancements for general (non-string) associations

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