Commit 186097b0 authored by Michal Vaner's avatar Michal Vaner
Browse files


git-svn-id: svn:// e5f2f494-b856-4b98-b285-d166d9295462
parent cd266f92
......@@ -294,6 +294,16 @@ public:
Result insert(const isc::dns::Name& name, RBNode<T>** inserted_node);
/// \brief Swaps two tree's contents.
/// This acts the same as many std::*.swap functions, exchanges the
/// contents. This doesn't throw anything.
void swap(RBTree<T>& other) {
std::swap(root_, other.root_);
std::swap(NULLNODE, other.NULLNODE);
std::swap(node_count_, other.node_count_);
/// \name RBTree balance functions
......@@ -176,4 +176,34 @@ TEST_F(RBTreeTest, dumpTree) {
str2 << "tree has 13 node(s)\nb. (black)\n a. (black)\n NULL\n NULL\n d.e.f. (black)[invisible] \n begin down from d.e.f.\n w.y. (black)[invisible] \n begin down from w.y.\n p. (black)\n o. (red)\n NULL\n NULL\n q. (red)\n NULL\n NULL\n end down from w.y.\n x. (red)\n NULL\n NULL\n z. (red)\n begin down from z.\n j. (black)\n NULL\n NULL\n end down from z.\n NULL\n NULL\n end down from d.e.f.\n c. (red)\n NULL\n NULL\n g.h. (red)\n begin down from g.h.\n i. (black)\n NULL\n NULL\n end down from g.h.\n NULL\n NULL\n";
EXPECT_EQ(str.str(), str2.str());
TEST_F(RBTreeTest, swap) {
// Store info about the first tree
std::ostringstream str1;
size_t count1(rbtree.getNodeCount());
// Create second one and store state
RBTree<int> tree2;
RBNode<int>* node;
tree2.insert(Name("second"), &node);
std::ostringstream str2;
// Swap them
// Check their sizes
ASSERT_EQ(1, rbtree.getNodeCount());
ASSERT_EQ(count1, tree2.getNodeCount());
// And content
std::ostringstream out;
ASSERT_EQ(str2.str(), out.str());
ASSERT_EQ(str1.str(), out.str());
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment