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.3 by gregl, Wed Dec 3 10:59:30 1997 UTC vs.
Revision 2.5 by gwlarson, Thu Sep 3 14:22:23 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ SGI";
11   #include <stdio.h>
12   #include "lookup.h"
13  
14 + #ifdef  NOSTRUCTASS
15 + #define  copystruct(d,s)        bcopy((char *)(s),(char *)(d),sizeof(*(d)))
16 + #else
17 + #define  copystruct(d,s)        (*(d) = *(s))
18 + #endif
19 +
20   #define MEM_PTR         char *
21  
22   extern MEM_PTR  calloc();
# Line 42 | Line 48 | int    nel;
48   }
49  
50  
51 < long
51 > unsigned long
52   lu_shash(s)                     /* hash a nul-terminated string */
53   char    *s;
54   {
# Line 73 | Line 79 | char   *s;
79                  41, 198, 99
80          };
81          register int    i = 0;
82 <        register long   h = 0;
82 >        register unsigned long  h = 0;
83          register unsigned char *t = (unsigned char *)s;
84  
85          while (*t)
86 <                h ^= (long)shuffle[*t++] << ((i+=11) & 0xf);
86 >                h ^= (unsigned long)shuffle[*t++] << ((i+=11) & 0xf);
87  
88          return(h);
89   }
# Line 88 | Line 94 | lu_find(tbl, key)              /* find a table entry */
94   register LUTAB  *tbl;
95   char    *key;
96   {
97 <        long    hval;
97 >        unsigned long   hval;
98          int     i, n;
99          register int    ndx;
100          register LUENT  *le;
101                                          /* look up object */
102 <        if (tbl->tsiz == 0)
103 <                lu_init(tbl, 1);
102 >        if (tbl->tsiz == 0 && !lu_init(tbl, 1))
103 >                return(NULL);
104          hval = (*tbl->hashf)(key);
105   tryagain:
106          ndx = hval % tbl->tsiz;
101        le = &tbl->tabl[ndx];
107          for (i = 0, n = 1; i < tbl->tsiz; i++, n += 2) {
108 +                le = &tbl->tabl[ndx];
109                  if (le->key == NULL) {
110                          le->hval = hval;
111                          return(le);
# Line 108 | Line 114 | tryagain:
114                        (tbl->keycmp == NULL || !(*tbl->keycmp)(le->key, key))) {
115                          return(le);
116                  }
117 <                le += n;
112 <                if ((ndx += n) >= tbl->tsiz) {  /* this happens rarely */
117 >                if ((ndx += n) >= tbl->tsiz)    /* this happens rarely */
118                          ndx = ndx % tbl->tsiz;
114                        le = &tbl->tabl[ndx];
115                }
119          }
120                                          /* table is full, reallocate */
121          le = tbl->tabl;
# Line 124 | Line 127 | tryagain:
127                  tbl->ndel = i;
128                  return(NULL);
129          }
127        if (!ndx)
128                goto tryagain;
130          /*
131           * The following code may fail if the user has reclaimed many
132           * deleted entries and the system runs out of memory in a
# Line 134 | Line 135 | tryagain:
135          while (ndx--)
136                  if (le[ndx].key != NULL)
137                          if (le[ndx].data != NULL)
138 <                                *lu_find(tbl, le[ndx].key) = le[ndx];
138 >                                copystruct(lu_find(tbl,le[ndx].key), &le[ndx]);
139                          else if (tbl->freek != NULL)
140                                  (*tbl->freek)(le[ndx].key);
141          free((MEM_PTR)le);
# Line 157 | Line 158 | char   *key;
158                  (*tbl->freed)(le->data);
159          le->data = NULL;
160          tbl->ndel++;
161 + }
162 +
163 +
164 + int
165 + lu_doall(tbl, f)                /* loop through all valid table entries */
166 + register LUTAB  *tbl;
167 + int     (*f)();
168 + {
169 +        int     rval = 0;
170 +        register LUENT  *tp;
171 +
172 +        for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; )
173 +                if (tp->data != NULL)
174 +                        if (f != NULL)
175 +                                rval += (*f)(tp);
176 +                        else
177 +                                rval++;
178 +        return(rval);
179   }
180  
181  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines