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.8 by greg, Fri Feb 28 20:11:29 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Table lookup routines
6   */
7  
8   #include <stdio.h>
9 + #include <stdlib.h>
10   #include "lookup.h"
11  
12   #ifndef MEM_PTR
13   #define MEM_PTR         void *
14   #endif
15  
18 extern MEM_PTR  calloc();
16  
20
17   int
18   lu_init(tbl, nel)               /* initialize tbl for at least nel elements */
19   register LUTAB  *tbl;
# Line 44 | Line 40 | int    nel;
40   }
41  
42  
43 < long
43 > unsigned long
44   lu_shash(s)                     /* hash a nul-terminated string */
45   char    *s;
46   {
# Line 75 | Line 71 | char   *s;
71                  41, 198, 99
72          };
73          register int    i = 0;
74 <        register long   h = 0;
74 >        register unsigned long  h = 0;
75          register unsigned char *t = (unsigned char *)s;
76  
77          while (*t)
# Line 90 | Line 86 | lu_find(tbl, key)              /* find a table entry */
86   register LUTAB  *tbl;
87   char    *key;
88   {
89 <        long    hval;
89 >        unsigned long   hval;
90          int     i, n;
91          register int    ndx;
92          register LUENT  *le;
93                                          /* look up object */
94 <        if (tbl->tsiz == 0)
95 <                lu_init(tbl, 1);
94 >        if (tbl->tsiz == 0 && !lu_init(tbl, 1))
95 >                return(NULL);
96          hval = (*tbl->hashf)(key);
97   tryagain:
98          ndx = hval % tbl->tsiz;
103        le = &tbl->tabl[ndx];
99          for (i = 0, n = 1; i < tbl->tsiz; i++, n += 2) {
100 +                le = &tbl->tabl[ndx];
101                  if (le->key == NULL) {
102                          le->hval = hval;
103                          return(le);
# Line 110 | Line 106 | tryagain:
106                        (tbl->keycmp == NULL || !(*tbl->keycmp)(le->key, key))) {
107                          return(le);
108                  }
109 <                le += n;
114 <                if ((ndx += n) >= tbl->tsiz) {  /* this happens rarely */
109 >                if ((ndx += n) >= tbl->tsiz)    /* this happens rarely */
110                          ndx = ndx % tbl->tsiz;
116                        le = &tbl->tabl[ndx];
117                }
111          }
112                                          /* table is full, reallocate */
113          le = tbl->tabl;
# Line 126 | Line 119 | tryagain:
119                  tbl->ndel = i;
120                  return(NULL);
121          }
129        if (!ndx)
130                goto tryagain;
122          /*
123           * The following code may fail if the user has reclaimed many
124           * deleted entries and the system runs out of memory in a

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines