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

Comparing ray/src/rt/data.c (file contents):
Revision 2.5 by greg, Sun Nov 22 10:02:57 1992 UTC vs.
Revision 2.6 by greg, Sun Nov 22 10:47:51 1992 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19   #include  "data.h"
20  
21  
22 + #define TABSIZ          97              /* table size (prime) */
23 +
24 + #define hash(s)         (shash(s)%TABSIZ)
25 +
26 +
27   extern char  *fgetword();
28  
29   extern char  *libpath;                  /* library search path */
30  
31 < static DATARRAY  *dlist = NULL;         /* data array list */
31 > static DATARRAY  *dtab[TABSIZ];         /* data array list */
32  
33 < static DATARRAY  *plist = NULL;         /* picture list */
33 > static DATARRAY  *ptab[TABSIZ];         /* picture list */
34  
35  
36   DATARRAY *
# Line 39 | Line 44 | char  *dname;
44          register int  i, j;
45          register DATARRAY  *dp;
46                                                  /* look for array in list */
47 <        for (dp = dlist; dp != NULL; dp = dp->next)
47 >        for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next)
48                  if (!strcmp(dname, dp->name))
49                          return(dp);             /* found! */
50  
# Line 127 | Line 132 | char  *dname;
132                  dp->arr[i] = atof(word);
133          }
134          fclose(fp);
135 <        dp->next = dlist;
136 <        return(dlist = dp);
135 >        i = hash(dname);
136 >        dp->next = dtab[i];
137 >        return(dtab[i] = dp);
138  
139   memerr:
140          error(SYSTEM, "out of memory in getdata");
# Line 165 | Line 171 | char  *pname;
171          register int  x, i;
172          register DATARRAY  *pp;
173                                                  /* look for array in list */
174 <        for (pp = plist; pp != NULL; pp = pp->next)
174 >        for (pp = ptab[hash(pname)]; pp != NULL; pp = pp->next)
175                  if (!strcmp(pname, pp->name))
176                          return(pp);             /* found! */
177  
# Line 232 | Line 238 | char  *pname;
238          }
239          free((char *)scanin);
240          fclose(fp);
241 +        i = hash(pname);
242          pp[0].next =
243          pp[1].next =
244 <        pp[2].next = plist;
245 <        return(plist = pp);
244 >        pp[2].next = ptab[i];
245 >        return(ptab[i] = pp);
246  
247   memerr:
248          error(SYSTEM, "out of memory in getpict");
# Line 249 | Line 256 | freedata(dname)                        /* free memory associated with dname
256   char  *dname;
257   {
258          DATARRAY  head;
259 +        int  hval, nents;
260          register DATARRAY  *dp, *dpl;
261          register int  i;
262  
263 <        head.next = dlist;
264 <        dpl = &head;
265 <        while ((dp = dpl->next) != NULL)
266 <                if (dname == NULL || !strcmp(dname, dp->name)) {
267 <                        dpl->next = dp->next;
268 <                        free((char *)dp->arr);
269 <                        for (i = 0; i < dp->nd; i++)
270 <                                if (dp->dim[i].p != NULL)
271 <                                        free((char *)dp->dim[i].p);
272 <                        freestr(dp->name);
273 <                        free((char *)dp);
274 <                } else
275 <                        dpl = dp;
276 <        dlist = head.next;
263 >        if (dname == NULL) {                    /* free all if NULL */
264 >                hval = 0; nents = TABSIZ;
265 >        } else {
266 >                hval = hash(dname); nents = 1;
267 >        }
268 >        while (nents--) {
269 >                head.next = dtab[hval];
270 >                dpl = &head;
271 >                while ((dp = dpl->next) != NULL)
272 >                        if (dname == NULL || !strcmp(dname, dp->name)) {
273 >                                dpl->next = dp->next;
274 >                                free((char *)dp->arr);
275 >                                for (i = 0; i < dp->nd; i++)
276 >                                        if (dp->dim[i].p != NULL)
277 >                                                free((char *)dp->dim[i].p);
278 >                                freestr(dp->name);
279 >                                free((char *)dp);
280 >                        } else
281 >                                dpl = dp;
282 >                dtab[hval++] = head.next;
283 >        }
284   }
285  
286  
# Line 273 | Line 288 | freepict(pname)                        /* free memory associated with pname
288   char  *pname;
289   {
290          DATARRAY  head;
291 +        int  hval, nents;
292          register DATARRAY  *pp, *ppl;
293  
294 <        head.next = plist;
295 <        ppl = &head;
296 <        while ((pp = ppl->next) != NULL)
297 <                if (pname == NULL || !strcmp(pname, pp->name)) {
298 <                        ppl->next = pp->next;
299 <                        free((char *)pp[0].arr);
300 <                        free((char *)pp[1].arr);
301 <                        free((char *)pp[2].arr);
302 <                        freestr(pp[0].name);
303 <                        free((char *)pp);
304 <                } else
305 <                        ppl = pp;
306 <        plist = head.next;
294 >        if (pname == NULL) {                    /* free all if NULL */
295 >                hval = 0; nents = TABSIZ;
296 >        } else {
297 >                hval = hash(pname); nents = 1;
298 >        }
299 >        while (nents--) {
300 >                head.next = ptab[hval];
301 >                ppl = &head;
302 >                while ((pp = ppl->next) != NULL)
303 >                        if (pname == NULL || !strcmp(pname, pp->name)) {
304 >                                ppl->next = pp->next;
305 >                                free((char *)pp[0].arr);
306 >                                free((char *)pp[1].arr);
307 >                                free((char *)pp[2].arr);
308 >                                freestr(pp[0].name);
309 >                                free((char *)pp);
310 >                        } else
311 >                                ppl = pp;
312 >                ptab[hval++] = head.next;
313 >        }
314   }
315  
316  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines