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

Comparing ray/src/cv/mgflib/lookup.c (file contents):
Revision 1.6 by gregl, Wed Oct 8 11:16:58 1997 UTC vs.
Revision 1.7 by gwlarson, Fri Sep 4 09:05:09 1998 UTC

# Line 44 | Line 44 | int    nel;
44   }
45  
46  
47 < long
47 > unsigned long
48   lu_shash(s)                     /* hash a nul-terminated string */
49   char    *s;
50   {
# Line 75 | Line 75 | char   *s;
75                  41, 198, 99
76          };
77          register int    i = 0;
78 <        register long   h = 0;
78 >        register unsigned long  h = 0;
79          register unsigned char *t = (unsigned char *)s;
80  
81          while (*t)
# Line 90 | Line 90 | lu_find(tbl, key)              /* find a table entry */
90   register LUTAB  *tbl;
91   char    *key;
92   {
93 <        long    hval;
93 >        unsigned long   hval;
94          int     i, n;
95          register int    ndx;
96          register LUENT  *le;
97                                          /* look up object */
98 <        if (tbl->tsiz == 0)
99 <                lu_init(tbl, 1);
98 >        if (tbl->tsiz == 0 && !lu_init(tbl, 1))
99 >                return(NULL);
100          hval = (*tbl->hashf)(key);
101   tryagain:
102          ndx = hval % tbl->tsiz;
103        le = &tbl->tabl[ndx];
103          for (i = 0, n = 1; i < tbl->tsiz; i++, n += 2) {
104 +                le = &tbl->tabl[ndx];
105                  if (le->key == NULL) {
106                          le->hval = hval;
107                          return(le);
# Line 110 | Line 110 | tryagain:
110                        (tbl->keycmp == NULL || !(*tbl->keycmp)(le->key, key))) {
111                          return(le);
112                  }
113 <                le += n;
114 <                if ((ndx += n) >= tbl->tsiz) {  /* this happens rarely */
113 >                if ((ndx += n) >= tbl->tsiz)    /* this happens rarely */
114                          ndx = ndx % tbl->tsiz;
116                        le = &tbl->tabl[ndx];
117                }
115          }
116                                          /* table is full, reallocate */
117          le = tbl->tabl;
# Line 126 | Line 123 | tryagain:
123                  tbl->ndel = i;
124                  return(NULL);
125          }
129        if (!ndx)
130                goto tryagain;
126          /*
127           * The following code may fail if the user has reclaimed many
128           * deleted entries and the system runs out of memory in a

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines