| 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" |
| 15 |
|
|
| 16 |
|
#include "object.h" |
| 17 |
|
|
| 19 |
– |
#include "otypes.h" |
| 20 |
– |
|
| 18 |
|
#ifndef OSTSIZ |
| 19 |
< |
#define OSTSIZ 12329 /* object table size (a prime!) */ |
| 19 |
> |
#ifdef BIGMEM |
| 20 |
> |
#define OSTSIZ 262139 /* object table size (a prime!) */ |
| 21 |
> |
#else |
| 22 |
> |
#define OSTSIZ 32749 /* 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; |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
|
| 45 |
+ |
void |
| 46 |
|
deletelem(os, obj) /* delete obj from os, no questions */ |
| 47 |
|
register OBJECT *os; |
| 48 |
|
OBJECT obj; |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
|
| 65 |
+ |
int |
| 66 |
|
inset(os, obj) /* determine if object is in set */ |
| 67 |
|
register OBJECT *os; |
| 68 |
|
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; |
| 82 |
< |
|
| 81 |
> |
upper = cm = i + 1; |
| 82 |
> |
/* binary search algorithm */ |
| 83 |
|
while ((i = (lower + upper) >> 1) != cm) { |
| 84 |
|
cm = obj - os[i]; |
| 85 |
|
if (cm > 0) |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
|
| 97 |
+ |
int |
| 98 |
|
setequal(os1, os2) /* determine if two sets are equal */ |
| 99 |
|
register OBJECT *os1, *os2; |
| 100 |
|
{ |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
+ |
void |
| 111 |
|
setcopy(os1, os2) /* copy object set os2 into os1 */ |
| 112 |
|
register OBJECT *os1, *os2; |
| 113 |
|
{ |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
+ |
OBJECT * |
| 122 |
+ |
setsave(os) /* allocate space and save set */ |
| 123 |
+ |
register OBJECT *os; |
| 124 |
+ |
{ |
| 125 |
+ |
OBJECT *osnew; |
| 126 |
+ |
register OBJECT *oset; |
| 127 |
+ |
register int i; |
| 128 |
+ |
|
| 129 |
+ |
if ((osnew = oset = (OBJECT *)malloc((*os+1)*sizeof(OBJECT))) == NULL) |
| 130 |
+ |
error(SYSTEM, "out of memory in setsave\n"); |
| 131 |
+ |
for (i = *os; i-- >= 0; ) /* inline setcopy */ |
| 132 |
+ |
*oset++ = *os++; |
| 133 |
+ |
return(osnew); |
| 134 |
+ |
} |
| 135 |
+ |
|
| 136 |
+ |
|
| 137 |
+ |
void |
| 138 |
+ |
setunion(osr, os1, os2) /* osr = os1 Union os2 */ |
| 139 |
+ |
register OBJECT *osr, *os1, *os2; |
| 140 |
+ |
{ |
| 141 |
+ |
register int i1, i2; |
| 142 |
+ |
|
| 143 |
+ |
osr[0] = 0; |
| 144 |
+ |
for (i1 = i2 = 1; i1 <= os1[0] || i2 <= os2[0]; ) { |
| 145 |
+ |
while (i1 <= os1[0] && (i2 > os2[0] || os1[i1] <= os2[i2])) { |
| 146 |
+ |
osr[++osr[0]] = os1[i1]; |
| 147 |
+ |
if (i2 <= os2[0] && os2[i2] == os1[i1]) |
| 148 |
+ |
i2++; |
| 149 |
+ |
i1++; |
| 150 |
+ |
} |
| 151 |
+ |
while (i2 <= os2[0] && (i1 > os1[0] || os2[i2] < os1[i1])) |
| 152 |
+ |
osr[++osr[0]] = os2[i2++]; |
| 153 |
+ |
} |
| 154 |
+ |
} |
| 155 |
+ |
|
| 156 |
+ |
|
| 157 |
+ |
void |
| 158 |
+ |
setintersect(osr, os1, os2) /* osr = os1 Intersect os2 */ |
| 159 |
+ |
register OBJECT *osr, *os1, *os2; |
| 160 |
+ |
{ |
| 161 |
+ |
register int i1, i2; |
| 162 |
+ |
|
| 163 |
+ |
osr[0] = 0; |
| 164 |
+ |
if (os1[0] <= 0) |
| 165 |
+ |
return; |
| 166 |
+ |
for (i1 = i2 = 1; i2 <= os2[0]; ) { |
| 167 |
+ |
while (os1[i1] < os2[i2]) |
| 168 |
+ |
if (++i1 > os1[0]) |
| 169 |
+ |
return; |
| 170 |
+ |
while (os2[i2] < os1[i1]) |
| 171 |
+ |
if (++i2 > os2[0]) |
| 172 |
+ |
return; |
| 173 |
+ |
if (os1[i1] == os2[i2]) |
| 174 |
+ |
osr[++osr[0]] = os2[i2++]; |
| 175 |
+ |
} |
| 176 |
+ |
} |
| 177 |
+ |
|
| 178 |
+ |
|
| 179 |
|
OCTREE |
| 180 |
|
fullnode(oset) /* return octree for object set */ |
| 181 |
|
OBJECT *oset; |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
|
| 235 |
+ |
void |
| 236 |
|
objset(oset, ot) /* get object set for full node */ |
| 237 |
|
register OBJECT *oset; |
| 238 |
|
OCTREE ot; |
| 242 |
|
|
| 243 |
|
if (!isfull(ot)) |
| 244 |
|
goto noderr; |
| 245 |
< |
i = oseti(ot); |
| 246 |
< |
if ((os = ostable[i%OSTSIZ]) == NULL) |
| 245 |
> |
ot = oseti(ot); |
| 246 |
> |
if ((os = ostable[ot%OSTSIZ]) == NULL) |
| 247 |
|
goto noderr; |
| 248 |
< |
for (i /= OSTSIZ; i--; os += *os + 1) |
| 248 |
> |
for (i = ot/OSTSIZ; i--; os += *os + 1) |
| 249 |
|
if (*os <= 0) |
| 250 |
|
goto noderr; |
| 251 |
|
for (i = *os; i-- >= 0; ) /* copy set here */ |
| 256 |
|
} |
| 257 |
|
|
| 258 |
|
|
| 259 |
< |
nonsurfinset(orig, nobjs) /* check sets for non-surfaces */ |
| 260 |
< |
int orig, nobjs; |
| 259 |
> |
int |
| 260 |
> |
dosets(f) /* loop through all sets */ |
| 261 |
> |
int (*f)(); |
| 262 |
|
{ |
| 263 |
+ |
int res = 0; |
| 264 |
|
int n; |
| 265 |
|
register OBJECT *os; |
| 192 |
– |
register OBJECT i; |
| 266 |
|
|
| 267 |
|
for (n = 0; n < OSTSIZ; n++) { |
| 268 |
|
if ((os = ostable[n]) == NULL) |
| 269 |
|
continue; |
| 270 |
< |
while ((i = *os++) > 0) |
| 271 |
< |
while (i--) { |
| 272 |
< |
if (*os >= orig && *os < orig+nobjs && |
| 273 |
< |
!issurface(objptr(*os)->otype)) |
| 201 |
< |
return(1); |
| 202 |
< |
os++; |
| 203 |
< |
} |
| 270 |
> |
while (*os > 0) { |
| 271 |
> |
res += (*f)(os); |
| 272 |
> |
os += *os + 1; |
| 273 |
> |
} |
| 274 |
|
} |
| 275 |
< |
return(0); |
| 275 |
> |
return(res); |
| 276 |
> |
} |
| 277 |
> |
|
| 278 |
> |
|
| 279 |
> |
void |
| 280 |
> |
donesets() /* free ALL SETS in our table */ |
| 281 |
> |
{ |
| 282 |
> |
register int n; |
| 283 |
> |
|
| 284 |
> |
for (n = 0; n < OSTSIZ; n++) |
| 285 |
> |
if (ostable[n] != NULL) { |
| 286 |
> |
free((void *)ostable[n]); |
| 287 |
> |
ostable[n] = NULL; |
| 288 |
> |
} |
| 289 |
|
} |