/usr/include/ace/RB_Tree.cpp is in libace-dev 6.3.3+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 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 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 | #ifndef ACE_RB_TREE_CPP
#define ACE_RB_TREE_CPP
#include "ace/Global_Macros.h"
#include "ace/RB_Tree.h"
#include "ace/SString.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#if !defined (__ACE_INLINE__)
#include "ace/RB_Tree.inl"
#endif /* __ACE_INLINE__ */
#include "ace/Log_Category.h"
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
// Constructor.
template <class EXT_ID, class INT_ID>
ACE_RB_Tree_Node<EXT_ID, INT_ID>::ACE_RB_Tree_Node (const EXT_ID &k, const INT_ID &t)
: k_ (k),
t_ (t),
color_ (RED),
parent_ (0),
left_ (0),
right_ (0)
{
ACE_TRACE ("ACE_RB_Tree_Node<EXT_ID, INT_ID>::ACE_RB_Tree_Node (const EXT_ID &k, const INT_ID &t)");
}
// Destructor.
template <class EXT_ID, class INT_ID>
ACE_RB_Tree_Node<EXT_ID, INT_ID>::~ACE_RB_Tree_Node (void)
{
ACE_TRACE ("ACE_RB_Tree_Node<EXT_ID, INT_ID>::~ACE_RB_Tree_Node");
}
// Constructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree (ACE_Allocator *alloc)
: root_ (0),
current_size_ (0)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree (ACE_Allocator *alloc)");
allocator_ = alloc;
if (this->open (alloc) == -1)
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT ("ACE_RB_Tree::ACE_RB_Tree\n")));
}
// Copy constructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &rbt)
: root_ (0),
current_size_ (0)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &rbt)");
ACE_WRITE_GUARD (ACE_LOCK, ace_mon, this->lock_);
allocator_ = rbt.allocator_;
// Make a deep copy of the passed tree.
ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> iter(rbt);
for (iter.first ();
iter.is_done () == 0; iter.next ())
insert_i (*(iter.key ()),
*(iter.item ()));
}
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree (
void *location,
ACE_Allocator *alloc
)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree (void *, ACE_Allocator *)");
if (location != this)
{
this->root_ = 0;
this->current_size_ = 0;
}
this->allocator_ = alloc;
}
// Destructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::~ACE_RB_Tree ()
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::~ACE_RB_Tree");
// Use the locked public method, to be totally safe, as the class
// can be used with an allocator and placement new.
this->close ();
}
// Assignment operator.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> void
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::operator = (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &rbt)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::operator =");
ACE_WRITE_GUARD (ACE_LOCK, ace_mon, this->lock_);
if (this != &rbt)
{
// Clear out the existing tree.
close_i ();
// Make a deep copy of the passed tree.
ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> iter(rbt);
for (iter.first ();
iter.is_done () == 0;
iter.next ())
insert_i (*(iter.key ()),
*(iter.item ()));
// Use the same allocator as the rhs.
allocator_ = rbt.allocator_;
}
}
// Less than comparison function for keys, default functor
// implementation returns 1 if k1 < k2, 0 otherwise.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::lessthan (const EXT_ID &k1, const EXT_ID &k2)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::lessthan");
return this->compare_keys_ (k1, k2);
}
// Method for right rotation of the tree about a given node.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> void
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_rotate_right (ACE_RB_Tree_Node<EXT_ID, INT_ID> *x)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_rotate_right");
if (!x)
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nerror: x is a null pointer in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::RB_rotate_right\n")));
else if (! (x->left()))
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nerror: x->left () is a null pointer in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::RB_rotate_right\n")));
else
{
ACE_RB_Tree_Node<EXT_ID, INT_ID> * y;
y = x->left ();
x->left (y->right ());
if (y->right ())
y->right ()->parent (x);
y->parent (x->parent ());
if (x->parent ())
{
if (x == x->parent ()->right ())
x->parent ()->right (y);
else
x->parent ()->left (y);
}
else
root_ = y;
y->right (x);
x->parent (y);
}
}
// Method for left rotation of the tree about a given node.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> void
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_rotate_left (ACE_RB_Tree_Node<EXT_ID, INT_ID> * x)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_rotate_left");
if (! x)
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nerror: x is a null pointer in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::RB_rotate_left\n")));
else if (! (x->right()))
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nerror: x->right () is a null pointer ")
ACE_TEXT ("in ACE_RB_Tree<EXT_ID, INT_ID>::RB_rotate_left\n")));
else
{
ACE_RB_Tree_Node<EXT_ID, INT_ID> * y;
y = x->right ();
x->right (y->left ());
if (y->left ())
y->left ()->parent (x);
y->parent (x->parent ());
if (x->parent ())
{
if (x == x->parent ()->left ())
x->parent ()->left (y);
else
x->parent ()->right (y);
}
else
root_ = y;
y->left (x);
x->parent (y);
}
}
// Method for restoring Red-Black properties after a specific deletion case.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> void
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::
RB_delete_fixup (ACE_RB_Tree_Node<EXT_ID, INT_ID> *x,
ACE_RB_Tree_Node<EXT_ID, INT_ID> *parent)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_delete_fixup");
while (x != this->root_
&& (!x
|| x->color () == ACE_RB_Tree_Node_Base::BLACK))
{
if (x == parent->left ())
{
ACE_RB_Tree_Node<EXT_ID, INT_ID> *w = parent->right ();
if (w && w->color () == ACE_RB_Tree_Node_Base::RED)
{
w->color (ACE_RB_Tree_Node_Base::BLACK);
parent->color (ACE_RB_Tree_Node_Base::RED);
RB_rotate_left (parent);
w = parent->right ();
}
// CLR pp. 263 says that nil nodes are implicitly colored BLACK
if (w
&& (!w->left ()
|| w->left ()->color () == ACE_RB_Tree_Node_Base::BLACK)
&& (!w->right ()
|| w->right ()->color () == ACE_RB_Tree_Node_Base::BLACK))
{
w->color (ACE_RB_Tree_Node_Base::RED);
x = parent;
parent = x->parent ();
}
else
{
// CLR pp. 263 says that nil nodes are implicitly colored BLACK
if (w
&& (!w->right ()
|| w->right ()->color () == ACE_RB_Tree_Node_Base::BLACK))
{
if (w->left ())
w->left ()->color (ACE_RB_Tree_Node_Base::BLACK);
w->color (ACE_RB_Tree_Node_Base::RED);
RB_rotate_right (w);
w = parent->right ();
}
if (w)
{
w->color (parent->color ());
if (w->right ())
w->right ()->color (ACE_RB_Tree_Node_Base::BLACK);
}
parent->color (ACE_RB_Tree_Node_Base::BLACK);
RB_rotate_left (parent);
x = root_;
}
}
else
{
ACE_RB_Tree_Node<EXT_ID, INT_ID> *w = parent->left ();
if (w && w->color () == ACE_RB_Tree_Node_Base::RED)
{
w->color (ACE_RB_Tree_Node_Base::BLACK);
parent->color (ACE_RB_Tree_Node_Base::RED);
RB_rotate_right (parent);
w = parent->left ();
}
// CLR pp. 263 says that nil nodes are implicitly colored BLACK
if (w
&& (!w->left ()
|| w->left ()->color () == ACE_RB_Tree_Node_Base::BLACK)
&& (!w->right ()
|| w->right ()->color () == ACE_RB_Tree_Node_Base::BLACK))
{
w->color (ACE_RB_Tree_Node_Base::RED);
x = parent;
parent = x->parent ();
}
else
{
// CLR pp. 263 says that nil nodes are implicitly colored BLACK
if (w
&& (!w->left ()
|| w->left ()->color () == ACE_RB_Tree_Node_Base::BLACK))
{
w->color (ACE_RB_Tree_Node_Base::RED);
if (w->right ())
w->right ()->color (ACE_RB_Tree_Node_Base::BLACK);
RB_rotate_left (w);
w = parent->left ();
}
if (w)
{
w->color (parent->color ());
if (w->left ())
w->left ()->color (ACE_RB_Tree_Node_Base::BLACK);
}
parent->color (ACE_RB_Tree_Node_Base::BLACK);
RB_rotate_right (parent);
x = root_;
}
}
}
if (x)
x->color (ACE_RB_Tree_Node_Base::BLACK);
}
// Return a pointer to a matching node if there is one, a pointer to
// the node under which to insert the item if the tree is not empty
// and there is no such match, or 0 if the tree is empty.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> ACE_RB_Tree_Node<EXT_ID, INT_ID> *
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::find_node (const EXT_ID &k, ACE_RB_Tree_Base::RB_SearchResult &result)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::find_node");
// Start at the root.
ACE_RB_Tree_Node<EXT_ID, INT_ID> *current = root_;
while (current)
{
// While there are more nodes to examine.
if (this->lessthan (current->key (), k))
{
// If the search key is greater than the current node's key.
if (current->right ())
// If the right subtree is not empty, search to the right.
current = current->right ();
else
{
// If the right subtree is empty, we're done searching,
// and are positioned to the left of the insertion point.
result = LEFT;
break;
}
}
else if (this->lessthan (k, current->key ()))
{
// Else if the search key is less than the current node's key.
if (current->left ())
// If the left subtree is not empty, search to the left.
current = current->left ();
else
{
// If the left subtree is empty, we're done searching,
// and are positioned to the right of the insertion point.
result = RIGHT;
break;
}
}
else
{
// If the keys match exactly, we're done as well.
result = EXACT;
break;
}
}
return current;
}
// Rebalance the tree after insertion of a node.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> void
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_rebalance (ACE_RB_Tree_Node<EXT_ID, INT_ID> * x)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_rebalance");
ACE_RB_Tree_Node<EXT_ID, INT_ID> *y = 0;
while (x &&
x->parent ()
&& x->parent ()->color () == ACE_RB_Tree_Node_Base::RED)
{
if (! x->parent ()->parent ())
{
// If we got here, something is drastically wrong!
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nerror: parent's parent is null in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::RB_rebalance\n")));
return;
}
if (x->parent () == x->parent ()->parent ()->left ())
{
y = x->parent ()->parent ()->right ();
if (y && y->color () == ACE_RB_Tree_Node_Base::RED)
{
// Handle case 1 (see CLR book, pp. 269).
x->parent ()->color (ACE_RB_Tree_Node_Base::BLACK);
y->color (ACE_RB_Tree_Node_Base::BLACK);
x->parent ()->parent ()->color (ACE_RB_Tree_Node_Base::RED);
x = x->parent ()->parent ();
}
else
{
if (x == x->parent ()->right ())
{
// Transform case 2 into case 3 (see CLR book, pp. 269).
x = x->parent ();
RB_rotate_left (x);
}
// Handle case 3 (see CLR book, pp. 269).
x->parent ()->color (ACE_RB_Tree_Node_Base::BLACK);
x->parent ()->parent ()->color (ACE_RB_Tree_Node_Base::RED);
RB_rotate_right (x->parent ()->parent ());
}
}
else
{
y = x->parent ()->parent ()->left ();
if (y && y->color () == ACE_RB_Tree_Node_Base::RED)
{
// Handle case 1 (see CLR book, pp. 269).
x->parent ()->color (ACE_RB_Tree_Node_Base::BLACK);
y->color (ACE_RB_Tree_Node_Base::BLACK);
x->parent ()->parent ()->color (ACE_RB_Tree_Node_Base::RED);
x = x->parent ()->parent ();
}
else
{
if (x == x->parent ()->left ())
{
// Transform case 2 into case 3 (see CLR book, pp. 269).
x = x->parent ();
RB_rotate_right (x);
}
// Handle case 3 (see CLR book, pp. 269).
x->parent ()->color (ACE_RB_Tree_Node_Base::BLACK);
x->parent ()->parent ()->color (ACE_RB_Tree_Node_Base::RED);
RB_rotate_left (x->parent ()->parent ());
}
}
}
}
// Method to find the successor node of the given node in the tree.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> ACE_RB_Tree_Node<EXT_ID, INT_ID> *
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_tree_successor (ACE_RB_Tree_Node<EXT_ID, INT_ID> *x) const
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_tree_successor");
if (x == 0)
return 0;
if (x->right ())
return RB_tree_minimum (x->right ());
ACE_RB_Tree_Node<EXT_ID, INT_ID> *y = x->parent ();
while ((y) && (x == y->right ()))
{
x = y;
y = y->parent ();
}
return y;
}
// Method to find the predecessor node of the given node in the tree.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> ACE_RB_Tree_Node<EXT_ID, INT_ID> *
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_tree_predecessor (ACE_RB_Tree_Node<EXT_ID, INT_ID> *x) const
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_tree_predecessor");
if (x == 0)
return 0;
if (x->left ())
return RB_tree_maximum (x->left ());
ACE_RB_Tree_Node<EXT_ID, INT_ID> *y = x->parent ();
while ((y) && (x == y->left ()))
{
x = y;
y = y->parent ();
}
return y;
}
// Method to find the minimum node of the subtree rooted at the given node.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> ACE_RB_Tree_Node<EXT_ID, INT_ID> *
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_tree_minimum (ACE_RB_Tree_Node<EXT_ID, INT_ID> *x) const
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_tree_minimum");
while ((x) && (x->left ()))
x = x->left ();
return x;
}
// Method to find the maximum node of the subtree rooted at the given node.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> ACE_RB_Tree_Node<EXT_ID, INT_ID> *
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_tree_maximum (ACE_RB_Tree_Node<EXT_ID, INT_ID> *x) const
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_tree_maximum");
while ((x) && (x->right ()))
x = x->right ();
return x;
}
// Delete children (left and right) of the node. Must be called with
// lock held.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
void ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::delete_children_i
(ACE_RB_Tree_Node<EXT_ID, INT_ID> *parent)
{
if (parent)
{
this->delete_children_i (parent->left ());
this->delete_children_i (parent->right ());
ACE_DES_FREE_TEMPLATE2
(parent->left (),
this->allocator_->free,
ACE_RB_Tree_Node,
EXT_ID, INT_ID);
ACE_DES_FREE_TEMPLATE2
(parent->right (),
this->allocator_->free,
ACE_RB_Tree_Node,
EXT_ID, INT_ID);
parent->left (0);
parent->right (0);
}
return;
}
// Close down an RB_Tree. this method should only be called with
// locks already held.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::close_i ()
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::close_i");
this->delete_children_i (this->root_);
ACE_DES_FREE_TEMPLATE2 (this->root_,
this->allocator()->free,
ACE_RB_Tree_Node,
EXT_ID, INT_ID);
this->current_size_ = 0;
this->root_ = 0;
return 0;
}
// Returns a pointer to the item corresponding to the given key, or 0
// if it cannot find the key in the tree. This method should only be
// called with locks already held.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::find_i (const EXT_ID &k,
ACE_RB_Tree_Node<EXT_ID, INT_ID>* &entry, int find_exact)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::find_i");
// Try to find a match.
RB_SearchResult result = LEFT;
ACE_RB_Tree_Node<EXT_ID, INT_ID> *current = find_node (k, result);
if (current)
{
// Found a match
if (!find_exact || result == EXACT)
entry = current; // Assign the entry for any match.
return (result == EXACT ? 0 : -1);
}
else
// The node is not there.
return -1;
}
// Inserts a *copy* of the key and the item into the tree: both the
// key type EXT_ID and the item type INT_ID must have well defined
// semantics for copy construction and < comparison. This method
// returns a pointer to the inserted item copy, or 0 if an error
// occurred. NOTE: if an identical key already exists in the tree, no
// new item is created, and the returned pointer addresses the
// existing item associated with the existing key. This method should
// only be called with locks already held.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> INT_ID *
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::insert_i (const EXT_ID &k, const INT_ID &t)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::insert_i (const EXT_ID &k, const INT_ID &t)");
// Find the closest matching node, if there is one.
RB_SearchResult result = LEFT;
ACE_RB_Tree_Node<EXT_ID, INT_ID> *current = find_node (k, result);
if (current)
{
// If the keys match, just return a pointer to the node's item.
if (result == EXACT)
return ¤t->item ();
// Otherwise if we're to the left of the insertion point, insert
// into the right subtree.
else if (result == LEFT)
{
if (current->right ())
{
// If there is already a right subtree, complain.
ACELIB_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nright subtree already present in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::insert_i\n")),
0);
}
else
{
// The right subtree is empty: insert new node there.
ACE_RB_Tree_Node<EXT_ID, INT_ID> *tmp = 0;
ACE_NEW_MALLOC_RETURN
(tmp,
(reinterpret_cast<ACE_RB_Tree_Node<EXT_ID, INT_ID>*>
(this->allocator_->malloc (sizeof (*tmp)))),
(ACE_RB_Tree_Node<EXT_ID, INT_ID>) (k, t),
0);
current->right (tmp);
// If the node was successfully inserted, set its
// parent, rebalance the tree, color the root black, and
// return a pointer to the inserted item.
INT_ID *item = &(current->right ()->item ());
current->right ()->parent (current);
RB_rebalance (current->right ());
root_->color (ACE_RB_Tree_Node_Base::BLACK);
++current_size_;
return item;
}
}
// Otherwise, we're to the right of the insertion point, so
// insert into the left subtree.
else // (result == RIGHT)
{
if (current->left ())
// If there is already a left subtree, complain.
ACELIB_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nleft subtree already present in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::insert_i\n")),
0);
else
{
// The left subtree is empty: insert new node there.
ACE_RB_Tree_Node<EXT_ID, INT_ID> *tmp = 0;
ACE_NEW_MALLOC_RETURN
(tmp,
(reinterpret_cast<ACE_RB_Tree_Node<EXT_ID, INT_ID>*>
(this->allocator_->malloc (sizeof (*tmp)))),
(ACE_RB_Tree_Node<EXT_ID, INT_ID>) (k, t),
0);
current->left (tmp);
// If the node was successfully inserted, set its
// parent, rebalance the tree, color the root black, and
// return a pointer to the inserted item.
INT_ID *item = ¤t->left ()->item ();
current->left ()->parent (current);
RB_rebalance (current->left ());
root_->color (ACE_RB_Tree_Node_Base::BLACK);
++current_size_;
return item;
}
}
}
else
{
// The tree is empty: insert at the root and color the root
// black.
ACE_NEW_MALLOC_RETURN
(this->root_,
(reinterpret_cast<ACE_RB_Tree_Node<EXT_ID, INT_ID>*>
(this->allocator_->malloc (sizeof (ACE_RB_Tree_Node<EXT_ID, INT_ID>)))),
(ACE_RB_Tree_Node<EXT_ID, INT_ID>) (k, t),
0);
this->root_->color (ACE_RB_Tree_Node_Base::BLACK);
++current_size_;
return &this->root_->item ();
}
}
// Inserts a *copy* of the key and the item into the tree: both the
// key type EXT_ID and the item type INT_ID must have well defined
// semantics for copy construction. The default implementation also
// requires that the key type support well defined < semantics. This
// method passes back a pointer to the inserted (or existing) node,
// and the search status. If the node already exists, the method
// returns 1. If the node does not exist, and a new one is
// successfully created, and the method returns 0. If there was an
// error, the method returns -1.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::insert_i (const EXT_ID &k,
const INT_ID &t,
ACE_RB_Tree_Node<EXT_ID, INT_ID> *&entry)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::insert_i");
// Find the closest matching node, if there is one.
RB_SearchResult result = LEFT;
ACE_RB_Tree_Node<EXT_ID, INT_ID> *current = find_node (k, result);
if (current)
{
// If the keys match, just return a pointer to the node's item.
if (result == EXACT)
{
entry = current;
return 1;
}
// Otherwise if we're to the left of the insertion
// point, insert into the right subtree.
else if (result == LEFT)
{
if (current->right ())
{
// If there is already a right subtree, complain.
ACELIB_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nright subtree already present in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::insert_i\n")),
-1);
}
else
{
// The right subtree is empty: insert new node there.
ACE_RB_Tree_Node<EXT_ID, INT_ID> *tmp = 0;
ACE_NEW_MALLOC_RETURN
(tmp,
(reinterpret_cast<ACE_RB_Tree_Node<EXT_ID, INT_ID>*>
(this->allocator_->malloc (sizeof (*tmp)))),
(ACE_RB_Tree_Node<EXT_ID, INT_ID>) (k, t),
-1);
current->right (tmp);
// If the node was successfully inserted, set its parent, rebalance
// the tree, color the root black, and return a pointer to the
// inserted item.
entry = current->right ();
current->right ()->parent (current);
RB_rebalance (current->right ());
this->root_->color (ACE_RB_Tree_Node_Base::BLACK);
++this->current_size_;
return 0;
}
}
// Otherwise, we're to the right of the insertion point, so
// insert into the left subtree.
else // (result == RIGHT)
{
if (current->left ())
// If there is already a left subtree, complain.
ACELIB_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nleft subtree already present in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::insert_i\n")),
-1);
else
{
// The left subtree is empty: insert new node there.
ACE_RB_Tree_Node<EXT_ID, INT_ID> *tmp = 0;
ACE_NEW_MALLOC_RETURN
(tmp,
(reinterpret_cast<ACE_RB_Tree_Node<EXT_ID, INT_ID>*>
(this->allocator_->malloc (sizeof (*tmp)))),
(ACE_RB_Tree_Node<EXT_ID, INT_ID>) (k, t),
-1);
current->left (tmp);
// If the node was successfully inserted, set its
// parent, rebalance the tree, color the root black, and
// return a pointer to the inserted item.
entry = current->left ();
current->left ()->parent (current);
RB_rebalance (current->left ());
this->root_->color (ACE_RB_Tree_Node_Base::BLACK);
++this->current_size_;
return 0;
}
}
}
else
{
// The tree is empty: insert at the root and color the root black.
ACE_NEW_MALLOC_RETURN
(this->root_,
(reinterpret_cast<ACE_RB_Tree_Node<EXT_ID, INT_ID>*>
(this->allocator_->malloc (sizeof (ACE_RB_Tree_Node<EXT_ID, INT_ID>)))),
(ACE_RB_Tree_Node<EXT_ID, INT_ID>) (k, t),
-1);
this->root_->color (ACE_RB_Tree_Node_Base::BLACK);
++this->current_size_;
entry = this->root_;
return 0;
}
}
// Removes the item associated with the given key from the tree and
// destroys it. Returns 1 if it found the item and successfully
// destroyed it, 0 if it did not find the item, or -1 if an error
// occurred. This method should only be called with locks already
// held.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (const EXT_ID &k, INT_ID &i)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (const EXT_ID &k, INT_ID &i)");
// Find a matching node, if there is one.
ACE_RB_Tree_Node<EXT_ID, INT_ID> *z;
RB_SearchResult result = LEFT;
z = find_node (k, result);
// If there is a matching node: remove and destroy it.
if (z && result == EXACT)
{
// Return the internal id stored in the deleted node.
i = z->item ();
return -1 == this->remove_i (z) ? -1 : 1;
}
// No matching node was found: return 0.
return 0;
}
/// Recursive function to dump the state of an object.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> void
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::
dump_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *node) const
{
#if defined (ACE_HAS_DUMP)
if (node)
{
dump_node_i (*node);
ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\ndown left\n")));
this->dump_i (node->left ());
ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nup left\n")));
ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\ndown right\n")));
this->dump_i (node->right ());
ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nup right\n")));
}
else
{
ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nNULL POINTER (BLACK)\n")));
}
#else /* !ACE_HAS_DUMP */
ACE_UNUSED_ARG (node);
#endif /* ACE_HAS_DUMP */
}
/// Function to dump node itself. Does not show parameterized node contents
/// in its basic form, but template specialization can be used to
/// provide definitions for various EXT_ID and INT_ID types.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> void
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::
dump_node_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> &node) const
{
#if defined (ACE_HAS_DUMP)
const char * color_str = (node.color () == ACE_RB_Tree_Node_Base::RED)
? "RED" : "BLACK";
ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT (" color=[%s]\n"), color_str));
#else /* !ACE_HAS_DUMP */
ACE_UNUSED_ARG (node);
#endif /* ACE_HAS_DUMP */
}
/// Tests the red-black invariant(s) throughout the whole tree.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::test_invariant (void)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::test_invariant");
ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
// Recurse from the root, starting with the measured black height at
// 0, and the expected black height at -1, which will cause the
// count from first measured path to a leaf to be used as the
// expected one from that point onward (the key is to check
// consistency).
int expected_black_height = -1;
if (this->test_invariant_recurse (this->root_, expected_black_height, 0) == 0)
{
ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("invariant holds\n")));
return 0;
}
return -1;
}
/// Recursive function to test the red-black invariant(s) at all nodes in a subtree.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::test_invariant_recurse (ACE_RB_Tree_Node<EXT_ID, INT_ID> *x,
int & expected_black_height,
int measured_black_height)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::test_invariant_recurse");
if (!x)
{
// Count each leaf (zero pointer) as a black node (per CLR algorithm description).
++measured_black_height;
if (expected_black_height == -1)
{
expected_black_height = measured_black_height;
}
else if (expected_black_height != measured_black_height)
{
ACELIB_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("\nexpected_black_height = %d but ")
ACE_TEXT ("\nmeasured_black_height = %d in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::test_invariant_recurse\n"),
expected_black_height, measured_black_height),
-1);
}
return 0;
}
// Check the invariant that a red node cannot have a red child.
if (x->color () == ACE_RB_Tree_Node_Base::RED)
{
if (x->left () && x->left ()->color () == ACE_RB_Tree_Node_Base::RED)
{
ACELIB_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nRED parent has RED left child in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::test_invariant_recurse\n")),
-1);
}
if (x->right () && x->right ()->color () == ACE_RB_Tree_Node_Base::RED)
{
ACELIB_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("\nRED parent has RED right child in ")
ACE_TEXT ("ACE_RB_Tree<EXT_ID, INT_ID>::test_invariant_recurse\n")),
-1);
}
}
else
{
// Count each black node traversed.
++measured_black_height;
}
return (test_invariant_recurse (x->left (), expected_black_height, measured_black_height) == 0)
? test_invariant_recurse (x->right (), expected_black_height, measured_black_height)
: -1;
}
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> int
ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *z)
{
ACE_TRACE ("ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::remove_i (ACE_RB_Tree_Node<EXT_ID, INT_ID> *z)");
// Delete the node and reorganize the tree to satisfy the Red-Black
// properties.
ACE_RB_Tree_Node<EXT_ID, INT_ID> *x;
ACE_RB_Tree_Node<EXT_ID, INT_ID> *y;
ACE_RB_Tree_Node<EXT_ID, INT_ID> *parent;
if (z->left () && z->right ())
y = RB_tree_successor (z);
else
y = z;
if (!y)
return -1;
if (y->left ())
x = y->left ();
else
x = y->right ();
parent = y->parent ();
if (x)
{
x->parent (parent);
}
if (parent)
{
if (y == parent->left ())
parent->left (x);
else
parent->right (x);
}
else
this->root_ = x;
if (y != z)
{
// Replace node z with node y, since y's pointer may well be
// held externally, and be linked with y's key and item.
// We will end up deleting the old unlinked, node z.
ACE_RB_Tree_Node<EXT_ID, INT_ID> *zParent = z->parent ();
ACE_RB_Tree_Node<EXT_ID, INT_ID> *zLeftChild = z->left ();
ACE_RB_Tree_Node<EXT_ID, INT_ID> *zRightChild = z->right ();
if (zParent)
{
if (z == zParent->left ())
{
zParent->left (y);
}
else
{
zParent->right (y);
}
}
else
{
this->root_ = y;
}
y->parent (zParent);
if (zLeftChild)
{
zLeftChild->parent (y);
}
y->left (zLeftChild);
if (zRightChild)
{
zRightChild->parent (y);
}
y->right (zRightChild);
if (parent == z)
{
parent = y;
}
ACE_RB_Tree_Node_Base::RB_Tree_Node_Color yColor = y->color ();
y->color (z->color ());
z->color (yColor);
//Reassign the y pointer to z because the node that y points to will be
//deleted
y = z;
}
// CLR pp. 263 says that nil nodes are implicitly colored BLACK
if (!y || y->color () == ACE_RB_Tree_Node_Base::BLACK)
RB_delete_fixup (x, parent);
y->parent (0);
y->right (0);
y->left (0);
ACE_DES_FREE_TEMPLATE2 (y,
this->allocator_->free,
ACE_RB_Tree_Node,
EXT_ID, INT_ID);
--this->current_size_;
return 0;
}
ACE_ALLOC_HOOK_DEFINE(ACE_RB_Tree_Iterator_Base)
// Constructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator_Base (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree, int set_first)
: tree_ (&tree), node_ (0)
{
ACE_TRACE ("ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator_Base (ACE_RB_Tree, int)");
// Position the iterator at the first (or last) node in the tree.
if (set_first)
node_ = tree_->RB_tree_minimum (tree_->root_);
else
node_ = tree_->RB_tree_maximum (tree_->root_);
}
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator_Base (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree, ACE_RB_Tree_Node<EXT_ID, INT_ID>* entry)
: tree_ (&tree), node_ (0)
{
ACE_TRACE ("ACE_RB_Tree_Iterator_Base(const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree, ACE_RB_Tree_Node<EXT_ID, INT_ID>* entry)");
node_ = entry;
}
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator_Base (const EXT_ID& key,ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree)
: tree_ (&tree), node_ (0)
{
ACE_TRACE("ACE_RB_Tree_Iterator_Base (ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree, const EXT_ID& key)");
ACE_RB_Tree_Node<EXT_ID, INT_ID>* entry = 0;
tree.find_i(key, entry);
node_ = entry;
}
// Copy constructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator_Base (const ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &iter)
: tree_ (iter.tree_),
node_ (iter.node_)
{
ACE_TRACE ("ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator_Base (ACE_RB_Tree_Iterator_Base)");
}
// Assignment operator.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK> void
ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::operator= (const ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &iter)
{
ACE_TRACE ("ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::operator=");
if (this != &iter)
{
tree_ = iter.tree_;
node_ = iter.node_;
}
}
// Destructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::~ACE_RB_Tree_Iterator_Base ()
{
ACE_TRACE ("ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::~ACE_RB_Tree_Iterator_Base");
}
// Dump the state of an object.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
void
ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::dump_i (void) const
{
ACE_TRACE ("ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::dump_i");
ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nnode_ = %x\n"), this->node_));
ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
ACE_ALLOC_HOOK_DEFINE(ACE_RB_Tree_Iterator)
// Constructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree,
int set_first)
: ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> (tree, set_first)
{
ACE_TRACE ("ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator");
}
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree,
ACE_RB_Tree_Node<EXT_ID, INT_ID>* entry)
: ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> (tree,entry)
{
ACE_TRACE ("ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator");
}
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator (const EXT_ID& key,ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree)
: ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>(key,tree)
{
ACE_TRACE ("ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Iterator");
}
// Destructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::~ACE_RB_Tree_Iterator ()
{
ACE_TRACE ("ACE_RB_Tree_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::~ACE_RB_Tree_Iterator");
}
ACE_ALLOC_HOOK_DEFINE(ACE_RB_Tree_Reverse_Iterator)
// Constructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Reverse_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Reverse_Iterator (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree, int set_last)
: ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> (tree, set_last ? 0 : 1)
{
ACE_TRACE ("ACE_RB_Tree_Reverse_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Reverse_Iterator");
}
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Reverse_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Reverse_Iterator (const ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree, ACE_RB_Tree_Node<EXT_ID, INT_ID>* entry)
: ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> (tree,entry)
{
ACE_TRACE ("ACE_RB_Tree_Reverse_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Reverse_Iterator");
}
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Reverse_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Reverse_Iterator (const EXT_ID& key,ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK> &tree)
: ACE_RB_Tree_Iterator_Base<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>(key,tree)
{
ACE_TRACE ("ACE_RB_Tree_Reverse_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::ACE_RB_Tree_Reverse_Iterator");
}
// Destructor.
template <class EXT_ID, class INT_ID, class COMPARE_KEYS, class ACE_LOCK>
ACE_RB_Tree_Reverse_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::~ACE_RB_Tree_Reverse_Iterator ()
{
ACE_TRACE ("ACE_RB_Tree_Reverse_Iterator<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::~ACE_RB_Tree_Reverse_Iterator");
}
ACE_END_VERSIONED_NAMESPACE_DECL
#endif /* !ACE_RB_TREE_CPP */
|