diff --git a/src/radix.h b/src/radix.h --- a/src/radix.h +++ b/src/radix.h @@ -33,7 +33,7 @@ * to speed before destroying anything. It is therefore crucial that the lock be * taken before reading anything in the tree. */ -template struct RadixTree { +template struct Uint256RadixKey { private: static const int BITS = 4; static const int MASK = (1 << BITS) - 1; @@ -50,13 +50,13 @@ std::atomic root; public: - RadixTree() : root(RadixElement()) {} - ~RadixTree() { root.load().decrementRefCount(); } + Uint256RadixKey() : root(RadixElement()) {} + ~Uint256RadixKey() { root.load().decrementRefCount(); } /** * Copy semantic. */ - RadixTree(const RadixTree &src) : RadixTree() { + Uint256RadixKey(const Uint256RadixKey &src) : Uint256RadixKey() { { RCULock lock; RadixElement e = src.root.load(); @@ -69,7 +69,7 @@ RCULock::synchronize(); } - RadixTree &operator=(const RadixTree &rhs) { + Uint256RadixKey &operator=(const Uint256RadixKey &rhs) { { RCULock lock; RadixElement e = rhs.root.load(); @@ -88,8 +88,10 @@ /** * Move semantic. */ - RadixTree(RadixTree &&src) : RadixTree() { *this = std::move(src); } - RadixTree &operator=(RadixTree &&rhs) { + Uint256RadixKey(Uint256RadixKey &&src) : Uint256RadixKey() { + *this = std::move(src); + } + Uint256RadixKey &operator=(Uint256RadixKey &&rhs) { { RCULock lock; RadixElement e = rhs.root.load(); @@ -134,7 +136,7 @@ } RCUPtr get(const KeyType &key) const { - T const *ptr = const_cast(this)->get(key).release(); + T const *ptr = const_cast(this)->get(key).release(); return RCUPtr::acquire(ptr); } diff --git a/src/test/radix_tests.cpp b/src/test/radix_tests.cpp --- a/src/test/radix_tests.cpp +++ b/src/test/radix_tests.cpp @@ -63,7 +63,7 @@ }; template void testInsert() { - RadixTree mytree; + Uint256RadixKey mytree; auto zero = RCUPtr::make(0); auto one = RCUPtr::make(1); @@ -119,7 +119,7 @@ } template void testGet() { - RadixTree mytree; + Uint256RadixKey mytree; auto zero = RCUPtr::make(0); auto one = RCUPtr::make(1); @@ -193,7 +193,7 @@ } template void testRemove() { - RadixTree mytree; + Uint256RadixKey mytree; auto zero = RCUPtr::make(0); auto one = RCUPtr::make(1); @@ -282,7 +282,7 @@ BOOST_AUTO_TEST_CASE(const_element_test) { using C = const TestElementInt; - RadixTree mytree; + Uint256RadixKey mytree; BOOST_CHECK(mytree.insert(RCUPtr::make(0))); BOOST_CHECK(mytree.insert(RCUPtr::make(1))); @@ -315,7 +315,7 @@ BOOST_CHECK(!mytree.remove(3)); } -void CheckConstTree(const RadixTree> &mytree, +void CheckConstTree(const Uint256RadixKey> &mytree, bool expected) { BOOST_CHECK_EQUAL(!!mytree.get(0), expected); BOOST_CHECK_EQUAL(!!mytree.get(1), expected); @@ -325,7 +325,7 @@ BOOST_AUTO_TEST_CASE(const_tree_test) { using E = TestElementInt; - RadixTree mytree; + Uint256RadixKey mytree; CheckConstTree(mytree, false); @@ -347,14 +347,14 @@ BOOST_AUTO_TEST_CASE(test_cow) { using E = TestElementInt; - RadixTree mytree; + Uint256RadixKey mytree; BOOST_CHECK(mytree.insert(RCUPtr::make(0))); BOOST_CHECK(mytree.insert(RCUPtr::make(1))); BOOST_CHECK(mytree.insert(RCUPtr::make(2))); BOOST_CHECK(mytree.insert(RCUPtr::make(3))); - RadixTree copyTree = mytree; + Uint256RadixKey copyTree = mytree; // The copy tree is identical. BOOST_CHECK(copyTree.get(0)); @@ -398,14 +398,14 @@ BOOST_AUTO_TEST_CASE(test_move) { using E = TestElementInt; - RadixTree mytree; + Uint256RadixKey mytree; BOOST_CHECK(mytree.insert(RCUPtr::make(0))); BOOST_CHECK(mytree.insert(RCUPtr::make(1))); BOOST_CHECK(mytree.insert(RCUPtr::make(2))); BOOST_CHECK(mytree.insert(RCUPtr::make(3))); - RadixTree movedTree = std::move(mytree); + Uint256RadixKey movedTree = std::move(mytree); BOOST_CHECK(!mytree.remove(0)); BOOST_CHECK(!mytree.remove(1)); @@ -424,7 +424,7 @@ BOOST_AUTO_TEST_CASE(insert_stress_test) { using E = TestElementInt; - RadixTree mytree; + Uint256RadixKey mytree; std::atomic success{0}; std::vector threads; @@ -482,7 +482,7 @@ BOOST_AUTO_TEST_CASE(tree_traversal) { using E = TestElement; - RadixTree mytree; + Uint256RadixKey mytree; // Build a vector of elements in ascending key order std::vector> elements;