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.11 by schorsch, Wed Jul 30 10:11:06 2003 UTC vs.
Revision 2.16 by schorsch, Wed Jun 7 17:52:03 2006 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 + #include <string.h>
11  
12   #include "lookup.h"
13  
14 + extern int
15 + lu_strcmp(
16 +        const void *s1,
17 +        const void *s2
18 + )
19 + {
20 +        return strcmp((const char*)s1,(const char*)s2);
21 + }
22  
23 < int
24 < lu_init(tbl, nel)               /* initialize tbl for at least nel elements */
25 < register LUTAB  *tbl;
26 < int     nel;
23 > extern int
24 > lu_init(                /* initialize tbl for at least nel elements */
25 >        register LUTAB  *tbl,
26 >        int     nel
27 > )
28   {
29          static int  hsiztab[] = {
30                  31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
# Line 39 | Line 47 | int    nel;
47   }
48  
49  
50 < unsigned long
51 < lu_shash(s)                     /* hash a nul-terminated string */
52 < char    *s;
50 > extern unsigned long
51 > lu_shash(                       /* hash a nul-terminated string */
52 >        const void      *s
53 > )
54   {
55          static unsigned char shuffle[256] = {
56                  0, 157, 58, 215, 116, 17, 174, 75, 232, 133, 34,
# Line 71 | Line 80 | char   *s;
80          };
81          register int    i = 0;
82          register unsigned long  h = 0;
83 <        register unsigned char *t = (unsigned char *)s;
83 >        register unsigned const char *t = (unsigned const char *)s;
84  
85          while (*t)
86                  h ^= (unsigned long)shuffle[*t++] << ((i+=11) & 0xf);
# Line 80 | Line 89 | char   *s;
89   }
90  
91  
92 < LUENT *
93 < lu_find(tbl, key)               /* find a table entry */
94 < register LUTAB  *tbl;
95 < char    *key;
92 > extern LUENT *
93 > lu_find(                /* find a table entry */
94 >        register LUTAB  *tbl,
95 >        const char      *key
96 > )
97   {
98          unsigned long   hval;
99          int     i, n;
# Line 135 | Line 145 | tryagain:
145   }
146  
147  
148 < void
149 < lu_delete(tbl, key)             /* delete a table entry */
150 < register LUTAB  *tbl;
151 < char    *key;
148 > extern void
149 > lu_delete(              /* delete a table entry */
150 >        register LUTAB  *tbl,
151 >        const char      *key
152 > )
153   {
154          register LUENT  *le;
155  
# Line 153 | Line 164 | char   *key;
164   }
165  
166  
167 < int
168 < lu_doall(tbl, f)                /* loop through all valid table entries */
169 < register LUTAB  *tbl;
170 < int     (*f)(LUENT *);
167 > extern int
168 > lu_doall(               /* loop through all valid table entries */
169 >        register const LUTAB    *tbl,
170 >        //int   (*f)(const LUENT *)
171 >        lut_doallf_t *f,
172 >        void *p
173 > )
174   {
175          int     rval = 0;
176 <        register LUENT  *tp;
176 >        register const LUENT    *tp;
177  
178          for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; )
179                  if (tp->data != NULL) {
180 <                        if (f != NULL)
181 <                                rval += (*f)(tp);
182 <                        else
180 >                        if (f != NULL) {
181 >                                int     r = (*f)(tp, p);
182 >                                if (r < 0)
183 >                                        return(-1);
184 >                                rval += r;
185 >                        } else
186                                  rval++;
187                  }
188          return(rval);
189   }
190  
191  
192 < void
193 < lu_done(tbl)                    /* free table and contents */
194 < register LUTAB  *tbl;
192 > extern void
193 > lu_done(                        /* free table and contents */
194 >        register LUTAB  *tbl
195 > )
196   {
197          register LUENT  *tp;
198  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines