| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
package gen.lib.cdt; |
| 47 |
import static gen.lib.cdt.dtrestore__c.dtrestore; |
| 48 |
import static smetana.core.JUtils.NEQ; |
| 49 |
import static smetana.core.JUtils.sizeof; |
| 50 |
import static smetana.core.JUtils.strcmp; |
| 51 |
import static smetana.core.JUtilsDebug.ENTERING; |
| 52 |
import static smetana.core.JUtilsDebug.LEAVING; |
| 53 |
import static smetana.core.Macro.N; |
| 54 |
import static smetana.core.Macro.UNSUPPORTED; |
| 55 |
import static smetana.core.Macro.UNSUPPORTED_INT; |
| 56 |
import h.Dtcompar_f; |
| 57 |
import h.ST_dt_s; |
| 58 |
import h.ST_dtdisc_s; |
| 59 |
import h.ST_dthold_s; |
| 60 |
import h.ST_dtlink_s; |
| 61 |
import h.ST_dthold_s; |
| 62 |
import smetana.core.CFunction; |
| 63 |
import smetana.core.CString; |
| 64 |
import smetana.core.__ptr__; |
| 65 |
|
| 66 |
public class dttree__c { |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
static class no_root extends RuntimeException {} |
| 134 |
static class has_root extends RuntimeException {} |
| 135 |
static class do_search extends RuntimeException {} |
| 136 |
static class dt_delete extends RuntimeException {} |
| 137 |
static class dt_insert extends RuntimeException {} |
| 138 |
static class dt_next extends RuntimeException {} |
| 139 |
|
| 140 |
|
| 141 |
public static Object dttree(ST_dt_s dt, __ptr__ obj, int type) { |
| 142 |
ENTERING("abqfzg1d1vkzk51225tcdlik5","dttree"); |
| 143 |
try { |
| 144 |
ST_dtlink_s root, t; |
| 145 |
int cmp, lk, sz, ky; |
| 146 |
ST_dtlink_s l, r, me=null; |
| 147 |
final ST_dtlink_s link = new ST_dtlink_s(); |
| 148 |
Object o, k, key = null; |
| 149 |
int n, minp; |
| 150 |
Dtcompar_f cmpf; |
| 151 |
ST_dtdisc_s disc; |
| 152 |
if (((dt.data.type) & 010000) !=0) { dtrestore(dt,null); } |
| 153 |
disc = (ST_dtdisc_s) dt.disc; ky = disc.key; |
| 154 |
sz = disc.size; |
| 155 |
lk = disc.link; |
| 156 |
cmpf = (Dtcompar_f) disc.comparf; |
| 157 |
dt.setInt("type", dt.type&~0100000); |
| 158 |
root = (ST_dtlink_s) dt.data.here; |
| 159 |
if(N(obj)) |
| 160 |
{ if(N(root) || N(type&(0000100|0000200|0000400)) ) |
| 161 |
return null; |
| 162 |
if((type&0000100)!=0) |
| 163 |
{ |
| 164 |
if(disc.freef!=null || disc.link < 0) { |
| 165 |
do { |
| 166 |
while((t = (ST_dtlink_s) root._left)!=null ) { |
| 167 |
root._left = t.right; |
| 168 |
t.right = root; |
| 169 |
root = t; |
| 170 |
} |
| 171 |
t = (ST_dtlink_s) root.right; |
| 172 |
if(disc.freef!=null) |
| 173 |
throw new UnsupportedOperationException(); |
| 174 |
|
| 175 |
if(disc.link < 0) |
| 176 |
dt.memoryf.exe(dt, root, null, disc); |
| 177 |
} while((root = t)!=null ); |
| 178 |
} |
| 179 |
dt.data.setInt("size", 0); |
| 180 |
dt.data.here = null; |
| 181 |
return null; |
| 182 |
} |
| 183 |
else |
| 184 |
{ if((type&0000400)!=0) |
| 185 |
{ while((t = (ST_dtlink_s) root.right)!=null ) { |
| 186 |
root.right = t._left; |
| 187 |
t._left = root; |
| 188 |
root = t; |
| 189 |
} |
| 190 |
} |
| 191 |
else |
| 192 |
{ while((t = (ST_dtlink_s) root._left)!=null ) { |
| 193 |
root._left = t.right; |
| 194 |
t.right = root; |
| 195 |
root = t; |
| 196 |
} |
| 197 |
} |
| 198 |
dt.data.here = root; |
| 199 |
return (lk < 0 ? root.castTo_ST_dthold_s().obj : root.addVirtualBytes(-lk) ); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
l = r = link; |
| 204 |
|
| 205 |
try { |
| 206 |
if(dt.meth.type == 0000010 && ((type&(0000002|0010000))!=0) ) { |
| 207 |
throw new UnsupportedOperationException(); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
} |
| 221 |
try { |
| 222 |
if(((type&(0001000|0000004|0000001|0004000))!=0)) |
| 223 |
{ key = ((type&0001000)!=0) ? obj : (sz < 0 ? ((__ptr__)obj).addVirtualBytes(ky) : ((__ptr__)obj).addVirtualBytes(ky)); |
| 224 |
if(root!=null) |
| 225 |
throw new do_search(); |
| 226 |
} |
| 227 |
else if((type&0000040)!=0) { |
| 228 |
throw new UnsupportedOperationException(); |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
} |
| 235 |
else if(root!=null && (lk < 0 ? (root.castTo_ST_dthold_s().obj!=null): NEQ(root.addVirtualBytes(-lk), obj))) |
| 236 |
{ key = (sz < 0 ? ((__ptr__)obj).addVirtualBytes(ky) : ((__ptr__)obj).addVirtualBytes(ky)); |
| 237 |
throw new do_search(); |
| 238 |
} |
| 239 |
} catch (do_search do_search) { |
| 240 |
|
| 241 |
if(dt.meth.type == 0000004 && |
| 242 |
(minp = dt.data.minp) != 0 && (type&(0001000|0000004))!=0) |
| 243 |
{ |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
throw new UnsupportedOperationException("do_search1"); |
| 284 |
} |
| 285 |
while(true) { |
| 286 |
k = lk < 0 ? root.castTo_ST_dthold_s().obj : root.addVirtualBytes(-lk); |
| 287 |
k = sz < 0 ? ((__ptr__)k).addVirtualBytes(ky) : ((__ptr__)k).addVirtualBytes(ky); |
| 288 |
if((cmp = (cmpf!=null ? (Integer)((CFunction)cmpf).exe(dt,key,k,disc) : |
| 289 |
(sz <= 0 ? strcmp((CString)key,(CString)k) : UNSUPPORTED_INT("memcmp(key,k,sz))") ))) == 0) |
| 290 |
break; |
| 291 |
else if(cmp < 0) |
| 292 |
{ if((t = (ST_dtlink_s) root._left)!=null ) |
| 293 |
{ |
| 294 |
k = lk < 0 ? t.castTo_ST_dthold_s().obj : t.addVirtualBytes(-lk); |
| 295 |
k = sz < 0 ? ((__ptr__)k).addVirtualBytes(ky) : ((__ptr__)k).addVirtualBytes(ky); |
| 296 |
if((cmp = (cmpf!=null ? (Integer)((CFunction)cmpf).exe(dt,key,k,disc) |
| 297 |
: (sz <= 0 ? strcmp((CString)key,(CString)k) : UNSUPPORTED_INT("memcmp(key,k,sz))") ))) < 0) |
| 298 |
{ root._left = t.right; |
| 299 |
t.right = root; |
| 300 |
r._left = t; |
| 301 |
r = t; |
| 302 |
if(N(root = (ST_dtlink_s) t._left) ) |
| 303 |
break; |
| 304 |
} |
| 305 |
else if(cmp == 0) |
| 306 |
{ r._left = root; |
| 307 |
r = root; |
| 308 |
root = t; |
| 309 |
break; |
| 310 |
} |
| 311 |
else |
| 312 |
{ l.right = t; |
| 313 |
l = t; |
| 314 |
r._left = root; |
| 315 |
r = root; |
| 316 |
if(N(root = (ST_dtlink_s) t.right) ) |
| 317 |
break; |
| 318 |
} |
| 319 |
} |
| 320 |
else |
| 321 |
{ |
| 322 |
r._left = root; |
| 323 |
r = root; |
| 324 |
root = null; |
| 325 |
break; |
| 326 |
} |
| 327 |
} |
| 328 |
else |
| 329 |
{ if ((t = (ST_dtlink_s) root.right)!=null ) |
| 330 |
{ |
| 331 |
k = (lk < 0 ? t.castTo_ST_dthold_s().obj : t.addVirtualBytes(-lk) ); |
| 332 |
k = sz < 0 ? ((__ptr__)k).addVirtualBytes(ky) : ((__ptr__)k).addVirtualBytes(ky); |
| 333 |
if((cmp = (cmpf!=null ? (Integer)((CFunction)cmpf).exe(dt,key,k,disc) |
| 334 |
: (sz <= 0 ? strcmp((CString)key,(CString)k) : UNSUPPORTED_INT("memcmp(key,k,sz))") ))) > 0) |
| 335 |
{ |
| 336 |
root.right = t._left; |
| 337 |
t._left = root; |
| 338 |
l.right = t; |
| 339 |
l = t; |
| 340 |
if(N(root = (ST_dtlink_s) t.right )) |
| 341 |
break; |
| 342 |
} |
| 343 |
else if(cmp == 0) |
| 344 |
{ l.right = root; |
| 345 |
l = root; |
| 346 |
root = t; |
| 347 |
break; |
| 348 |
} |
| 349 |
else |
| 350 |
{ r._left = t; |
| 351 |
r = t; |
| 352 |
l.right = root; |
| 353 |
l = root; |
| 354 |
if(N(root = (ST_dtlink_s) t._left )) |
| 355 |
break; |
| 356 |
} |
| 357 |
} |
| 358 |
else |
| 359 |
{ l.right = root; |
| 360 |
l = root; |
| 361 |
root = null; |
| 362 |
break; |
| 363 |
} |
| 364 |
} |
| 365 |
} |
| 366 |
} |
| 367 |
if(root!=null) |
| 368 |
{ |
| 369 |
dt.setInt("type", dt.type | 0100000); |
| 370 |
l.right = root._left; |
| 371 |
r._left = root.right; |
| 372 |
if((type&(0000004|0001000))!=0) |
| 373 |
{ |
| 374 |
throw new has_root(); |
| 375 |
} |
| 376 |
else if((type&0000010)!=0) |
| 377 |
{ root._left = link.right; |
| 378 |
root.right = null; |
| 379 |
link.right = root; |
| 380 |
|
| 381 |
if((root = (ST_dtlink_s) link._left)!=null ) |
| 382 |
{ while((t = (ST_dtlink_s) root._left)!=null ) { |
| 383 |
root._left = t.right; |
| 384 |
t.right = root; |
| 385 |
root = t; |
| 386 |
} |
| 387 |
link._left = root.right; |
| 388 |
throw new has_root(); |
| 389 |
} |
| 390 |
else throw new no_root(); |
| 391 |
} |
| 392 |
else if((type&0000020)!=0) { |
| 393 |
throw new UnsupportedOperationException(); |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
} |
| 406 |
else if((type&(0000002|0010000))!=0) { |
| 407 |
throw new UnsupportedOperationException(); |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
} |
| 419 |
else if((type&(0000001|0004000))!=0) |
| 420 |
{ if((dt.meth.type&0000004)!=0) |
| 421 |
throw new has_root(); |
| 422 |
else |
| 423 |
{ |
| 424 |
root._left = null; |
| 425 |
root.right = link._left; |
| 426 |
link._left = root; |
| 427 |
|
| 428 |
if(disc.makef!=null && (type&0000001)!=0) |
| 429 |
obj = (__ptr__) disc.makef.exe(dt,obj,disc); |
| 430 |
if(obj!=null) |
| 431 |
{ |
| 432 |
if(lk >= 0) |
| 433 |
root = (ST_dtlink_s) ((__ptr__)obj.addVirtualBytes(lk)).castTo(ST_dtlink_s.class); |
| 434 |
else |
| 435 |
{ |
| 436 |
root = (ST_dtlink_s)(((ST_dthold_s)dt.memoryf.exe( |
| 437 |
dt,null,sizeof(ST_dthold_s.class),disc)).castTo(ST_dtlink_s.class)); |
| 438 |
if(root!=null) |
| 439 |
root.castTo(ST_dthold_s.class).setPtr("obj", obj); |
| 440 |
else if(disc.makef!=null && disc.freef!=null && |
| 441 |
((type&0000001))!=0) |
| 442 |
UNSUPPORTED("(*disc->freef)(dt,obj,disc);"); |
| 443 |
} |
| 444 |
} |
| 445 |
if(root!=null) |
| 446 |
{ if(dt.data.size >= 0) |
| 447 |
dt.data.setInt("size", dt.data.size+1 ); |
| 448 |
throw new has_root(); |
| 449 |
} |
| 450 |
else throw new UnsupportedOperationException("goto no_root"); |
| 451 |
} |
| 452 |
} |
| 453 |
else if((type&0000040)!=0) { |
| 454 |
throw new UnsupportedOperationException(); |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
} |
| 469 |
} |
| 470 |
else |
| 471 |
{ |
| 472 |
r._left = null; |
| 473 |
l.right = null; |
| 474 |
if((type&0000010)!=0) |
| 475 |
{ |
| 476 |
|
| 477 |
if((root = (ST_dtlink_s) link._left)!=null ) |
| 478 |
{ while((t = (ST_dtlink_s) root._left)!=null ) { |
| 479 |
root._left = t.right; |
| 480 |
t.right = root; |
| 481 |
root = t; |
| 482 |
} |
| 483 |
link._left = root.right; |
| 484 |
throw new has_root(); |
| 485 |
} |
| 486 |
else throw new no_root(); |
| 487 |
|
| 488 |
} |
| 489 |
else if((type&0000020)!=0) |
| 490 |
throw new UnsupportedOperationException("goto dt_prev"); |
| 491 |
else if((type&(0000004|0001000))!=0) |
| 492 |
{ |
| 493 |
throw new no_root(); |
| 494 |
} |
| 495 |
else if((type&(0000001|0004000))!=0) |
| 496 |
{ |
| 497 |
if(disc.makef!=null && (type&0000001)!=0) |
| 498 |
obj = (__ptr__) disc.makef.exe(dt,obj,disc); |
| 499 |
if(obj!=null) |
| 500 |
{ |
| 501 |
if(lk >= 0) |
| 502 |
root = (ST_dtlink_s) ((__ptr__)obj.addVirtualBytes(lk)).castTo(ST_dtlink_s.class); |
| 503 |
else |
| 504 |
{ |
| 505 |
root = (ST_dtlink_s)(((ST_dthold_s)dt.memoryf.exe( |
| 506 |
dt,null,sizeof(ST_dthold_s.class),disc)).castTo(ST_dtlink_s.class)); |
| 507 |
if(root!=null) |
| 508 |
root.castTo(ST_dthold_s.class).setPtr("obj", obj); |
| 509 |
else if(disc.makef!=null && disc.freef!=null && |
| 510 |
((type&0000001))!=0) |
| 511 |
UNSUPPORTED("(*disc->freef)(dt,obj,disc);"); |
| 512 |
} |
| 513 |
} |
| 514 |
if(root!=null) |
| 515 |
{ if(dt.data.size >= 0) |
| 516 |
dt.data.setInt("size", dt.data.size+1 ); |
| 517 |
throw new has_root(); |
| 518 |
} |
| 519 |
else throw new UnsupportedOperationException("goto no_root"); |
| 520 |
} |
| 521 |
else if((type&0000040)!=0) |
| 522 |
{ root = me; |
| 523 |
dt.data.setInt("size", dt.data.size+1 ); |
| 524 |
throw new UnsupportedOperationException("goto has_root"); |
| 525 |
} |
| 526 |
else |
| 527 |
{ obj = null; |
| 528 |
throw new UnsupportedOperationException("goto no_root"); |
| 529 |
} |
| 530 |
|
| 531 |
} |
| 532 |
|
| 533 |
} catch (has_root has_root) { |
| 534 |
root = (ST_dtlink_s) root.castTo(ST_dtlink_s.class); |
| 535 |
root._left = link.right; |
| 536 |
root.right = link._left; |
| 537 |
if((dt.meth.type&0000010)!=0 && (type&(0000004|0001000))!=0 ) |
| 538 |
{ |
| 539 |
throw new UnsupportedOperationException(); |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
} |
| 552 |
dt.data.here = root; |
| 553 |
return (lk < 0 ? root.castTo_ST_dthold_s().obj : root.addVirtualBytes(-lk)); |
| 554 |
} catch (no_root no_root) { |
| 555 |
while((t = (ST_dtlink_s) r._left)!=null) |
| 556 |
r = t; |
| 557 |
r._left = link.right; |
| 558 |
dt.data.here = link._left; |
| 559 |
return (type&0000002)!=0 ? obj : null; |
| 560 |
} |
| 561 |
throw new UnsupportedOperationException(); |
| 562 |
} finally { |
| 563 |
LEAVING("abqfzg1d1vkzk51225tcdlik5","dttree"); |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
} |