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.8 by greg, Sat Feb 22 02:07:22 2003 UTC vs.
Revision 2.17 by greg, Tue Apr 28 16:56:10 2015 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  External symbols declared in object.h
8   */
9  
10 < /* ====================================================================
11 < * The Radiance Software License, Version 1.0
12 < *
13 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
14 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
15 < *
16 < * Redistribution and use in source and binary forms, with or without
17 < * modification, are permitted provided that the following conditions
18 < * are met:
19 < *
20 < * 1. Redistributions of source code must retain the above copyright
21 < *         notice, this list of conditions and the following disclaimer.
22 < *
23 < * 2. Redistributions in binary form must reproduce the above copyright
24 < *       notice, this list of conditions and the following disclaimer in
25 < *       the documentation and/or other materials provided with the
26 < *       distribution.
27 < *
28 < * 3. The end-user documentation included with the redistribution,
29 < *           if any, must include the following acknowledgment:
30 < *             "This product includes Radiance software
31 < *                 (http://radsite.lbl.gov/)
32 < *                 developed by the Lawrence Berkeley National Laboratory
33 < *               (http://www.lbl.gov/)."
34 < *       Alternately, this acknowledgment may appear in the software itself,
35 < *       if and wherever such third-party acknowledgments normally appear.
36 < *
37 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
38 < *       and "The Regents of the University of California" must
39 < *       not be used to endorse or promote products derived from this
40 < *       software without prior written permission. For written
41 < *       permission, please contact [email protected].
42 < *
43 < * 5. Products derived from this software may not be called "Radiance",
44 < *       nor may "Radiance" appear in their name, without prior written
45 < *       permission of Lawrence Berkeley National Laboratory.
46 < *
47 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
48 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
51 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 < * SUCH DAMAGE.
59 < * ====================================================================
60 < *
61 < * This software consists of voluntary contributions made by many
62 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
63 < * information on Lawrence Berkeley National Laboratory, please see
64 < * <http://www.lbl.gov/>.
65 < */
10 > #include "copyright.h"
11  
12   #include  "standard.h"
13  
# Line 71 | Line 16 | static const char      RCSid[] = "$Id$";
16   #include  "object.h"
17  
18   #ifndef  OSTSIZ
19 < #ifdef  BIGMEM
75 < #define  OSTSIZ         262139          /* object table size (a prime!) */
76 < #else
19 > #ifdef  SMLMEM
20   #define  OSTSIZ         32749           /* object table size (a prime!) */
21 + #else
22 + #define  OSTSIZ         262139          /* object table size (a prime!) */
23   #endif
24   #endif
25  
26 + #undef xtra_long
27 + #ifdef _WIN64
28 + typedef unsigned long long int  xtra_long;
29 + #else
30 + typedef unsigned long int       xtra_long;
31 + #endif
32 +
33   static OBJECT  *ostable[OSTSIZ];        /* the object set table */
34  
35  
36   void
37 < insertelem(os, obj)             /* insert obj into os, no questions */
38 < register OBJECT  *os;
39 < OBJECT  obj;
37 > insertelem(                     /* insert obj into os, no questions */
38 >        OBJECT  *os,
39 >        OBJECT  obj
40 > )
41   {
42 <        register int  i;
42 >        int  i;
43          
44          for (i = os[0]++; i > 0; i--)
45                  if (os[i] > obj)
# Line 98 | Line 51 | OBJECT  obj;
51  
52  
53   void
54 < deletelem(os, obj)              /* delete obj from os, no questions */
55 < register OBJECT  *os;
56 < OBJECT  obj;
54 > deletelem(                      /* delete obj from os, no questions */
55 >        OBJECT  *os,
56 >        OBJECT  obj
57 > )
58   {
59 <        register int  i;
59 >        int  i;
60  
61          i = (*os)--;
62          os++;
# Line 118 | Line 72 | OBJECT  obj;
72  
73  
74   int
75 < inset(os, obj)                  /* determine if object is in set */
76 < register OBJECT  *os;
77 < OBJECT  obj;
75 > inset(                          /* determine if object is in set */
76 >        OBJECT  *os,
77 >        OBJECT  obj
78 > )
79   {
80          int  upper, lower;
81 <        register int  cm, i;
81 >        int  cm, i;
82  
83 <        if ((i = os[0]) <= 6) {         /* linear search algorithm */
83 >        if ((i = os[0]) <= 12) {        /* linear search algorithm */
84                  cm = obj;
85                  while (i-- > 0)
86                          if (*++os == cm)
# Line 150 | Line 105 | OBJECT  obj;
105  
106  
107   int
108 < setequal(os1, os2)              /* determine if two sets are equal */
109 < register OBJECT  *os1, *os2;
108 > setequal(                       /* determine if two sets are equal */
109 >        OBJECT  *os1,
110 >        OBJECT  *os2
111 > )
112   {
113 <        register int  i;
113 >        int  i;
114  
115          for (i = *os1; i-- >= 0; )
116                  if (*os1++ != *os2++)
# Line 163 | Line 120 | register OBJECT  *os1, *os2;
120  
121  
122   void
123 < setcopy(os1, os2)               /* copy object set os2 into os1 */
124 < register OBJECT  *os1, *os2;
123 > setcopy(                        /* copy object set os2 into os1 */
124 >        OBJECT  *os1,
125 >        OBJECT  *os2
126 > )
127   {
128 <        register int  i;
128 >        int  i;
129  
130          for (i = *os2; i-- >= 0; )
131                  *os1++ = *os2++;
# Line 174 | Line 133 | register OBJECT  *os1, *os2;
133  
134  
135   OBJECT *
136 < setsave(os)                     /* allocate space and save set */
137 < register OBJECT  *os;
136 > setsave(                        /* allocate space and save set */
137 >        OBJECT  *os
138 > )
139   {
140          OBJECT  *osnew;
141 <        register OBJECT  *oset;
142 <        register int  i;
141 >        OBJECT  *oset;
142 >        int  i;
143  
144          if ((osnew = oset = (OBJECT *)malloc((*os+1)*sizeof(OBJECT))) == NULL)
145                  error(SYSTEM, "out of memory in setsave\n");
# Line 190 | Line 150 | register OBJECT  *os;
150  
151  
152   void
153 < setunion(osr, os1, os2)         /* osr = os1 Union os2 */
154 < register OBJECT  *osr, *os1, *os2;
153 > setunion(                       /* osr = os1 Union os2 */
154 >        OBJECT  *osr,
155 >        OBJECT  *os1,
156 >        OBJECT  *os2
157 > )
158   {
159 <        register int    i1, i2;
159 >        int     i1, i2;
160  
161          osr[0] = 0;
162          for (i1 = i2 = 1; i1 <= os1[0] || i2 <= os2[0]; ) {
# Line 210 | Line 173 | register OBJECT  *osr, *os1, *os2;
173  
174  
175   void
176 < setintersect(osr, os1, os2)     /* osr = os1 Intersect os2 */
177 < register OBJECT  *osr, *os1, *os2;
176 > setintersect(                   /* osr = os1 Intersect os2 */
177 >        OBJECT  *osr,
178 >        OBJECT  *os1,
179 >        OBJECT  *os2
180 > )
181   {
182 <        register int    i1, i2;
182 >        int     i1, i2;
183  
184          osr[0] = 0;
185          if (os1[0] <= 0)
# Line 232 | Line 198 | register OBJECT  *osr, *os1, *os2;
198  
199  
200   OCTREE
201 < fullnode(oset)                  /* return octree for object set */
202 < OBJECT  *oset;
201 > fullnode(                       /* return octree for object set */
202 >        OBJECT  *oset
203 > )
204   {
205 <        int  osentry, ntries;
206 <        long  hval;
205 >        unsigned int  ntries;
206 >        xtra_long  hval;
207          OCTREE  ot;
208 <        register int  i;
209 <        register OBJECT  *os;
208 >        int  osentry, i;
209 >        OBJECT  *os;
210                                          /* hash on set */
211          hval = 0;
212          os = oset;
# Line 248 | Line 215 | OBJECT  *oset;
215                  hval += *os++;
216          ntries = 0;
217   tryagain:
218 <        osentry = (hval + (long)ntries*ntries) % OSTSIZ;
218 >        osentry = (hval + (xtra_long)ntries*ntries) % OSTSIZ;
219          os = ostable[osentry];
220          if (os == NULL) {
221                  os = ostable[osentry] = (OBJECT *)malloc(
# Line 264 | Line 231 | tryagain:
231                  ot = oseti(i*OSTSIZ + osentry);
232                  if (*os > 0)                    /* found it */
233                          return(ot);
234 <                if (!isfull(ot))                /* entry overflow */
234 >                if (!isfull(ot)) {              /* entry overflow */
235                          if (++ntries < OSTSIZ)
236                                  goto tryagain;
237                          else
238                                  error(INTERNAL, "hash table overflow in fullnode");
239 +                }
240                                                  /* remember position */
241                  i = os - ostable[osentry];
242                  os = ostable[osentry] = (OBJECT *)realloc(
243 <                                (char *)ostable[osentry],
243 >                                (void *)ostable[osentry],
244                                  (unsigned)(i+oset[0]+2)*sizeof(OBJECT));
245                  if (os == NULL)
246                          goto memerr;
# Line 284 | Line 252 | tryagain:
252          return(ot);
253   memerr:
254          error(SYSTEM, "out of memory in fullnode");
255 +        return 0; /* pro forma return */
256   }
257  
258  
259   void
260 < objset(oset, ot)                /* get object set for full node */
261 < register OBJECT  *oset;
262 < OCTREE  ot;
260 > objset(                 /* get object set for full node */
261 >        OBJECT  *oset,
262 >        OCTREE  ot
263 > )
264   {
265 <        register OBJECT  *os;
266 <        register int  i;
265 >        OBJECT  *os;
266 >        int  i;
267  
268          if (!isfull(ot))
269                  goto noderr;
# Line 311 | Line 281 | noderr:
281   }
282  
283  
314 int
315 dosets(f)                               /* loop through all sets */
316 int     (*f)();
317 {
318        int  res = 0;
319        int  n;
320        register OBJECT  *os;
321
322        for (n = 0; n < OSTSIZ; n++) {
323                if ((os = ostable[n]) == NULL)
324                        continue;
325                while (*os > 0) {
326                        res += (*f)(os);
327                        os += *os + 1;
328                }
329        }
330        return(res);
331 }
332
333
284   void
285 < donesets()                      /* free ALL SETS in our table */
285 > donesets(void)                  /* free ALL SETS in our table */
286   {
287 <        register int  n;
287 >        int  n;
288  
289          for (n = 0; n < OSTSIZ; n++)
290                  if (ostable[n] != NULL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines