Added bounded_range function to trees

[SVN r79499]
This commit is contained in:
Ion Gaztañaga
2012-07-14 13:29:57 +00:00
parent 07b1322fa3
commit fae0724cb6
7 changed files with 192 additions and 3 deletions

View File

@@ -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 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] [section:release_notes_boost_1_49_00 Boost 1.49 Release]
* Fixed bugs * Fixed bugs

View File

@@ -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 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. "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.

View File

@@ -41,6 +41,36 @@ struct has_insert_before
static const bool value = false; static const bool value = false;
}; };
template<class T>
struct has_const_searches
{
static const bool value = true;
};
template<class T, bool = has_const_searches<T>::value>
struct search_const_iterator
{
typedef typename T::const_iterator type;
};
template<class T>
struct search_const_iterator<T, false>
{
typedef typename T::iterator type;
};
template<class T, bool = has_const_searches<T>::value>
struct search_const_container
{
typedef const T type;
};
template<class T>
struct search_const_container<T, false>
{
typedef T type;
};
template<class ValueTraits, template <class = ::boost::intrusive::none, class = ::boost::intrusive::none, class = ::boost::intrusive::none, class = ::boost::intrusive::none> class ContainerDefiner> template<class ValueTraits, template <class = ::boost::intrusive::none, class = ::boost::intrusive::none, class = ::boost::intrusive::none, class = ::boost::intrusive::none> class ContainerDefiner>
struct test_generic_assoc struct test_generic_assoc
{ {

View File

@@ -206,6 +206,7 @@ void test_generic_multiset<ValueTraits, ContainerDefiner>::test_find(std::vector
>::type multiset_type; >::type multiset_type;
multiset_type testset (values.begin(), values.end()); 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; value_type cmp_val;
@@ -222,6 +223,61 @@ void test_generic_multiset<ValueTraits, ContainerDefiner>::test_find(std::vector
cmp_val.value_ = 7; cmp_val.value_ = 7;
BOOST_TEST (testset.find (cmp_val) == testset.end()); BOOST_TEST (testset.find (cmp_val) == testset.end());
} }
{ //1, 2, 2, 3, 4, 5
typename search_const_container<multiset_type>::type &const_testset = testset;
std::pair<iterator,iterator> range;
std::pair<typename search_const_iterator<multiset_type>::type
,typename search_const_iterator<multiset_type>::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<iterator,iterator> 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 }}} //namespace boost::intrusive::test

View File

@@ -265,7 +265,7 @@ void test_generic_set<ValueTraits, ContainerDefiner>::test_swap(std::vector<type
BOOST_TEST (&*testset1.begin() == &values[3]); BOOST_TEST (&*testset1.begin() == &values[3]);
} }
//test: find, equal_range (lower_bound, upper_bound): //test: find, equal_range (lower_bound, upper_bound), bounded_range:
template<class ValueTraits, template <class = ::boost::intrusive::none, class = ::boost::intrusive::none, class = ::boost::intrusive::none, class = ::boost::intrusive::none> class ContainerDefiner> template<class ValueTraits, template <class = ::boost::intrusive::none, class = ::boost::intrusive::none, class = ::boost::intrusive::none, class = ::boost::intrusive::none> class ContainerDefiner>
void test_generic_set<ValueTraits, ContainerDefiner>::test_find(std::vector<typename ValueTraits::value_type>& values) void test_generic_set<ValueTraits, ContainerDefiner>::test_find(std::vector<typename ValueTraits::value_type>& values)
{ {
@@ -277,6 +277,7 @@ void test_generic_set<ValueTraits, ContainerDefiner>::test_find(std::vector<type
>::type set_type; >::type set_type;
set_type testset (values.begin(), values.end()); 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; value_type cmp_val;
@@ -293,6 +294,62 @@ void test_generic_set<ValueTraits, ContainerDefiner>::test_find(std::vector<type
cmp_val.value_ = 7; cmp_val.value_ = 7;
BOOST_TEST (testset.find (cmp_val) == testset.end()); BOOST_TEST (testset.find (cmp_val) == testset.end());
} }
{
typename search_const_container<set_type>::type &const_testset = testset;
std::pair<iterator,iterator> range;
std::pair<typename search_const_iterator<set_type>::type
,typename search_const_iterator<set_type>::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<iterator,iterator> 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 }}} //namespace boost::intrusive::test

View File

@@ -68,6 +68,23 @@ struct has_rebalance<boost::intrusive::splay_multiset<T,
static const bool value = true; static const bool value = true;
}; };
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class T, class O1, class O2, class O3, class O4>
#else
template<class T, class ...Options>
#endif
struct has_const_searches<boost::intrusive::splay_multiset<T,
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
O1, O2, O3, O4
#else
Options...
#endif
> >
{
static const bool value = false;
};
}}} }}}
using namespace boost::intrusive; using namespace boost::intrusive;

View File

@@ -65,6 +65,22 @@ struct has_rebalance<boost::intrusive::splay_set<T,
static const bool value = true; static const bool value = true;
}; };
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class T, class O1, class O2, class O3, class O4>
#else
template<class T, class ...Options>
#endif
struct has_const_searches<boost::intrusive::splay_set<T,
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
O1, O2, O3, O4
#else
Options...
#endif
> >
{
static const bool value = false;
};
}}} }}}
using namespace boost::intrusive; using namespace boost::intrusive;