| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
/****************************************************************************/ |
| 4 |
/* */ |
| 5 |
/* File: dlmgr.t */ |
| 6 |
/* */ |
| 7 |
/* Purpose: templates for dynamic linked list management */ |
| 8 |
/* */ |
| 9 |
/* Author: Stefan Lang */ |
| 10 |
/* Institut fuer Computeranwendungen III */ |
| 11 |
/* Universitaet Stuttgart */ |
| 12 |
/* Pfaffenwaldring 27 */ |
| 13 |
/* 70550 Stuttgart */ |
| 14 |
/* email: [email protected] */ |
| 15 |
/* phone: 0049-(0)711-685-7003 */ |
| 16 |
/* fax : 0049-(0)711-685-7000 */ |
| 17 |
/* */ |
| 18 |
/* History: 960915 sl start of dynamic list management */ |
| 19 |
/* */ |
| 20 |
/* Remarks: */ |
| 21 |
/* Management of dynamic linked lists, which consist of */ |
| 22 |
/* several parts. An object can be mapped to a part of the list */ |
| 23 |
/* by its priority using PRIO2LISTPART(). */ |
| 24 |
/* The formulation on object basis allows for management of */ |
| 25 |
/* elements, nodes, vectors and vertices. */ |
| 26 |
/* A list has the form: */ |
| 27 |
/* p0first-p0last->p1first-p1last->...->pnfirst..pnlast */ |
| 28 |
/* where each part p0,p1,..,pn is limited by two pointers, */ |
| 29 |
/* pxfirst and pxlast, x=0..n. The part numbers are ordered */ |
| 30 |
/* increasingly and connected in a manner that one can run */ |
| 31 |
/* through the whole list in increasing order (SUCC) but only */ |
| 32 |
/* through one listpart in decreasing order (PRED). */ |
| 33 |
/* Linking/Unlinking of objects in a list part is done in a */ |
| 34 |
/* way that preserves these conventions. */ |
| 35 |
/* */ |
| 36 |
/****************************************************************************/ |
| 37 |
|
| 38 |
START_UGDIM_NAMESPACE |
| 39 |
|
| 40 |
#ifdef ModelP |
| 41 |
|
| 42 |
UNLINK(OTYPE) |
| 43 |
{ |
| 44 |
INT Prio = DDD_InfoPriority( HDR(OTYPE)((Object)) ); |
| 45 |
INT listpart = PRIO2LISTPART( CAT(OTYPE,_LIST) ,Prio); |
| 46 |
INT listpart1 = listpart; |
| 47 |
OTYPE *Object1 = NULL; |
| 48 |
|
| 49 |
IFDEBUG(gm,2) |
| 50 |
printf("GRID_UNLINK_" STR(OTYPE) "():" STR(OTYPE) |
| 51 |
" has listpart=%d for prio=%d\n",listpart,Prio); |
| 52 |
fflush(stdout); |
| 53 |
ENDDEBUG |
| 54 |
|
| 55 |
if (listpart<0 || listpart>LASTPART_OF_LIST(OTYPE)) |
| 56 |
{ |
| 57 |
printf(" GRID_UNLINK_" STR(OTYPE) "(): ERROR " STR(OTYPE) |
| 58 |
" has no valid listpart=%d for prio=%d\n",listpart,Prio); |
| 59 |
fflush(stdout); |
| 60 |
ASSERT(0); |
| 61 |
} |
| 62 |
|
| 63 |
IFDEBUG(gm,4) |
| 64 |
{ |
| 65 |
INT n = 0; |
| 66 |
printf(" GRID_UNLINK_" STR(OTYPE) "_LIST before is:\n"); |
| 67 |
|
| 68 |
for (Object1 = CAT(PFIRST,OTYPE(Grid)); |
| 69 |
Object1 != NULL; |
| 70 |
Object1 = SUCC(Object1)) |
| 71 |
{ |
| 72 |
n++; |
| 73 |
printf(" nob=%d o=" CAT(FORMAT(OTYPE),FMTX) "\n", |
| 74 |
n,CAT(FORMAT(OTYPE),PRTX(Object1))); |
| 75 |
} |
| 76 |
CAT(PRINT_LIST_STARTS_,OTYPE)(Grid,CAT(OTYPE,_LISTPARTS)); |
| 77 |
} |
| 78 |
ENDDEBUG |
| 79 |
|
| 80 |
switch (listpart) |
| 81 |
{ |
| 82 |
case FIRSTPART_OF_LIST: |
| 83 |
|
| 84 |
if (PRED(Object)!=NULL) |
| 85 |
SUCC(PRED(Object)) = SUCC(Object); |
| 86 |
|
| 87 |
if (CAT(LISTPART_LAST,OTYPE(Grid,listpart)) != Object) |
| 88 |
{ |
| 89 |
if (CAT(LISTPART_FIRST,OTYPE(Grid,listpart)) == Object) |
| 90 |
CAT(LISTPART_FIRST,OTYPE(Grid,listpart)) = SUCC(Object); |
| 91 |
|
| 92 |
if (SUCC(Object)!=NULL) |
| 93 |
PRED(SUCC(Object)) = PRED(Object); |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
if (CAT(LISTPART_FIRST,OTYPE(Grid,listpart)) == Object) |
| 98 |
CAT(LISTPART_FIRST,OTYPE(Grid,listpart)) = NULL; |
| 99 |
|
| 100 |
CAT(LISTPART_LAST,OTYPE(Grid,listpart)) = PRED(Object); |
| 101 |
} |
| 102 |
|
| 103 |
break; |
| 104 |
|
| 105 |
case LASTPART_OF_LIST(OTYPE): |
| 106 |
|
| 107 |
if (PRED(Object)!=NULL) |
| 108 |
SUCC(PRED(Object)) = SUCC(Object); |
| 109 |
else |
| 110 |
{ |
| 111 |
CAT(LISTPART_FIRST,OTYPE(Grid,LASTPART_OF_LIST(OTYPE))) = SUCC(Object); |
| 112 |
|
| 113 |
do |
| 114 |
{ |
| 115 |
listpart1--; |
| 116 |
Object1 = CAT(LISTPART_LAST,OTYPE(Grid,listpart1)); |
| 117 |
} |
| 118 |
while (listpart1>FIRSTPART_OF_LIST && Object1==NULL); |
| 119 |
|
| 120 |
if (Object1!=NULL) |
| 121 |
SUCC(Object1) = SUCC(Object); |
| 122 |
} |
| 123 |
if (SUCC(Object)!=NULL) |
| 124 |
PRED(SUCC(Object)) = PRED(Object); |
| 125 |
else |
| 126 |
{ |
| 127 |
CAT(LISTPART_LAST,OTYPE(Grid,LASTPART_OF_LIST(OTYPE))) = PRED(Object); |
| 128 |
if (PRED(Object) != NULL) |
| 129 |
SUCC(PRED(Object)) = NULL; |
| 130 |
} |
| 131 |
break; |
| 132 |
|
| 133 |
default: |
| 134 |
|
| 135 |
/* unlink in middle of list */ |
| 136 |
if (PRED(Object)!=NULL) |
| 137 |
SUCC(PRED(Object)) = SUCC(Object); |
| 138 |
else |
| 139 |
{ |
| 140 |
if (SUCC(Object)!=NULL) |
| 141 |
PRED(SUCC(Object)) = NULL; |
| 142 |
|
| 143 |
do |
| 144 |
{ |
| 145 |
listpart1--; |
| 146 |
Object1 = CAT(LISTPART_LAST,OTYPE(Grid,listpart1)); |
| 147 |
} |
| 148 |
while (listpart1>FIRSTPART_OF_LIST && Object1==NULL); |
| 149 |
|
| 150 |
if (Object1!=NULL) |
| 151 |
SUCC(Object1) = SUCC(Object); |
| 152 |
} |
| 153 |
if (CAT(LISTPART_LAST,OTYPE(Grid,listpart)) != Object) |
| 154 |
{ |
| 155 |
if (CAT(LISTPART_FIRST,OTYPE(Grid,listpart)) == Object) |
| 156 |
CAT(LISTPART_FIRST,OTYPE(Grid,listpart)) = SUCC(Object); |
| 157 |
|
| 158 |
if (SUCC(Object)!=NULL) |
| 159 |
PRED(SUCC(Object)) = PRED(Object); |
| 160 |
} |
| 161 |
else |
| 162 |
{ |
| 163 |
if (CAT(LISTPART_FIRST,OTYPE(Grid,listpart)) == Object) |
| 164 |
CAT(LISTPART_FIRST,OTYPE(Grid,listpart)) = NULL; |
| 165 |
|
| 166 |
CAT(LISTPART_LAST,OTYPE(Grid,listpart)) = PRED(Object); |
| 167 |
} |
| 168 |
|
| 169 |
break; |
| 170 |
} |
| 171 |
SUCC(Object) = PRED(Object) = NULL; |
| 172 |
|
| 173 |
/* decrement counter */ |
| 174 |
CAT(COUNT,OTYPE(Grid))--; |
| 175 |
ASSERT(CAT(COUNT,OTYPE(Grid))>=0); |
| 176 |
/* decrement counter for priority */ |
| 177 |
CAT(PRIOCOUNT,OTYPE(Grid,Prio))--; |
| 178 |
ASSERT(CAT(PRIOCOUNT,OTYPE(Grid,Prio))>=0); |
| 179 |
ASSERT(Prio>0); |
| 180 |
|
| 181 |
IFDEBUG(gm,4) |
| 182 |
/* debug loop in list */ |
| 183 |
{ |
| 184 |
INT n = 0; |
| 185 |
|
| 186 |
printf(" GRID_UNLINK_" STR(OTYPE) "_LIST after is:\n"); |
| 187 |
|
| 188 |
for (Object1 = CAT(PFIRST,OTYPE(Grid)); |
| 189 |
Object1 != NULL; |
| 190 |
Object1 = SUCC(Object1)) |
| 191 |
{ |
| 192 |
n++; |
| 193 |
printf(" nob=%d o=" CAT(FORMAT(OTYPE),FMTX) "\n", |
| 194 |
n,CAT(FORMAT(OTYPE),PRTX(Object1))); |
| 195 |
if (n>10000) |
| 196 |
{ |
| 197 |
printf("GRID_UNLINK_" STR(OTYPE) "(): LOOPERROR " STR(OTYPE) |
| 198 |
" has listpart=%d for prio=%d\n",listpart,Prio); |
| 199 |
fflush(stdout); |
| 200 |
assert(0); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
CAT(PRINT_LIST_STARTS_,OTYPE)(Grid,CAT(OTYPE,_LISTPARTS)); |
| 205 |
|
| 206 |
/* object number error detection */ |
| 207 |
if (n != CAT(COUNT,OTYPE(Grid))) |
| 208 |
{ |
| 209 |
printf(" Object=" CAT(FORMAT(OTYPE),FMTX) "\n", |
| 210 |
CAT(FORMAT(OTYPE),PRTX(Object))); |
| 211 |
printf("GRID_UNLINK_" STR(OTYPE) "(): COUNTERERROR " STR(OTYPE) |
| 212 |
" has listpart=%d for prio=%d n=%d count=%d\n", |
| 213 |
listpart,Prio,n,CAT(COUNT,OTYPE(Grid))); |
| 214 |
fflush(stdout); |
| 215 |
assert(0); |
| 216 |
} |
| 217 |
} |
| 218 |
ENDDEBUG |
| 219 |
} |
| 220 |
|
| 221 |
#else |
| 222 |
|
| 223 |
UNLINK(OTYPE) |
| 224 |
{ |
| 225 |
if (PRED(Object)!=NULL) |
| 226 |
SUCC(PRED(Object)) = SUCC(Object); |
| 227 |
else |
| 228 |
{ |
| 229 |
CAT(FIRST,OTYPE(Grid)) = SUCC(Object); |
| 230 |
if (SUCC(Object)!=NULL) PRED(SUCC(Object)) = NULL; |
| 231 |
} |
| 232 |
if (SUCC(Object)!=NULL) |
| 233 |
PRED(SUCC(Object)) = PRED(Object); |
| 234 |
else |
| 235 |
{ |
| 236 |
CAT(LAST,OTYPE(Grid)) = PRED(Object); |
| 237 |
if (PRED(Object)!=NULL) SUCC(PRED(Object)) = NULL; |
| 238 |
} |
| 239 |
|
| 240 |
/* decrement counter */ |
| 241 |
CAT(COUNT,OTYPE(Grid))--; |
| 242 |
} |
| 243 |
#endif |
| 244 |
|
| 245 |
#ifdef ModelP |
| 246 |
|
| 247 |
LINK(OTYPE) |
| 248 |
{ |
| 249 |
INT listpart = PRIO2LISTPART(CAT(OTYPE,_LIST),Prio); |
| 250 |
INT listpartprev = listpart; |
| 251 |
INT listpartnext = listpart; |
| 252 |
OTYPE *Object1 = NULL; |
| 253 |
|
| 254 |
ASSERT(Grid != NULL); |
| 255 |
ASSERT(Object != NULL); |
| 256 |
ASSERT(Prio >= 0); |
| 257 |
|
| 258 |
IFDEBUG(gm,2) |
| 259 |
printf("GRID_LINK_" STR(OTYPE) "():" STR(OTYPE) |
| 260 |
" has listpart=%d for prio=%d obj=%p\n", listpart, Prio, (void*) Object); |
| 261 |
fflush(stdout); |
| 262 |
ENDDEBUG |
| 263 |
|
| 264 |
if (listpart<0 || listpart>LASTPART_OF_LIST(OTYPE)) |
| 265 |
{ |
| 266 |
printf("GRID_LINK_" STR(OTYPE) "(): ERROR " STR(OTYPE) |
| 267 |
" has no valid listpart=%d for prio=%d\n",listpart,Prio); |
| 268 |
fflush(stdout); |
| 269 |
ASSERT(0); |
| 270 |
} |
| 271 |
|
| 272 |
PRED(Object) = SUCC(Object) = NULL; |
| 273 |
|
| 274 |
switch (listpart) |
| 275 |
{ |
| 276 |
case FIRSTPART_OF_LIST: |
| 277 |
|
| 278 |
Object1 = CAT(LISTPART_FIRST,OTYPE(Grid,FIRSTPART_OF_LIST)); |
| 279 |
PRED(Object) = NULL; |
| 280 |
CAT(LISTPART_FIRST,OTYPE(Grid,FIRSTPART_OF_LIST)) = Object; |
| 281 |
if (Object1==NULL) |
| 282 |
{ |
| 283 |
CAT(LISTPART_LAST,OTYPE(Grid,FIRSTPART_OF_LIST)) = Object; |
| 284 |
do |
| 285 |
{ |
| 286 |
listpartnext++; |
| 287 |
CAT(Object1=LISTPART_FIRST,OTYPE(Grid,listpartnext)); |
| 288 |
} |
| 289 |
while (listpartnext<LASTPART_OF_LIST(OTYPE) && Object1==NULL); |
| 290 |
SUCC(Object) = Object1; |
| 291 |
} |
| 292 |
else |
| 293 |
{ |
| 294 |
SUCC(Object) = Object1; |
| 295 |
PRED(Object1) = Object; |
| 296 |
} |
| 297 |
break; |
| 298 |
|
| 299 |
case LASTPART_OF_LIST(OTYPE): |
| 300 |
|
| 301 |
Object1 = CAT(LISTPART_LAST,OTYPE(Grid,LASTPART_OF_LIST(OTYPE))); |
| 302 |
SUCC(Object) = NULL; |
| 303 |
CAT(LISTPART_LAST,OTYPE(Grid,LASTPART_OF_LIST(OTYPE))) = Object; |
| 304 |
if (Object1==NULL) |
| 305 |
{ |
| 306 |
PRED(Object) = NULL; |
| 307 |
CAT(LISTPART_FIRST,OTYPE(Grid,LASTPART_OF_LIST(OTYPE))) = Object; |
| 308 |
|
| 309 |
do |
| 310 |
{ |
| 311 |
listpartprev--; |
| 312 |
Object1=CAT(LISTPART_LAST,OTYPE(Grid,listpartprev)); |
| 313 |
} |
| 314 |
while (listpartprev>FIRSTPART_OF_LIST && Object1==NULL); |
| 315 |
|
| 316 |
if (Object1!=NULL) |
| 317 |
SUCC(Object1) = Object; |
| 318 |
} |
| 319 |
else |
| 320 |
{ |
| 321 |
PRED(Object) = Object1; |
| 322 |
SUCC(Object1) = Object; |
| 323 |
} |
| 324 |
break; |
| 325 |
|
| 326 |
default: |
| 327 |
|
| 328 |
/* link in middle of list */ |
| 329 |
Object1 = CAT(LISTPART_FIRST,OTYPE(Grid,listpart)); |
| 330 |
|
| 331 |
CAT(LISTPART_FIRST,OTYPE(Grid,listpart)) = Object; |
| 332 |
SUCC(Object) = Object1; |
| 333 |
PRED(Object) = NULL; |
| 334 |
|
| 335 |
/* empty list? */ |
| 336 |
if (Object1 == NULL) |
| 337 |
{ |
| 338 |
CAT(LISTPART_LAST,OTYPE(Grid,listpart)) = Object; |
| 339 |
do |
| 340 |
{ |
| 341 |
listpartnext++; |
| 342 |
Object1=CAT(LISTPART_FIRST,OTYPE(Grid,listpartnext)); |
| 343 |
} |
| 344 |
while (listpartnext<LASTPART_OF_LIST(OTYPE) && Object1==NULL); |
| 345 |
SUCC(Object) = Object1; |
| 346 |
} |
| 347 |
else |
| 348 |
PRED(Object1) = Object; |
| 349 |
|
| 350 |
do |
| 351 |
{ |
| 352 |
listpartprev--; |
| 353 |
Object1=CAT(LISTPART_LAST,OTYPE(Grid,listpartprev)); |
| 354 |
} |
| 355 |
while (listpartprev>FIRSTPART_OF_LIST && Object1==NULL); |
| 356 |
|
| 357 |
if (Object1 != NULL) |
| 358 |
SUCC(Object1) = Object; |
| 359 |
break; |
| 360 |
} |
| 361 |
|
| 362 |
/* increment counter */ |
| 363 |
CAT(COUNT,OTYPE(Grid))++; |
| 364 |
/* increment counter for priority */ |
| 365 |
CAT(PRIOCOUNT,OTYPE(Grid,Prio))++; |
| 366 |
ASSERT(Prio>0); |
| 367 |
|
| 368 |
IFDEBUG(gm,4) |
| 369 |
/* debug loop in list */ |
| 370 |
{ |
| 371 |
INT n = 0; |
| 372 |
for (Object1 = CAT(PFIRST,OTYPE(Grid)); |
| 373 |
Object1 != NULL; |
| 374 |
Object1 = SUCC(Object1)) |
| 375 |
{ |
| 376 |
n++; |
| 377 |
if (n>10000) |
| 378 |
{ |
| 379 |
printf("GRID_LINK_" STR(OTYPE) "(): LOOPERROR " STR(OTYPE) |
| 380 |
" has listpart=%d for prio=%d\n",listpart,Prio); |
| 381 |
fflush(stdout); |
| 382 |
assert(0); |
| 383 |
} |
| 384 |
|
| 385 |
} |
| 386 |
|
| 387 |
/* object number error detection */ |
| 388 |
if (n != CAT(COUNT,OTYPE(Grid))) |
| 389 |
{ |
| 390 |
printf("GRID_LINK_" STR(OTYPE) "(): COUNTERERROR " STR(OTYPE) |
| 391 |
" has listpart=%d for prio=%d n=%d count=%d\n", |
| 392 |
listpart,Prio,n,CAT(COUNT,OTYPE(Grid))); |
| 393 |
fflush(stdout); |
| 394 |
assert(0); |
| 395 |
} |
| 396 |
|
| 397 |
} |
| 398 |
ENDDEBUG |
| 399 |
} |
| 400 |
|
| 401 |
#else |
| 402 |
|
| 403 |
LINK(OTYPE) |
| 404 |
{ |
| 405 |
OTYPE *after; |
| 406 |
|
| 407 |
after = CAT(LAST,OTYPE(Grid)); |
| 408 |
SUCC(Object) = NULL; |
| 409 |
if (after==NULL) |
| 410 |
{ |
| 411 |
PRED(Object) = NULL; |
| 412 |
CAT(LAST,OTYPE(Grid)) = Object; |
| 413 |
CAT(FIRST,OTYPE(Grid)) = Object; |
| 414 |
} |
| 415 |
else |
| 416 |
{ |
| 417 |
PRED(Object) = after; |
| 418 |
CAT(LAST,OTYPE(Grid)) = Object; |
| 419 |
SUCC(after) = Object; |
| 420 |
} |
| 421 |
|
| 422 |
/* increment counter */ |
| 423 |
CAT(COUNT,OTYPE(Grid))++; |
| 424 |
|
| 425 |
} |
| 426 |
#endif |
| 427 |
|
| 428 |
#ifdef ModelP |
| 429 |
LINKX(OTYPE) |
| 430 |
{ |
| 431 |
INT listpart = PRIO2LISTPART(CAT(OTYPE,_LIST),Prio); |
| 432 |
OTYPE *Object1 = NULL; |
| 433 |
|
| 434 |
ASSERT(Grid != NULL); |
| 435 |
ASSERT(Object != NULL); |
| 436 |
ASSERT(Prio >= 0); |
| 437 |
|
| 438 |
if (After == NULL) |
| 439 |
{ |
| 440 |
IFDEBUG(gm,2) |
| 441 |
printf(" GRID_LINKX_" STR(OTYPE) "():" STR(OTYPE) |
| 442 |
" calling GRID_LINK_" STR(OTYPE) "(): Object=%p After=%p \n", |
| 443 |
(void*) Object, (void*) After); |
| 444 |
ENDDEBUG |
| 445 |
|
| 446 |
CAT(GRID_LINK_,OTYPE) (Grid,Object,Prio); |
| 447 |
return; |
| 448 |
} |
| 449 |
|
| 450 |
#ifdef Debug |
| 451 |
/* this conistency is not true since elements have already their new |
| 452 |
priorities, but the handlers for them must not have been called |
| 453 |
at this point */ |
| 454 |
if (0) |
| 455 |
{ |
| 456 |
INT listpartafter; |
| 457 |
|
| 458 |
/* After object must be in same list as Object */ |
| 459 |
listpartafter = PRIO2LISTPART(CAT(OTYPE,_LIST),DDD_InfoPriority(HDR(OTYPE)(After))); |
| 460 |
ASSERT(listpart == listpartafter); |
| 461 |
} |
| 462 |
#endif |
| 463 |
|
| 464 |
IFDEBUG(gm,2) |
| 465 |
printf("GRID_LINKX_" STR(OTYPE) "():" STR(OTYPE) |
| 466 |
" has listpart=%d for prio=%d obj=%p\n", listpart, Prio, (void*) Object); |
| 467 |
fflush(stdout); |
| 468 |
ENDDEBUG |
| 469 |
|
| 470 |
#ifdef Debug |
| 471 |
if (listpart<0 || listpart>LASTPART_OF_LIST(OTYPE)) |
| 472 |
{ |
| 473 |
printf("GRID_LINKX_" STR(OTYPE) "(): ERROR " STR(OTYPE) |
| 474 |
" has no valid listpart=%d for prio=%d\n",listpart,Prio); |
| 475 |
fflush(stdout); |
| 476 |
ASSERT(0); |
| 477 |
} |
| 478 |
#endif |
| 479 |
|
| 480 |
SUCC(Object) = SUCC(After); |
| 481 |
if (SUCC(Object) != NULL) |
| 482 |
{ |
| 483 |
if (PRED(SUCC(Object)) == After) |
| 484 |
PRED(SUCC(Object)) = Object; |
| 485 |
} |
| 486 |
SUCC(After) = Object; |
| 487 |
PRED(Object) = After; |
| 488 |
|
| 489 |
if (After == CAT(LISTPART_LAST,OTYPE(Grid,listpart))) |
| 490 |
{ |
| 491 |
CAT(LISTPART_LAST,OTYPE(Grid,listpart)) = Object; |
| 492 |
} |
| 493 |
|
| 494 |
/* increment counter */ |
| 495 |
CAT(COUNT,OTYPE(Grid))++; |
| 496 |
/* increment counter for priority */ |
| 497 |
CAT(PRIOCOUNT,OTYPE(Grid,Prio))++; |
| 498 |
ASSERT(Prio>0); |
| 499 |
|
| 500 |
|
| 501 |
IFDEBUG(gm,4) |
| 502 |
/* debug loop in list */ |
| 503 |
{ |
| 504 |
INT n = 0; |
| 505 |
for (Object1 = CAT(PFIRST,OTYPE(Grid)); |
| 506 |
Object1 != NULL; |
| 507 |
Object1 = SUCC(Object1)) |
| 508 |
{ |
| 509 |
n++; |
| 510 |
if (n>10000) |
| 511 |
{ |
| 512 |
printf("GRID_LINKX_" STR(OTYPE) "(): LOOPERROR " STR(OTYPE) |
| 513 |
" has listpart=%d for prio=%d\n",listpart,Prio); |
| 514 |
fflush(stdout); |
| 515 |
assert(0); |
| 516 |
} |
| 517 |
|
| 518 |
} |
| 519 |
|
| 520 |
/* object number error detection */ |
| 521 |
if (n != CAT(COUNT,OTYPE(Grid))) |
| 522 |
{ |
| 523 |
printf("GRID_LINKX_" STR(OTYPE) "(): COUNTERERROR " STR(OTYPE) |
| 524 |
" has listpart=%d for prio=%d n=%d count=%d\n", |
| 525 |
listpart,Prio,n,CAT(COUNT,OTYPE(Grid))); |
| 526 |
fflush(stdout); |
| 527 |
assert(0); |
| 528 |
} |
| 529 |
|
| 530 |
} |
| 531 |
ENDDEBUG |
| 532 |
} |
| 533 |
#else |
| 534 |
|
| 535 |
LINKX(OTYPE) |
| 536 |
{ |
| 537 |
INT listpart = PRIO2LISTPART(CAT(OTYPE,_LIST),Prio); |
| 538 |
|
| 539 |
ASSERT(Grid != NULL); |
| 540 |
ASSERT(Object != NULL); |
| 541 |
ASSERT(Prio >= 0); |
| 542 |
|
| 543 |
if (After == NULL) |
| 544 |
{ |
| 545 |
IFDEBUG(gm,2) |
| 546 |
printf(" GRID_LINKX_" STR(OTYPE) "():" STR(OTYPE) |
| 547 |
" calling GRID_LINK_" STR(OTYPE) "(): Object=%p After=%p \n", (void*) Object, (void*) After); |
| 548 |
ENDDEBUG |
| 549 |
|
| 550 |
CAT(GRID_LINK_,OTYPE) (Grid,Object,Prio); |
| 551 |
return; |
| 552 |
} |
| 553 |
|
| 554 |
IFDEBUG(gm,2) |
| 555 |
printf("GRID_LINKX_" STR(OTYPE) "():" STR(OTYPE) |
| 556 |
" has listpart=%d for prio=%d obj=%p\n", listpart, Prio, (void*) Object); |
| 557 |
fflush(stdout); |
| 558 |
ENDDEBUG |
| 559 |
|
| 560 |
SUCC(Object) = SUCC(After); |
| 561 |
if (SUCC(Object) != NULL) |
| 562 |
{ |
| 563 |
if (PRED(SUCC(Object)) == After) |
| 564 |
PRED(SUCC(Object)) = Object; |
| 565 |
} |
| 566 |
SUCC(After) = Object; |
| 567 |
PRED(Object) = After; |
| 568 |
|
| 569 |
if (After == CAT(LAST,OTYPE(Grid))) |
| 570 |
{ |
| 571 |
CAT(LAST,OTYPE(Grid)) = Object; |
| 572 |
} |
| 573 |
|
| 574 |
/* increment counter */ |
| 575 |
CAT(COUNT,OTYPE(Grid))++; |
| 576 |
|
| 577 |
} |
| 578 |
|
| 579 |
#endif |
| 580 |
|
| 581 |
#ifdef ModelP |
| 582 |
INIT(OTYPE) |
| 583 |
{ |
| 584 |
INT i; |
| 585 |
for (i=0; i<=LASTPART_OF_LIST(OTYPE); i++) |
| 586 |
{ |
| 587 |
CAT(LISTPART_FIRST,OTYPE(Grid,i)) = NULL; |
| 588 |
CAT(LISTPART_LAST,OTYPE(Grid,i)) = NULL; |
| 589 |
} |
| 590 |
CAT(COUNT,OTYPE(Grid)) = 0; |
| 591 |
} |
| 592 |
#else |
| 593 |
INIT(OTYPE) |
| 594 |
{ |
| 595 |
CAT(FIRST,OTYPE(Grid)) = CAT(LAST,OTYPE(Grid)) = NULL; |
| 596 |
CAT(COUNT,OTYPE(Grid)) = 0; |
| 597 |
} |
| 598 |
#endif |
| 599 |
|
| 600 |
#ifdef ModelP |
| 601 |
PRINT_LIST(OTYPE) |
| 602 |
{ |
| 603 |
if (prios==2) |
| 604 |
{ |
| 605 |
printf (" fg=%p fg=%p fm=%p lm=%p\n", |
| 606 |
(void*) CAT(LISTPART_FIRST,OTYPE(Grid,0)), |
| 607 |
(void*) CAT(LISTPART_LAST,OTYPE(Grid,0)), |
| 608 |
(void*) CAT(LISTPART_FIRST,OTYPE(Grid,1)), |
| 609 |
(void*) CAT(LISTPART_LAST,OTYPE(Grid,1))); |
| 610 |
} |
| 611 |
else |
| 612 |
{ |
| 613 |
printf (" fg=%p fg=%p fb=%p lb=%p fm=%p lm=%p\n", |
| 614 |
(void*) CAT(LISTPART_FIRST,OTYPE(Grid,0)), |
| 615 |
(void*) CAT(LISTPART_LAST,OTYPE(Grid,0)), |
| 616 |
(void*) CAT(LISTPART_FIRST,OTYPE(Grid,1)), |
| 617 |
(void*) CAT(LISTPART_LAST,OTYPE(Grid,1)), |
| 618 |
(void*) CAT(LISTPART_FIRST,OTYPE(Grid,2)), |
| 619 |
(void*) CAT(LISTPART_LAST,OTYPE(Grid,2))); |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
CHECK(OTYPE) |
| 624 |
{ |
| 625 |
INT i,objs = 0; |
| 626 |
OTYPE *Object; |
| 627 |
|
| 628 |
PRINTDEBUG(gm,2,(" GRID_CHECK_" STR(OTYPE) "_LIST:\n")); |
| 629 |
|
| 630 |
IFDEBUG(gm,2) |
| 631 |
CAT(PRINT_LIST_STARTS_,OTYPE)(Grid,CAT(OTYPE,_LISTPARTS)); |
| 632 |
ENDDEBUG |
| 633 |
|
| 634 |
for (Object = CAT(PFIRST,OTYPE(Grid)); |
| 635 |
Object != NULL; |
| 636 |
Object = SUCC(Object)) |
| 637 |
{ |
| 638 |
objs++; |
| 639 |
} |
| 640 |
if (objs != CAT(COUNT,OTYPE(Grid))) |
| 641 |
{ |
| 642 |
printf(" ERROR: %d objs in list, but counter=%d\n", |
| 643 |
objs,CAT(COUNT,OTYPE(Grid))); |
| 644 |
} |
| 645 |
|
| 646 |
for (i=FIRSTPART_OF_LIST; |
| 647 |
i<=LASTPART_OF_LIST(OTYPE); |
| 648 |
i++) |
| 649 |
{ |
| 650 |
INT prios[MAX_LISTPARTS],j,prio_error; |
| 651 |
|
| 652 |
LISTPART2PRIO(CAT(OTYPE,_LIST),i,prios); |
| 653 |
|
| 654 |
objs = 0; |
| 655 |
for (Object = CAT(LISTPART_LAST,OTYPE(Grid,i)); |
| 656 |
Object != NULL; |
| 657 |
Object = PRED(Object)) |
| 658 |
{ |
| 659 |
INT prio = DDD_InfoPriority(HDR(OTYPE)(Object)); |
| 660 |
assert(prio != -1); |
| 661 |
|
| 662 |
objs++; |
| 663 |
prio_error = 1; |
| 664 |
for (j=0; j<MAX_LISTPARTS; j++) |
| 665 |
if (prios[j] == prio) |
| 666 |
{ |
| 667 |
prio_error = 0; |
| 668 |
break; |
| 669 |
} |
| 670 |
|
| 671 |
if (prio_error) |
| 672 |
{ |
| 673 |
printf(" ERROR nob=%d o=" CAT(FORMAT(OTYPE),FMTX) |
| 674 |
" WRONG LIST=%d prio=%d\n", |
| 675 |
objs,CAT(FORMAT(OTYPE),PRTX(Object)),i,prio); |
| 676 |
} |
| 677 |
|
| 678 |
if (Object == CAT(LISTPART_FIRST,OTYPE(Grid,i))) |
| 679 |
{ |
| 680 |
if (i>FIRSTPART_OF_LIST) |
| 681 |
{ |
| 682 |
INT listpartprev = i; |
| 683 |
OTYPE *Object1; |
| 684 |
|
| 685 |
do |
| 686 |
{ |
| 687 |
listpartprev--; |
| 688 |
Object1=CAT(LISTPART_LAST,OTYPE(Grid,listpartprev)); |
| 689 |
} |
| 690 |
while (listpartprev>FIRSTPART_OF_LIST && Object1==NULL); |
| 691 |
|
| 692 |
if (Object1 != NULL) |
| 693 |
if (CAT(LISTPART_FIRST,OTYPE(Grid,i))!= |
| 694 |
SUCC(Object1)) |
| 695 |
{ |
| 696 |
printf(" ERROR: first pointer of listpart=%d" |
| 697 |
" dead\n",i); |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
PRINTDEBUG(gm,2,(" listpart=%d prio=%d has nobjs=%d\n", |
| 702 |
i,prio,objs)); |
| 703 |
} |
| 704 |
} |
| 705 |
} |
| 706 |
} |
| 707 |
#else |
| 708 |
CHECK(OTYPE) |
| 709 |
{ |
| 710 |
} |
| 711 |
#endif |
| 712 |
|
| 713 |
/* undefine used macros to allow redefinition */ |
| 714 |
#undef OTYPE |
| 715 |
#undef PRED |
| 716 |
#undef SUCC |
| 717 |
|
| 718 |
END_UGDIM_NAMESPACE |