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

Comparing ray/src/common/lookup.c (file contents):
Revision 2.7 by greg, Tue Feb 25 02:47:21 2003 UTC vs.
Revision 2.14 by greg, Tue May 25 06:30:46 2004 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   * Table lookup routines
6   */
7  
8 #include "copyright.h"
9
8   #include <stdio.h>
9   #include <stdlib.h>
10 +
11   #include "lookup.h"
12  
13 < #ifdef  NOSTRUCTASS
14 < #define  copystruct(d,s)        bcopy((char *)(s),(char *)(d),sizeof(*(d)))
15 < #else
16 < #define  copystruct(d,s)        (*(d) = *(s))
17 < #endif
13 > extern int
14 > lu_strcmp(
15 >        const void *s1,
16 >        const void *s2
17 > )
18 > {
19 >        return strcmp((const char*)s1,(const char*)s2);
20 > }
21  
22 <
23 < int
24 < lu_init(tbl, nel)               /* initialize tbl for at least nel elements */
25 < register LUTAB  *tbl;
26 < int     nel;
22 > extern int
23 > lu_init(                /* initialize tbl for at least nel elements */
24 >        register LUTAB  *tbl,
25 >        int     nel
26 > )
27   {
28          static int  hsiztab[] = {
29                  31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
# Line 44 | Line 46 | int    nel;
46   }
47  
48  
49 < unsigned long
50 < lu_shash(s)                     /* hash a nul-terminated string */
51 < char    *s;
49 > extern unsigned long
50 > lu_shash(                       /* hash a nul-terminated string */
51 >        void    *s
52 > )
53   {
54          static unsigned char shuffle[256] = {
55                  0, 157, 58, 215, 116, 17, 174, 75, 232, 133, 34,
# Line 85 | Line 88 | char   *s;
88   }
89  
90  
91 < LUENT *
92 < lu_find(tbl, key)               /* find a table entry */
93 < register LUTAB  *tbl;
94 < char    *key;
91 > extern LUENT *
92 > lu_find(                /* find a table entry */
93 >        register LUTAB  *tbl,
94 >        char    *key
95 > )
96   {
97          unsigned long   hval;
98          int     i, n;
# Line 129 | Line 133 | tryagain:
133           * recursive call to lu_find().
134           */
135          while (ndx--)
136 <                if (le[ndx].key != NULL)
136 >                if (le[ndx].key != NULL) {
137                          if (le[ndx].data != NULL)
138 <                                copystruct(lu_find(tbl,le[ndx].key), &le[ndx]);
138 >                                *lu_find(tbl,le[ndx].key) = le[ndx];
139                          else if (tbl->freek != NULL)
140                                  (*tbl->freek)(le[ndx].key);
141 +                }
142          free((void *)le);
143          goto tryagain;                  /* should happen only once! */
144   }
145  
146  
147 < void
148 < lu_delete(tbl, key)             /* delete a table entry */
149 < register LUTAB  *tbl;
150 < char    *key;
147 > extern void
148 > lu_delete(              /* delete a table entry */
149 >        register LUTAB  *tbl,
150 >        char    *key
151 > )
152   {
153          register LUENT  *le;
154  
# Line 157 | Line 163 | char   *key;
163   }
164  
165  
166 < int
167 < lu_doall(tbl, f)                /* loop through all valid table entries */
168 < register LUTAB  *tbl;
169 < int     (*f)();
166 > extern int
167 > lu_doall(               /* loop through all valid table entries */
168 >        register LUTAB  *tbl,
169 >        //int   (*f)(LUENT *)
170 >        lut_doallf_t *f,
171 >        void *p
172 > )
173   {
174          int     rval = 0;
175          register LUENT  *tp;
176  
177          for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; )
178 <                if (tp->data != NULL)
179 <                        if (f != NULL)
180 <                                rval += (*f)(tp);
181 <                        else
178 >                if (tp->data != NULL) {
179 >                        if (f != NULL) {
180 >                                int     r = (*f)(tp, p);
181 >                                if (r < 0)
182 >                                        return(-1);
183 >                                rval += r;
184 >                        } else
185                                  rval++;
186 +                }
187          return(rval);
188   }
189  
190  
191 < void
192 < lu_done(tbl)                    /* free table and contents */
193 < register LUTAB  *tbl;
191 > extern void
192 > lu_done(                        /* free table and contents */
193 >        register LUTAB  *tbl
194 > )
195   {
196          register LUENT  *tp;
197  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines