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

Comparing ray/src/common/objset.c (file contents):
Revision 2.4 by greg, Fri Mar 7 15:45:28 1997 UTC vs.
Revision 2.12 by schorsch, Sat Jun 7 12:50:20 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 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   *  objset.c - routines for maintaining object sets.
6   *
7 < *      7/28/85
7 > *  External symbols declared in object.h
8   */
9  
10 + #include "copyright.h"
11 +
12   #include  "standard.h"
13  
14   #include  "octree.h"
# Line 17 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16   #include  "object.h"
17  
18   #ifndef  OSTSIZ
19 < #ifdef  BIGMEM
20 < #define  OSTSIZ         56437           /* object table size (a prime!) */
19 > #ifdef  SMLMEM
20 > #define  OSTSIZ         32749           /* object table size (a prime!) */
21   #else
22 < #define  OSTSIZ         12329           /* object table size (a prime!) */
22 > #define  OSTSIZ         262139          /* object table size (a prime!) */
23   #endif
24   #endif
25  
26   static OBJECT  *ostable[OSTSIZ];        /* the object set table */
27  
28  
29 + void
30   insertelem(os, obj)             /* insert obj into os, no questions */
31   register OBJECT  *os;
32   OBJECT  obj;
# Line 42 | Line 42 | OBJECT  obj;
42   }
43  
44  
45 + void
46   deletelem(os, obj)              /* delete obj from os, no questions */
47   register OBJECT  *os;
48   OBJECT  obj;
# Line 61 | Line 62 | OBJECT  obj;
62   }
63  
64  
65 + int
66   inset(os, obj)                  /* determine if object is in set */
67   register OBJECT  *os;
68   OBJECT  obj;
# Line 68 | Line 70 | OBJECT  obj;
70          int  upper, lower;
71          register int  cm, i;
72  
73 +        if ((i = os[0]) <= 6) {         /* linear search algorithm */
74 +                cm = obj;
75 +                while (i-- > 0)
76 +                        if (*++os == cm)
77 +                                return(1);
78 +                return(0);
79 +        }
80          lower = 1;
81 <        upper = cm = os[0] + 1;
81 >        upper = cm = i + 1;
82                                          /* binary search algorithm */
83          while ((i = (lower + upper) >> 1) != cm) {
84                  cm = obj - os[i];
# Line 85 | Line 94 | OBJECT  obj;
94   }
95  
96  
97 + int
98   setequal(os1, os2)              /* determine if two sets are equal */
99   register OBJECT  *os1, *os2;
100   {
# Line 97 | Line 107 | register OBJECT  *os1, *os2;
107   }
108  
109  
110 + void
111   setcopy(os1, os2)               /* copy object set os2 into os1 */
112   register OBJECT  *os1, *os2;
113   {
# Line 123 | Line 134 | register OBJECT  *os;
134   }
135  
136  
137 + void
138   setunion(osr, os1, os2)         /* osr = os1 Union os2 */
139   register OBJECT  *osr, *os1, *os2;
140   {
# Line 142 | Line 154 | register OBJECT  *osr, *os1, *os2;
154   }
155  
156  
157 + void
158   setintersect(osr, os1, os2)     /* osr = os1 Intersect os2 */
159   register OBJECT  *osr, *os1, *os2;
160   {
# Line 204 | Line 217 | tryagain:
217                                                  /* remember position */
218                  i = os - ostable[osentry];
219                  os = ostable[osentry] = (OBJECT *)realloc(
220 <                                (char *)ostable[osentry],
220 >                                (void *)ostable[osentry],
221                                  (unsigned)(i+oset[0]+2)*sizeof(OBJECT));
222                  if (os == NULL)
223                          goto memerr;
# Line 216 | Line 229 | tryagain:
229          return(ot);
230   memerr:
231          error(SYSTEM, "out of memory in fullnode");
232 +        return NULL; /* pro forma return */
233   }
234  
235  
236 + void
237   objset(oset, ot)                /* get object set for full node */
238   register OBJECT  *oset;
239   OCTREE  ot;
# Line 228 | Line 243 | OCTREE  ot;
243  
244          if (!isfull(ot))
245                  goto noderr;
246 <        i = oseti(ot);
247 <        if ((os = ostable[i%OSTSIZ]) == NULL)
246 >        ot = oseti(ot);
247 >        if ((os = ostable[ot%OSTSIZ]) == NULL)
248                  goto noderr;
249 <        for (i /= OSTSIZ; i--; os += *os + 1)
249 >        for (i = ot/OSTSIZ; i--; os += *os + 1)
250                  if (*os <= 0)
251                          goto noderr;
252          for (i = *os; i-- >= 0; )               /* copy set here */
# Line 262 | Line 277 | int    (*f)();
277   }
278  
279  
280 + void
281   donesets()                      /* free ALL SETS in our table */
282   {
283          register int  n;
284  
285          for (n = 0; n < OSTSIZ; n++)
286                  if (ostable[n] != NULL) {
287 <                        free((char *)ostable[n]);
287 >                        free((void *)ostable[n]);
288                          ostable[n] = NULL;
289                  }
290   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines