ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/lookup.h
Revision: 2.5
Committed: Wed Sep 2 18:42:11 1998 UTC (25 years, 8 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 2.4: +13 -13 lines
Log Message:
changed lookup routines to use unsigned long hash values

File Contents

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