From fae0724cb6c935541b85882d6f50104a76d18d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 14 Jul 2012 13:29:57 +0000 Subject: [PATCH] Added `bounded_range` function to trees [SVN r79499] --- doc/intrusive.qbk | 12 +++++++ proj/vc7ide/to-do.txt | 1 + test/generic_assoc_test.hpp | 30 +++++++++++++++++ test/generic_multiset_test.hpp | 58 +++++++++++++++++++++++++++++++- test/generic_set_test.hpp | 61 ++++++++++++++++++++++++++++++++-- test/splay_multiset_test.cpp | 17 ++++++++++ test/splay_set_test.cpp | 16 +++++++++ 7 files changed, 192 insertions(+), 3 deletions(-) diff --git a/doc/intrusive.qbk b/doc/intrusive.qbk index a520047..7dd3d18 100644 --- a/doc/intrusive.qbk +++ b/doc/intrusive.qbk @@ -3829,6 +3829,18 @@ all the objects to be inserted in intrusive containers in containers like `std:: [section:release_notes Release Notes] +[section:release_notes_boost_1_51_00 Boost 1.51 Release] + +* Fixed bugs + [@https://svn.boost.org/trac/boost/ticket/6841 #6841], + [@https://svn.boost.org/trac/boost/ticket/6907 #6907], + [@https://svn.boost.org/trac/boost/ticket/6922 #6922], + [@https://svn.boost.org/trac/boost/ticket/7033 #7033], + +* Added `bounded_range` function to trees. + +[endsect] + [section:release_notes_boost_1_49_00 Boost 1.49 Release] * Fixed bugs diff --git a/proj/vc7ide/to-do.txt b/proj/vc7ide/to-do.txt index c57890b..c4eafc6 100644 --- a/proj/vc7ide/to-do.txt +++ b/proj/vc7ide/to-do.txt @@ -33,3 +33,4 @@ http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1456.html Now, intrusive containers don't allocate memory at all, so incremental rehashing must be trigered by the user using "incremental_rehash(bool)" (use an additional bucket, that is, incremental rehash) and "incremental_rehash(bucket_traits)" (to update the new bucket array with an array that should be twice/half the size of the previous one). I admit that this is not explained at all with an example, so I will note this issue in my to do list. +Review throwing conditions in trees. Searches say nothrow, but if comparison throws the function will throw. \ No newline at end of file diff --git a/test/generic_assoc_test.hpp b/test/generic_assoc_test.hpp index 28a0201..a578b46 100644 --- a/test/generic_assoc_test.hpp +++ b/test/generic_assoc_test.hpp @@ -41,6 +41,36 @@ struct has_insert_before static const bool value = false; }; +template +struct has_const_searches +{ + static const bool value = true; +}; + +template::value> +struct search_const_iterator +{ + typedef typename T::const_iterator type; +}; + +template +struct search_const_iterator +{ + typedef typename T::iterator type; +}; + +template::value> +struct search_const_container +{ + typedef const T type; +}; + +template +struct search_const_container +{ + typedef T type; +}; + template class ContainerDefiner> struct test_generic_assoc { diff --git a/test/generic_multiset_test.hpp b/test/generic_multiset_test.hpp index 51236cc..f2110b2 100644 --- a/test/generic_multiset_test.hpp +++ b/test/generic_multiset_test.hpp @@ -205,7 +205,8 @@ void test_generic_multiset::test_find(std::vector , constant_time_size >::type multiset_type; multiset_type testset (values.begin(), values.end()); - typedef typename multiset_type::iterator iterator; + typedef typename multiset_type::iterator iterator; + typedef typename multiset_type::const_iterator const_iterator; { value_type cmp_val; @@ -222,6 +223,61 @@ void test_generic_multiset::test_find(std::vector cmp_val.value_ = 7; BOOST_TEST (testset.find (cmp_val) == testset.end()); } + { //1, 2, 2, 3, 4, 5 + typename search_const_container::type &const_testset = testset; + std::pair range; + std::pair::type + ,typename search_const_iterator::type> const_range; + value_type cmp_val_lower, cmp_val_upper; + { + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 2; + //left-closed, right-closed + std::pair range = testset.bounded_range (cmp_val_lower, cmp_val_upper, true, true); + BOOST_TEST (range.first->value_ == 1); + BOOST_TEST (range.second->value_ == 3); + BOOST_TEST (std::distance (range.first, range.second) == 3); + } + { + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 2; + const_range = const_testset.bounded_range (cmp_val_lower, cmp_val_upper, true, false); + BOOST_TEST (const_range.first->value_ == 1); + BOOST_TEST (const_range.second->value_ == 2); + BOOST_TEST (std::distance (const_range.first, const_range.second) == 1); + + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 3; + range = testset.bounded_range (cmp_val_lower, cmp_val_upper, true, false); + BOOST_TEST (range.first->value_ == 1); + BOOST_TEST (range.second->value_ == 3); + BOOST_TEST (std::distance (range.first, range.second) == 3); + } + { + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 2; + const_range = const_testset.bounded_range (cmp_val_lower, cmp_val_upper, false, true); + BOOST_TEST (const_range.first->value_ == 2); + BOOST_TEST (const_range.second->value_ == 3); + BOOST_TEST (std::distance (const_range.first, const_range.second) == 2); + } + { + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 2; + range = testset.bounded_range (cmp_val_lower, cmp_val_upper, false, false); + BOOST_TEST (range.first->value_ == 2); + BOOST_TEST (range.second->value_ == 2); + BOOST_TEST (std::distance (range.first, range.second) == 0); + } + { + cmp_val_lower.value_ = 5; + cmp_val_upper.value_ = 6; + const_range = const_testset.bounded_range (cmp_val_lower, cmp_val_upper, true, false); + BOOST_TEST (const_range.first->value_ == 5); + BOOST_TEST (const_range.second == const_testset.end()); + BOOST_TEST (std::distance (const_range.first, const_range.second) == 1); + } + } } }}} //namespace boost::intrusive::test diff --git a/test/generic_set_test.hpp b/test/generic_set_test.hpp index 9340235..43d5336 100644 --- a/test/generic_set_test.hpp +++ b/test/generic_set_test.hpp @@ -265,7 +265,7 @@ void test_generic_set::test_swap(std::vector class ContainerDefiner> void test_generic_set::test_find(std::vector& values) { @@ -276,7 +276,8 @@ void test_generic_set::test_find(std::vector >::type set_type; set_type testset (values.begin(), values.end()); - typedef typename set_type::iterator iterator; + typedef typename set_type::iterator iterator; + typedef typename set_type::const_iterator const_iterator; { value_type cmp_val; @@ -293,6 +294,62 @@ void test_generic_set::test_find(std::vector::type &const_testset = testset; + std::pair range; + std::pair::type + ,typename search_const_iterator::type> const_range; + value_type cmp_val_lower, cmp_val_upper; + { + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 2; + //left-closed, right-closed + std::pair range = testset.bounded_range (cmp_val_lower, cmp_val_upper, true, true); + BOOST_TEST (range.first->value_ == 1); + BOOST_TEST (range.second->value_ == 3); + BOOST_TEST (std::distance (range.first, range.second) == 2); + } + { + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 2; + const_range = const_testset.bounded_range (cmp_val_lower, cmp_val_upper, true, false); + BOOST_TEST (const_range.first->value_ == 1); + BOOST_TEST (const_range.second->value_ == 2); + BOOST_TEST (std::distance (const_range.first, const_range.second) == 1); + + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 3; + range = testset.bounded_range (cmp_val_lower, cmp_val_upper, true, false); + BOOST_TEST (range.first->value_ == 1); + BOOST_TEST (range.second->value_ == 3); + BOOST_TEST (std::distance (range.first, range.second) == 2); + } + { + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 2; + const_range = const_testset.bounded_range (cmp_val_lower, cmp_val_upper, false, true); + BOOST_TEST (const_range.first->value_ == 2); + BOOST_TEST (const_range.second->value_ == 3); + BOOST_TEST (std::distance (const_range.first, const_range.second) == 1); + } + { + cmp_val_lower.value_ = 1; + cmp_val_upper.value_ = 2; + range = testset.bounded_range (cmp_val_lower, cmp_val_upper, false, false); + BOOST_TEST (range.first->value_ == 2); + BOOST_TEST (range.second->value_ == 2); + BOOST_TEST (std::distance (range.first, range.second) == 0); + } + { + cmp_val_lower.value_ = 5; + cmp_val_upper.value_ = 6; + const_range = const_testset.bounded_range (cmp_val_lower, cmp_val_upper, true, false); + BOOST_TEST (const_range.first->value_ == 5); + BOOST_TEST (const_range.second == const_testset.end()); + BOOST_TEST (std::distance (const_range.first, const_range.second) == 1); + } + } } }}} //namespace boost::intrusive::test diff --git a/test/splay_multiset_test.cpp b/test/splay_multiset_test.cpp index 83481f8..b6d6760 100644 --- a/test/splay_multiset_test.cpp +++ b/test/splay_multiset_test.cpp @@ -68,6 +68,23 @@ struct has_rebalance +#else +template +#endif +struct has_const_searches > +{ + static const bool value = false; +}; + + }}} using namespace boost::intrusive; diff --git a/test/splay_set_test.cpp b/test/splay_set_test.cpp index c4ac86f..62c0bae 100644 --- a/test/splay_set_test.cpp +++ b/test/splay_set_test.cpp @@ -65,6 +65,22 @@ struct has_rebalance +#else +template +#endif +struct has_const_searches > +{ + static const bool value = false; +}; + }}} using namespace boost::intrusive;