00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
#include <nt.h>
00027
#include "triangle.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036 #define SwapPointers(Ptr1, Ptr2) { \
00037
PVOID _SWAP_POINTER_TEMP; \
00038
_SWAP_POINTER_TEMP = (PVOID)(Ptr1); \
00039
(Ptr1) = (Ptr2); \
00040
(Ptr2) = _SWAP_POINTER_TEMP; \
00041
}
00042
00043 #define SwapUlongs(Ptr1, Ptr2) { \
00044
ULONG _SWAP_POINTER_TEMP; \
00045
_SWAP_POINTER_TEMP = (ULONG)(Ptr1); \
00046
(Ptr1) = (Ptr2); \
00047
(Ptr2) = _SWAP_POINTER_TEMP; \
00048
}
00049
00050 #define SwapRefsButKeepFlags(Ref1, Ref2) { \
00051
ULONG _SWAP_ULONG_TEMP; \
00052
_SWAP_ULONG_TEMP = (ULONG)(Ref1); \
00053
(Ref1) = ((Ref2) & 0xfffffffc) | ((Ref1) & 0x00000003); \
00054
(Ref2) = (_SWAP_ULONG_TEMP & 0xfffffffc) | ((Ref2) & 0x00000003); \
00055
}
00056
00057
00058
00059
00060
00061
00062
00063 #define SetRefViaPointer(Ref, Ulong) { \
00064
if (Ref != NULL) { \
00065
(*(Ref)) = (((ULONG)(Ulong)) & 0xfffffffc) | ((ULONG)(*(Ref)) & 0x00000003); \
00066
} \
00067
}
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 PULONG
00087
TriAddressOfBackRefViaParent (
00088 IN
PTRI_SPLAY_LINKS Links
00089 );
00090
00091 PULONG
00092
TriAddressOfBackRefViaChild (
00093 IN
PTRI_SPLAY_LINKS Links
00094 );
00095
00096
VOID
00097
TriSwapSplayLinks (
00098 IN
PTRI_SPLAY_LINKS Link1,
00099 IN
PTRI_SPLAY_LINKS Link2
00100 );
00101
00102
VOID
00103
TriRotateRight (
00104 IN
PTRI_SPLAY_LINKS Links
00105 );
00106
00107
VOID
00108
TriRotateLeft (
00109 IN
PTRI_SPLAY_LINKS Links
00110 );
00111
00112
PTRI_SPLAY_LINKS
00113 TriSplay (
00114 IN
PTRI_SPLAY_LINKS Links
00115 )
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 {
00136
PTRI_SPLAY_LINKS Parent;
00137
PTRI_SPLAY_LINKS GrandParent;
00138
00139
00140
00141
00142
00143
while (!
TriIsRoot(Links)) {
00144
00145
00146
00147
00148
00149 Parent =
TriParent(Links);
00150
00151
if (
TriIsRoot(Parent)) {
00152
00153
00154
00155
00156
00157
if (
TriIsLeftChild(Links)) {
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
TriRotateRight(Parent);
00168
00169 }
else {
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
TriRotateLeft(Parent);
00181
00182 }
00183
00184 }
else {
00185
00186
00187
00188
00189
00190
00191 GrandParent =
TriParent(Parent);
00192
00193
if (
TriIsLeftChild(Links)) {
00194
00195
if (
TriIsLeftChild(Parent)) {
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
TriRotateRight(GrandParent);
00208
TriRotateRight(Parent);
00209
00210 }
else {
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
TriRotateRight(Parent);
00223
TriRotateLeft(GrandParent);
00224
00225 }
00226
00227 }
else {
00228
00229
if (
TriIsLeftChild(Parent)) {
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
TriRotateLeft(Parent);
00242
TriRotateRight(GrandParent);
00243
00244 }
else {
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
TriRotateLeft(GrandParent);
00257
TriRotateLeft(Parent);
00258
00259 }
00260
00261 }
00262
00263 }
00264
00265 }
00266
00267
return Links;
00268
00269 }
00270
00271
00272
PTRI_SPLAY_LINKS
00273 TriDelete (
00274 IN
PTRI_SPLAY_LINKS Links
00275 )
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 {
00297
PTRI_SPLAY_LINKS Predecessor;
00298
PTRI_SPLAY_LINKS Parent;
00299
PTRI_SPLAY_LINKS Child;
00300
00301 PULONG ParentChildRef;
00302
00303
00304
00305
00306
00307
00308
00309
if ((
TriLeftChild(Links) !=
NULL) && (
TriRightChild(Links) !=
NULL)) {
00310
00311
00312
00313
00314
00315 Predecessor =
TriSubtreePredecessor(Links);
00316
TriSwapSplayLinks(Predecessor, Links);
00317
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327
if ((
TriLeftChild(Links) ==
NULL) && (
TriRightChild(Links) ==
NULL)) {
00328
00329
00330
00331
00332
00333
if (
TriIsRoot(Links)) {
00334
00335
return NULL;
00336
00337 }
00338
00339
00340
00341
00342
00343 Parent =
TriParent(Links);
00344
if (
MakeIntoPointer(Parent->
Refs.Child) == Links &&
00345
MakeIntoPointer(Links->Refs.ParSib) == Parent) {
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 Parent->
Refs.Child = 0;
00357
return TriSplay(Parent);
00358
00359 }
else if (
TriIsLeftChild(Links)) {
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 Parent->
Refs.Child =
MakeIntoRightChildRef(Links->Refs.ParSib);
00371
return TriSplay(Parent);
00372
00373 }
else {
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 ParentChildRef =
TriAddressOfBackRefViaParent(Links);
00386 *ParentChildRef =
MakeIntoParentRef(Parent);
00387
return TriSplay(Parent);
00388
00389 }
00390
00391 }
00392
00393
00394
00395
00396
00397
00398
00399
if (
TriLeftChild(Links) !=
NULL) {
00400 Child =
TriLeftChild(Links);
00401 }
else {
00402 Child =
TriRightChild(Links);
00403 }
00404
00405
00406
00407
00408
00409
00410
if (
TriIsRoot(Links)) {
00411 Child->
Refs.ParSib =
MakeIntoParentRef(Child);
00412
return Child;
00413 }
00414
00415
00416
00417
00418
00419
00420
00421
00422 Parent =
TriParent(Links);
00423 ParentChildRef =
TriAddressOfBackRefViaParent(Links);
00424
SetRefViaPointer(ParentChildRef, Child);
00425 Child->
Refs.ParSib = Links->Refs.ParSib;
00426
00427
return TriSplay(Parent);
00428
00429 }
00430
00431
00432
PTRI_SPLAY_LINKS
00433 TriSubtreeSuccessor (
00434 IN
PTRI_SPLAY_LINKS Links
00435 )
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 {
00457
PTRI_SPLAY_LINKS Ptr;
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
if ((
Ptr =
TriRightChild(Links)) !=
NULL) {
00475
00476
while (
TriLeftChild(
Ptr) !=
NULL) {
00477
Ptr =
TriLeftChild(
Ptr);
00478 }
00479
00480
return Ptr;
00481
00482 }
00483
00484
00485
00486
00487
00488
return NULL;
00489
00490 }
00491
00492
00493
PTRI_SPLAY_LINKS
00494 TriSubtreePredecessor (
00495 IN
PTRI_SPLAY_LINKS Links
00496 )
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517 {
00518
PTRI_SPLAY_LINKS Ptr;
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
if ((
Ptr =
TriLeftChild(Links)) !=
NULL) {
00535
00536
while (
TriRightChild(
Ptr) !=
NULL) {
00537
Ptr =
TriRightChild(
Ptr);
00538 }
00539
00540
return Ptr;
00541
00542 }
00543
00544
00545
00546
00547
00548
return NULL;
00549
00550 }
00551
00552
00553
PTRI_SPLAY_LINKS
00554 TriRealSuccessor (
00555 IN
PTRI_SPLAY_LINKS Links
00556 )
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 {
00577
PTRI_SPLAY_LINKS Ptr;
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
if ((
Ptr =
TriRightChild(Links)) !=
NULL) {
00595
00596
while (
TriLeftChild(
Ptr) !=
NULL) {
00597
Ptr =
TriLeftChild(
Ptr);
00598 }
00599
00600
return Ptr;
00601
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
Ptr = Links;
00618
while (!
TriIsLeftChild(
Ptr) && !
TriIsRoot(
Ptr)) {
00619
Ptr =
TriParent(
Ptr);
00620 }
00621
00622
if (
TriIsLeftChild(
Ptr)) {
00623
return TriParent(
Ptr);
00624 }
00625
00626
00627
00628
00629
00630
return NULL;
00631
00632 }
00633
00634
00635
PTRI_SPLAY_LINKS
00636 TriRealPredecessor (
00637 IN
PTRI_SPLAY_LINKS Links
00638 )
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658 {
00659
PTRI_SPLAY_LINKS Ptr;
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
if ((
Ptr =
TriLeftChild(Links)) !=
NULL) {
00676
00677
while (
TriRightChild(
Ptr) !=
NULL) {
00678
Ptr =
TriRightChild(
Ptr);
00679 }
00680
00681
return Ptr;
00682
00683 }
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
Ptr = Links;
00699
while (
TriIsLeftChild(
Ptr)) {
00700
Ptr =
TriParent(
Ptr);
00701 }
00702
00703
if (!
TriIsLeftChild(
Ptr) && !
TriIsRoot(
Ptr)) {
00704
return TriParent(
Ptr);
00705 }
00706
00707
00708
00709
00710
00711
return NULL;
00712
00713 }
00714
00715
00716 PULONG
00717 TriAddressOfBackRefViaParent (
00718 IN
PTRI_SPLAY_LINKS Links
00719 )
00720
00721 {
00722
PTRI_SPLAY_LINKS Ptr;
00723
00724
00725
00726
00727
00728
00729
if (
TriIsRoot(Links)) {
00730
00731
return NULL;
00732
00733 }
00734
00735
00736
00737
00738
00739
00740
00741
00742
Ptr =
TriParent(Links);
00743
if (
MakeIntoPointer(
Ptr->Refs.Child) == Links) {
00744
return &(
Ptr->Refs.Child);
00745 }
else {
00746
return &(
MakeIntoPointer(
Ptr->Refs.Child)->Refs.ParSib);
00747 }
00748
00749 }
00750
00751
00752 PULONG
00753 TriAddressOfBackRefViaChild (
00754 IN
PTRI_SPLAY_LINKS Links
00755 )
00756
00757 {
00758
PTRI_SPLAY_LINKS Ptr;
00759
00760
00761
00762
00763
00764
Ptr =
MakeIntoPointer(Links->Refs.Child);
00765
00766
00767
00768
00769
00770
00771
if (
Ptr ==
NULL) {
00772
return NULL;
00773
00774
00775
00776
00777
00778
00779 }
else if (
MakeIntoPointer(
Ptr->Refs.ParSib) == Links) {
00780
return &(
Ptr->Refs.ParSib);
00781
00782
00783
00784
00785
00786
00787 }
else {
00788
return &(
MakeIntoPointer(
Ptr->Refs.ParSib)->Refs.ParSib);
00789
00790 }
00791
00792 }
00793
00794
00795
VOID
00796 TriSwapSplayLinks (
00797 IN
PTRI_SPLAY_LINKS Link1,
00798 IN
PTRI_SPLAY_LINKS Link2
00799 )
00800
00801 {
00802 PULONG Parent1ChildRef;
00803 PULONG Parent2ChildRef;
00804
00805 PULONG Child1ParSibRef;
00806 PULONG Child2ParSibRef;
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
if ((
TriIsRoot(Link1)) ||
00828 (
TriParent(Link2) == Link1) ||
00829 (
MakeIntoPointer(Link1->Refs.ParSib) == Link2)) {
00830
00831
SwapPointers(Link1, Link2);
00832
00833 }
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
if (
TriParent(Link1) != Link2) {
00856
00857
if (!
TriIsRoot(Link2)) {
00858
00859
if (
MakeIntoPointer(Link2->Refs.ParSib) != Link1) {
00860
00861
00862
00863
00864
00865
00866
00867 Parent1ChildRef =
TriAddressOfBackRefViaParent(Link1);
00868 Child1ParSibRef =
TriAddressOfBackRefViaChild(Link1);
00869 Parent2ChildRef =
TriAddressOfBackRefViaParent(Link2);
00870 Child2ParSibRef =
TriAddressOfBackRefViaChild(Link2);
00871
SwapUlongs(Link1->Refs.Child, Link2->Refs.Child);
00872
SwapUlongs(Link1->Refs.ParSib, Link2->Refs.ParSib);
00873
SetRefViaPointer(Parent1ChildRef, Link2);
00874
SetRefViaPointer(Parent2ChildRef, Link1);
00875
SetRefViaPointer(Child1ParSibRef, Link2);
00876
SetRefViaPointer(Child2ParSibRef, Link1);
00877
00878 }
else {
00879
00880
00881
00882
00883
00884
00885
00886 Child1ParSibRef =
TriAddressOfBackRefViaChild(Link1);
00887 Parent2ChildRef =
TriAddressOfBackRefViaParent(Link2);
00888 Child2ParSibRef =
TriAddressOfBackRefViaChild(Link2);
00889
SwapUlongs(Link1->Refs.Child, Link2->Refs.Child);
00890
SetRefViaPointer(Child1ParSibRef, Link2);
00891
SetRefViaPointer(Child2ParSibRef, Link1);
00892 *Parent2ChildRef =
MakeIntoLeftChildRef(Link1);
00893 Link2->Refs.ParSib = Link1->Refs.ParSib;
00894 Link1->Refs.ParSib =
MakeIntoSiblingRef(Link2);
00895
00896 }
00897
00898 }
else {
00899
00900
00901
00902
00903
00904
00905 Parent1ChildRef =
TriAddressOfBackRefViaParent(Link1);
00906 Child1ParSibRef =
TriAddressOfBackRefViaChild(Link1);
00907 Child2ParSibRef =
TriAddressOfBackRefViaChild(Link2);
00908
SwapUlongs(Link1->Refs.Child, Link2->Refs.Child);
00909 Link2->Refs.ParSib = Link1->Refs.ParSib;
00910 Link1->Refs.ParSib =
MakeIntoParentRef(Link1);
00911
SetRefViaPointer(Child1ParSibRef, Link2);
00912
SetRefViaPointer(Child2ParSibRef, Link1);
00913
SetRefViaPointer(Parent1ChildRef, Link2);
00914
00915 }
00916
00917 }
else {
00918
00919
if (
MakeIntoPointer(Link2->Refs.Child) == Link1 &&
00920
MakeIntoPointer(Link1->Refs.ParSib) == Link2) {
00921
00922
if (!
TriIsRoot(Link2)) {
00923
00924
00925
00926
00927
00928
00929 Child1ParSibRef =
TriAddressOfBackRefViaChild(Link1);
00930 Parent2ChildRef =
TriAddressOfBackRefViaParent(Link2);
00931
SetRefViaPointer(Child1ParSibRef, Link2);
00932
SetRefViaPointer(Parent2ChildRef, Link1);
00933 Link1->Refs.ParSib = Link2->Refs.ParSib;
00934 Link2->Refs.ParSib =
MakeIntoParentRef(Link1);
00935
SwapRefsButKeepFlags(Link1->Refs.Child, Link2->Refs.Child);
00936
SetRefViaPointer(&Link1->Refs.Child, Link2);
00937
00938 }
else {
00939
00940
00941
00942
00943
00944
00945 Child1ParSibRef =
TriAddressOfBackRefViaChild(Link1);
00946
SetRefViaPointer(Child1ParSibRef, Link2);
00947 Link1->Refs.ParSib =
MakeIntoParentRef(Link1);
00948 Link2->Refs.ParSib =
MakeIntoParentRef(Link1);
00949
SwapRefsButKeepFlags(Link1->Refs.Child, Link2->Refs.Child);
00950
SetRefViaPointer(&Link1->Refs.Child, Link2);
00951
00952 }
00953
00954 }
else if (
TriIsLeftChild(Link1)) {
00955
00956
if (!
TriIsRoot(Link2)) {
00957
00958
00959
00960
00961
00962
00963 Child1ParSibRef =
TriAddressOfBackRefViaChild(Link1);
00964 Parent2ChildRef =
TriAddressOfBackRefViaParent(Link2);
00965 Child2ParSibRef =
TriAddressOfBackRefViaChild(Link2);
00966
SetRefViaPointer(Child1ParSibRef, Link2);
00967
SetRefViaPointer(Parent2ChildRef, Link1);
00968
SetRefViaPointer(Child2ParSibRef, Link1);
00969 Link2->Refs.Child = Link1->Refs.Child;
00970 Link1->Refs.Child =
MakeIntoLeftChildRef(Link2);
00971
SwapUlongs(Link1->Refs.ParSib, Link2->Refs.ParSib);
00972
00973 }
else {
00974
00975
00976
00977
00978
00979
00980 Child1ParSibRef =
TriAddressOfBackRefViaChild(Link1);
00981 Child2ParSibRef =
TriAddressOfBackRefViaChild(Link2);
00982
SetRefViaPointer(Child1ParSibRef, Link2);
00983
SetRefViaPointer(Child2ParSibRef, Link1);
00984 Link2->Refs.Child = Link1->Refs.Child;
00985 Link1->Refs.Child =
MakeIntoLeftChildRef(Link2);
00986 Link2->Refs.ParSib = Link1->Refs.ParSib;
00987 Link1->Refs.ParSib =
MakeIntoParentRef(Link1);
00988
00989 }
00990
00991 }
else {
00992
00993
if (!
TriIsRoot(Link2)) {
00994
00995
00996
00997
00998
00999
01000 Parent1ChildRef =
TriAddressOfBackRefViaParent(Link1);
01001 Child1ParSibRef =
TriAddressOfBackRefViaChild(Link1);
01002 Parent2ChildRef =
TriAddressOfBackRefViaParent(Link2);
01003
SetRefViaPointer(Parent1ChildRef, Link2);
01004
SetRefViaPointer(Child1ParSibRef, Link2);
01005
SetRefViaPointer(Parent2ChildRef, Link1);
01006
SwapUlongs(Link1->Refs.Child, Link2->Refs.Child);
01007 Link1->Refs.ParSib = Link2->Refs.ParSib;
01008 Link2->Refs.ParSib =
MakeIntoParentRef(Link1);
01009
01010 }
else {
01011
01012
01013
01014
01015
01016
01017 Parent1ChildRef =
TriAddressOfBackRefViaParent(Link1);
01018 Child1ParSibRef =
TriAddressOfBackRefViaChild(Link1);
01019
SetRefViaPointer(Parent1ChildRef, Link2);
01020
SetRefViaPointer(Child1ParSibRef, Link2);
01021
SwapUlongs(Link1->Refs.Child, Link2->Refs.Child);
01022 Link1->Refs.ParSib =
MakeIntoParentRef(Link1);
01023 Link1->Refs.ParSib =
MakeIntoParentRef(Link1);
01024
01025 }
01026
01027 }
01028
01029 }
01030
01031 }
01032
01033
01034
VOID
01035 TriRotateRight (
01036 IN
PTRI_SPLAY_LINKS Links
01037 )
01038
01039 {
01040 BOOLEAN IsRoot;
01041 PULONG ParentChildRef;
01042 ULONG SavedParSibRef;
01043
PTRI_SPLAY_LINKS LeftChild;
01044
PTRI_SPLAY_LINKS a,b,
c;
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
if (
TriIsRoot(Links)) {
01067 IsRoot =
TRUE;
01068 }
else {
01069 IsRoot =
FALSE;
01070 ParentChildRef =
TriAddressOfBackRefViaParent(Links);
01071 SavedParSibRef = Links->Refs.ParSib;
01072 }
01073
01074
01075
01076
01077
01078
01079
01080 LeftChild =
TriLeftChild(Links);
01081 a =
TriLeftChild(LeftChild);
01082 b =
TriRightChild(LeftChild);
01083
c =
TriRightChild(Links);
01084
01085
if ((a !=
NULL) && (b !=
NULL) && (
c !=
NULL)) {
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097 a->
Refs.ParSib =
MakeIntoSiblingRef(Links);
01098 b->
Refs.ParSib =
MakeIntoSiblingRef(
c);
01099 Links->Refs.Child =
MakeIntoLeftChildRef(b);
01100 Links->Refs.ParSib =
MakeIntoParentRef(LeftChild);
01101
01102 }
else if ((a !=
NULL) && (b !=
NULL) && (
c ==
NULL)) {
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114 a->
Refs.ParSib =
MakeIntoSiblingRef(Links);
01115 b->
Refs.ParSib =
MakeIntoParentRef(Links);
01116 Links->Refs.Child =
MakeIntoLeftChildRef(b);
01117 Links->Refs.ParSib =
MakeIntoParentRef(LeftChild);
01118
01119 }
else if ((a !=
NULL) && (b ==
NULL) && (
c !=
NULL)) {
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131 a->
Refs.ParSib =
MakeIntoSiblingRef(Links);
01132 Links->Refs.Child =
MakeIntoRightChildRef(
c);
01133 Links->Refs.ParSib =
MakeIntoParentRef(LeftChild);
01134
01135 }
else if ((a !=
NULL) && (b ==
NULL) && (
c ==
NULL)) {
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147 a->
Refs.ParSib =
MakeIntoSiblingRef(Links);
01148 Links->Refs.Child = 0
L;
01149 Links->Refs.ParSib =
MakeIntoParentRef(LeftChild);
01150
01151 }
else if ((a ==
NULL) && (b !=
NULL) && (
c !=
NULL)) {
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163 b->
Refs.ParSib =
MakeIntoSiblingRef(
c);
01164 Links->Refs.Child =
MakeIntoLeftChildRef(b);
01165 Links->Refs.ParSib =
MakeIntoParentRef(LeftChild);
01166 LeftChild->
Refs.Child =
MakeIntoRightChildRef(Links);
01167
01168 }
else if ((a ==
NULL) && (b !=
NULL) && (
c ==
NULL)) {
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180 b->
Refs.ParSib =
MakeIntoParentRef(Links);
01181 Links->Refs.Child =
MakeIntoLeftChildRef(b);
01182 Links->Refs.ParSib =
MakeIntoParentRef(LeftChild);
01183 LeftChild->
Refs.Child =
MakeIntoRightChildRef(Links);
01184
01185 }
else if ((a ==
NULL) && (b ==
NULL) && (
c !=
NULL)) {
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197 Links->Refs.Child =
MakeIntoRightChildRef(
c);
01198 Links->Refs.ParSib =
MakeIntoParentRef(LeftChild);
01199 LeftChild->
Refs.Child =
MakeIntoRightChildRef(Links);
01200
01201 }
else if ((a ==
NULL) && (b ==
NULL) && (
c ==
NULL)) {
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212 Links->Refs.Child = 0
L;
01213 Links->Refs.ParSib =
MakeIntoParentRef(LeftChild);
01214 LeftChild->
Refs.Child =
MakeIntoRightChildRef(Links);
01215
01216 }
01217
01218
if (IsRoot) {
01219 LeftChild->
Refs.ParSib =
MakeIntoParentRef(LeftChild);
01220 }
else {
01221 LeftChild->
Refs.ParSib = SavedParSibRef;
01222
SetRefViaPointer(ParentChildRef, LeftChild);
01223 }
01224
01225 }
01226
01227
01228
VOID
01229 TriRotateLeft (
01230 IN
PTRI_SPLAY_LINKS Links
01231 )
01232
01233 {
01234 BOOLEAN IsRoot;
01235 PULONG ParentChildRef;
01236 ULONG SavedParSibRef;
01237
PTRI_SPLAY_LINKS RightChild;
01238
PTRI_SPLAY_LINKS a,b,
c;
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
if (
TriIsRoot(Links)) {
01261 IsRoot =
TRUE;
01262 }
else {
01263 IsRoot =
FALSE;
01264 ParentChildRef =
TriAddressOfBackRefViaParent(Links);
01265 SavedParSibRef = Links->Refs.ParSib;
01266 }
01267
01268
01269
01270
01271
01272
01273
01274 RightChild =
TriRightChild(Links);
01275 a =
TriLeftChild(Links);
01276 b =
TriLeftChild(RightChild);
01277
c =
TriRightChild(RightChild);
01278
01279
if ((a !=
NULL) && (b !=
NULL) && (
c !=
NULL)) {
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291 a->
Refs.ParSib =
MakeIntoSiblingRef(b);
01292 b->
Refs.ParSib =
MakeIntoParentRef(Links);
01293 Links->Refs.ParSib =
MakeIntoSiblingRef(
c);
01294 RightChild->
Refs.Child =
MakeIntoLeftChildRef(Links);
01295
01296 }
else if ((a !=
NULL) && (b !=
NULL) && (
c ==
NULL)) {
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308 a->
Refs.ParSib =
MakeIntoSiblingRef(b);
01309 b->
Refs.ParSib =
MakeIntoParentRef(Links);
01310 Links->Refs.ParSib =
MakeIntoParentRef(RightChild);
01311 RightChild->
Refs.Child =
MakeIntoLeftChildRef(Links);
01312
01313 }
else if ((a !=
NULL) && (b ==
NULL) && (
c !=
NULL)) {
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325 a->
Refs.ParSib =
MakeIntoParentRef(Links);
01326 Links->Refs.ParSib =
MakeIntoSiblingRef(
c);
01327 RightChild->
Refs.Child =
MakeIntoLeftChildRef(Links);
01328
01329 }
else if ((a !=
NULL) && (b ==
NULL) && (
c ==
NULL)) {
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341 a->
Refs.ParSib =
MakeIntoParentRef(Links);
01342 Links->Refs.ParSib =
MakeIntoParentRef(RightChild);
01343 RightChild->
Refs.Child =
MakeIntoLeftChildRef(Links);
01344
01345 }
else if ((a ==
NULL) && (b !=
NULL) && (
c !=
NULL)) {
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357 b->
Refs.ParSib =
MakeIntoParentRef(Links);
01358 Links->Refs.Child =
MakeIntoRightChildRef(b);
01359 Links->Refs.ParSib =
MakeIntoSiblingRef(
c);
01360 RightChild->
Refs.Child =
MakeIntoLeftChildRef(Links);
01361
01362 }
else if ((a ==
NULL) && (b !=
NULL) && (
c ==
NULL)) {
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374 b->
Refs.ParSib =
MakeIntoParentRef(Links);
01375 Links->Refs.Child =
MakeIntoRightChildRef(b);
01376 Links->Refs.ParSib =
MakeIntoParentRef(RightChild);
01377 RightChild->
Refs.Child =
MakeIntoLeftChildRef(Links);
01378
01379 }
else if ((a ==
NULL) && (b ==
NULL) && (
c !=
NULL)) {
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391 Links->Refs.Child = 0
L;
01392 Links->Refs.ParSib =
MakeIntoSiblingRef(
c);
01393 RightChild->
Refs.Child =
MakeIntoLeftChildRef(Links);
01394
01395 }
else if ((a ==
NULL) && (b ==
NULL) && (
c ==
NULL)) {
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407 Links->Refs.Child = 0
L;
01408 Links->Refs.ParSib =
MakeIntoParentRef(RightChild);
01409 RightChild->
Refs.Child =
MakeIntoLeftChildRef(Links);
01410
01411 }
01412
01413
if (IsRoot) {
01414 RightChild->
Refs.ParSib =
MakeIntoParentRef(RightChild);
01415 }
else {
01416 RightChild->
Refs.ParSib = SavedParSibRef;
01417
SetRefViaPointer(ParentChildRef, RightChild);
01418 }
01419
01420 }