ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/lookup.h
(Generate patch)

Comparing ray/src/cv/mgflib/lookup.h (file contents):
Revision 1.3 by greg, Sat Jun 25 09:47:57 1994 UTC vs.
Revision 1.11 by schorsch, Sat Jun 7 01:11:17 2003 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1994 Regents of the University of California */
2 <
3 < /* SCCSid "$SunId$ LBL" */
4 <
1 > /* RCSid: $Id$ */
2   /*
3 < * Header file for table lookup routines
3 > * Header file for general associative table lookup routines
4   */
5 + #ifndef _MGF_LOOKUP_H_
6 + #define _MGF_LOOKUP_H_
7 + #ifdef __cplusplus
8 + extern "C" {
9 + #endif
10  
11 +
12   typedef struct {
13 <        char    *key;           /* key name (dynamically allocated) */
13 >        char    *key;           /* key name */
14 >        long    hval;           /* key hash value (for efficiency) */
15          char    *data;          /* pointer to client data */
16   } LUENT;
17  
18   typedef struct {
19 <        void    (*freek)();     /* free entry key */
20 <        void    (*freed)();     /* free entry data */
19 >        unsigned long   (*hashf)(char *);       /* key hash function */
20 >        int     (*keycmp)(const char *, const char *);  /* key comparison function */
21 >        void    (*freek)(char *);       /* free a key */
22 >        void    (*freed)(char *);       /* free the data */
23          int     tsiz;           /* current table size */
24          LUENT   *tabl;          /* table, if allocated */
25          int     ndel;           /* number of deleted entries */
26   } LUTAB;
27  
28 < #define LU_SINIT(fk,fd)         {(void (*)())(fk),(void (*)())(fd),0,NULL,0}
28 > #define LU_SINIT(fk,fd)         {lu_shash,strcmp,(void (*)())(fk),\
29 >                                (void (*)())(fd),0,NULL,0}
30  
31   /*
32   * The lu_init routine is called to initialize a table.  The number of
# Line 29 | Line 36 | typedef struct {
36   * and the expected (minimum) table size.  The value returned is the
37   * actual allocated table size (or zero if there was insufficient memory).
38   *
39 < * It isn't fully necessary to initialize the LUTAB structure.  If it
40 < * is cleared (tsiz = 0, tabl = NULL), then the first call to lu_find
41 < * will allocate a minimal table.  If key and data free functions are
42 < * to be used, the LU_SINIT macro provides a convenient declaration.
39 > * The hashf, keycmp, freek and freed member functions must be assigned
40 > * separately.  If the hash value is sufficient to guarantee equality
41 > * between keys, then the keycmp pointer may be NULL.  Otherwise, it
42 > * should return 0 if the two passed keys match.  If it is not necessary
43 > * (or possible) to free the key and/or data values, then the freek and/or
44 > * freed member functions may be NULL.
45   *
46 + * It isn't fully necessary to call lu_init to initialize the LUTAB structure.
47 + * If tsiz is 0, then the first call to lu_find will allocate a minimal table.
48 + * The LU_SINIT macro provides a convenient static declaration for character
49 + * string keys.
50 + *
51   * The lu_find routine returns the entry corresponding to the given
52 < * key (any nul-terminated string).  If the entry does not exist, the
53 < * corresponding key field will be NULL.  If the entry has been
54 < * previously deleted but not yet freed, then only the data field
55 < * will be NULL.  It is the caller's responsibility to (allocate and)
56 < * assign the key and data fields when creating a new entry.
57 < * The only case where lu_find returns NULL is when the system
44 < * has run out of memory.
52 > * key.  If the entry does not exist, the corresponding key field will
53 > * be NULL.  If the entry has been previously deleted but not yet freed,
54 > * then only the data field will be NULL.  It is the caller's
55 > * responsibility to (allocate and) assign the key and data fields when
56 > * creating a new entry.  The only case where lu_find returns NULL is when
57 > * the system has run out of memory.
58   *
59   * The lu_delete routine frees an entry's data (if any) by calling
60   * the freed member function, but does not free the key field.  This
61   * will be freed later during (or instead of) table reallocation.
62 + * It is therefore an error to reuse or do anything with the key
63 + * field after calling lu_delete.
64   *
65   * The lu_done routine calls the given free function once for each
66   * assigned table entry (i.e. each entry with an assigned key value).
# Line 54 | Line 69 | typedef struct {
69   * allocated table itself.
70   */
71  
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
72   extern int      lu_init(LUTAB *, int);
73   extern LUENT    *lu_find(LUTAB *, char *);
74   extern void     lu_delete(LUTAB *, char *);
75   extern void     lu_done(LUTAB *);
76 < extern int      lu_hash(char *);
76 > extern unsigned long    lu_shash(char *);
77 >
78 >
79 > #ifdef __cplusplus
80 > }
81   #endif
82 + #endif /* _MGF_LOOKUP_H_ */
83 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines