2
0
mirror of https://github.com/boostorg/icl.git synced 2026-01-19 04:12:13 +00:00

added test to detect ticket_12872

This commit is contained in:
jofaber
2018-06-03 18:59:05 +02:00
parent 09d25cdd88
commit a6e5904618
2 changed files with 102 additions and 70 deletions

View File

@@ -20,7 +20,7 @@ Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin
#endif
#include <limits>
#include <boost/next_prior.hpp>
#include <boost/next_prior.hpp>
#include <boost/icl/associative_interval_container.hpp>
#include <boost/icl/type_traits/interval_type_default.hpp>
#include <boost/icl/interval.hpp>
@@ -40,14 +40,14 @@ namespace boost{namespace icl
{
/** \brief Implements a set as a set of intervals (base class) */
template
template
<
typename SubType,
typename DomainT,
typename DomainT,
ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT),
ICL_INTERVAL(ICL_COMPARE) Interval = ICL_INTERVAL_INSTANCE(ICL_INTERVAL_DEFAULT, DomainT, Compare),
ICL_ALLOC Alloc = std::allocator
>
>
class interval_base_set
{
public:
@@ -115,7 +115,7 @@ public:
/// allocator type of the corresponding element set
typedef Alloc<DomainT> domain_allocator_type;
/// Container type for the implementation
/// Container type for the implementation
typedef typename ICL_IMPL_SPACE::set<interval_type,key_compare,allocator_type> ImplSetT;
/// key type of the implementing container
@@ -144,15 +144,15 @@ public:
typedef typename ImplSetT::const_reverse_iterator const_reverse_iterator;
/// element iterator: Depreciated, see documentation.
typedef boost::icl::element_iterator<iterator> element_iterator;
typedef boost::icl::element_iterator<iterator> element_iterator;
/// element const iterator: Depreciated, see documentation.
typedef boost::icl::element_iterator<const_iterator> element_const_iterator;
typedef boost::icl::element_iterator<const_iterator> element_const_iterator;
/// element reverse iterator: Depreciated, see documentation.
typedef boost::icl::element_iterator<reverse_iterator> element_reverse_iterator;
typedef boost::icl::element_iterator<reverse_iterator> element_reverse_iterator;
/// element const reverse iterator: Depreciated, see documentation.
typedef boost::icl::element_iterator<const_reverse_iterator> element_const_reverse_iterator;
typedef boost::icl::element_iterator<const_reverse_iterator> element_const_reverse_iterator;
BOOST_STATIC_CONSTANT(int, fineness = 0);
BOOST_STATIC_CONSTANT(int, fineness = 0);
public:
//==========================================================================
@@ -181,20 +181,20 @@ public:
}
/** Move assignment operator */
interval_base_set& operator = (interval_base_set src)
interval_base_set& operator = (interval_base_set src)
{ //call by value sice 'src' is a "sink value"
this->_set = boost::move(src._set);
return *this;
return *this;
}
//==========================================================================
# else
/** Copy assignment operator */
interval_base_set& operator = (const interval_base_set& src)
{
interval_base_set& operator = (const interval_base_set& src)
{
this->_set = src._set;
return *this;
return *this;
}
# endif // BOOST_ICL_NO_CXX11_RVALUE_REFERENCES
@@ -220,9 +220,9 @@ public:
}
/** Size of the iteration over this container */
std::size_t iterative_size()const
{
return _set.size();
std::size_t iterative_size()const
{
return _set.size();
}
//==========================================================================
@@ -231,15 +231,15 @@ public:
/** Find the interval, that contains element \c key_value */
const_iterator find(const element_type& key_value)const
{
{
return icl::find(*this, key_value);
//CL return this->_set.find(icl::singleton<segment_type>(key));
//CL return this->_set.find(icl::singleton<segment_type>(key));
}
/** Find the first interval, that collides with interval \c key_interval */
const_iterator find(const interval_type& key_interval)const
{
return this->_set.find(key_interval);
{
return this->_set.find(key_interval);
}
//==========================================================================
@@ -247,23 +247,23 @@ public:
//==========================================================================
/** Add a single element \c key to the set */
SubType& add(const element_type& key)
SubType& add(const element_type& key)
{
return icl::add(*that(), key);
}
/** Add an interval of elements \c inter_val to the set */
SubType& add(const segment_type& inter_val)
SubType& add(const segment_type& inter_val)
{
_add(inter_val);
return *that();
}
/** Add an interval of elements \c inter_val to the set. Iterator
\c prior_ is a hint to the position \c inter_val can be
/** Add an interval of elements \c inter_val to the set. Iterator
\c prior_ is a hint to the position \c inter_val can be
inserted after. */
iterator add(iterator prior_, const segment_type& inter_val)
{
iterator add(iterator prior_, const segment_type& inter_val)
{
return _add(prior_, inter_val);
}
@@ -272,35 +272,35 @@ public:
//==========================================================================
/** Subtract a single element \c key from the set */
SubType& subtract(const element_type& key)
{
SubType& subtract(const element_type& key)
{
return icl::subtract(*that(), key);
}
/** Subtract an interval of elements \c inter_val from the set */
SubType& subtract(const segment_type& inter_val);
SubType& subtract(const segment_type& inter_val);
//==========================================================================
//= Insertion
//==========================================================================
/** Insert an element \c key into the set */
SubType& insert(const element_type& key)
{
return add(key);
SubType& insert(const element_type& key)
{
return add(key);
}
/** Insert an interval of elements \c inter_val to the set */
SubType& insert(const segment_type& inter_val)
{
return add(inter_val);
SubType& insert(const segment_type& inter_val)
{
return add(inter_val);
}
/** Insert an interval of elements \c inter_val to the set. Iterator
\c prior_ is a hint to the position \c inter_val can be
/** Insert an interval of elements \c inter_val to the set. Iterator
\c prior_ is a hint to the position \c inter_val can be
inserted after. */
iterator insert(iterator prior_, const segment_type& inter_val)
{
return add(prior_, inter_val);
iterator insert(iterator prior_, const segment_type& inter_val)
{
return add(prior_, inter_val);
}
@@ -309,27 +309,27 @@ public:
//= Erasure
//==========================================================================
/** Erase an element \c key from the set */
SubType& erase(const element_type& key)
{
return subtract(key);
SubType& erase(const element_type& key)
{
return subtract(key);
}
/** Erase an interval of elements \c inter_val from the set */
SubType& erase(const segment_type& inter_val)
{
return subtract(inter_val);
SubType& erase(const segment_type& inter_val)
{
return subtract(inter_val);
}
/** Erase the interval that iterator \c position points to. */
void erase(iterator position)
{
_set.erase(position);
{
_set.erase(position);
}
/** Erase all intervals in the range <tt>[first,past)</tt> of iterators. */
void erase(iterator first, iterator past)
{
_set.erase(first, past);
{
_set.erase(first, past);
}
//==========================================================================
@@ -373,16 +373,16 @@ public:
{ return _set.upper_bound(interval); }
std::pair<iterator,iterator> equal_range(const key_type& interval)
{
{
return std::pair<iterator,iterator>
(_set.lower_bound(interval), _set.upper_bound(interval));
(_set.lower_bound(interval), _set.upper_bound(interval));
}
std::pair<const_iterator,const_iterator>
std::pair<const_iterator,const_iterator>
equal_range(const key_type& interval)const
{
{
return std::pair<const_iterator,const_iterator>
(_set.lower_bound(interval), _set.upper_bound(interval));
(_set.lower_bound(interval), _set.upper_bound(interval));
}
private:
@@ -470,7 +470,7 @@ inline void interval_base_set<SubType,DomainT,Compare,Interval,Alloc>
// [lead_gap--- . . .
// [prior_) [-- it_ ...
this->_set.insert(prior_, lead_gap);
interval_type end_gap = left_subtract(inter_val, cur_itv);
if(!icl::is_empty(end_gap))
// [---------------end_gap)
@@ -495,12 +495,12 @@ inline void interval_base_set<SubType,DomainT,Compare,Interval,Alloc>
//= Addition
//==============================================================================
template <class SubType, class DomainT, ICL_COMPARE Compare, ICL_INTERVAL(ICL_COMPARE) Interval, ICL_ALLOC Alloc>
inline typename interval_base_set<SubType,DomainT,Compare,Interval,Alloc>::iterator
inline typename interval_base_set<SubType,DomainT,Compare,Interval,Alloc>::iterator
interval_base_set<SubType,DomainT,Compare,Interval,Alloc>
::_add(const segment_type& addend)
{
typedef typename interval_base_set<SubType,DomainT,Compare,Interval,Alloc>::iterator iterator;
if(icl::is_empty(addend))
if(icl::is_empty(addend))
return this->_set.end();
std::pair<iterator,bool> insertion = this->_set.insert(addend);
@@ -515,7 +515,7 @@ inline typename interval_base_set<SubType,DomainT,Compare,Interval,Alloc>::itera
}
template <class SubType, class DomainT, ICL_COMPARE Compare, ICL_INTERVAL(ICL_COMPARE) Interval, ICL_ALLOC Alloc>
inline typename interval_base_set<SubType,DomainT,Compare,Interval,Alloc>::iterator
inline typename interval_base_set<SubType,DomainT,Compare,Interval,Alloc>::iterator
interval_base_set<SubType,DomainT,Compare,Interval,Alloc>
::_add(iterator prior_, const segment_type& addend)
{
@@ -541,11 +541,11 @@ template <class SubType, class DomainT, ICL_COMPARE Compare, ICL_INTERVAL(ICL_CO
inline SubType& interval_base_set<SubType,DomainT,Compare,Interval,Alloc>
::subtract(const segment_type& minuend)
{
if(icl::is_empty(minuend))
if(icl::is_empty(minuend))
return *that();
std::pair<iterator, iterator> exterior = equal_range(minuend);
if(exterior.first == exterior.second)
if(exterior.first == exterior.second)
return *that();
iterator first_ = exterior.first;
@@ -553,7 +553,7 @@ inline SubType& interval_base_set<SubType,DomainT,Compare,Interval,Alloc>
iterator last_ = prior(end_);
interval_type left_resid = right_subtract(*first_, minuend);
interval_type right_resid;
interval_type right_resid;
if(first_ != end_)
right_resid = left_subtract(*last_ , minuend);
@@ -574,17 +574,17 @@ inline SubType& interval_base_set<SubType,DomainT,Compare,Interval,Alloc>
template<class SubType,
class DomainT, ICL_COMPARE Compare, ICL_INTERVAL(ICL_COMPARE) Interval, ICL_ALLOC Alloc>
struct is_set<icl::interval_base_set<SubType,DomainT,Compare,Interval,Alloc> >
{
{
typedef is_set<icl::interval_base_set<SubType,DomainT,Compare,Interval,Alloc> > type;
BOOST_STATIC_CONSTANT(bool, value = true);
BOOST_STATIC_CONSTANT(bool, value = true);
};
template<class SubType,
class DomainT, ICL_COMPARE Compare, ICL_INTERVAL(ICL_COMPARE) Interval, ICL_ALLOC Alloc>
struct is_interval_container<icl::interval_base_set<SubType,DomainT,Compare,Interval,Alloc> >
{
{
typedef is_interval_container<icl::interval_base_set<SubType,DomainT,Compare,Interval,Alloc> > type;
BOOST_STATIC_CONSTANT(bool, value = true);
BOOST_STATIC_CONSTANT(bool, value = true);
};
@@ -592,5 +592,3 @@ struct is_interval_container<icl::interval_base_set<SubType,DomainT,Compare,Inte
}} // namespace icl boost
#endif

View File

@@ -15,6 +15,8 @@ Copyright (c) 2011-2011: Joachim Faulhaber
#include <boost/icl/separate_interval_set.hpp>
#include <boost/icl/split_interval_set.hpp>
#include <iostream>
using namespace std;
using namespace boost;
using namespace unit_test;
@@ -174,3 +176,35 @@ BOOST_AUTO_TEST_CASE(test_span_and_hull)
BOOST_CHECK_EQUAL( hull< right_open_interval<int> >(2,1)
, construct< right_open_interval<int> >(1,3) );
}
BOOST_AUTO_TEST_CASE(test_ticket_12872)
{
boost::icl::split_interval_set<unsigned> ss
= boost::icl::split_interval_set<unsigned>();
std::vector<std::pair<unsigned, unsigned> > rs;
rs.push_back(make_pair(88, 96));
rs.push_back(make_pair(72, 96));
rs.push_back(make_pair(80, 96));
rs.push_back(make_pair(24, 64));
rs.push_back(make_pair(80, 96));
rs.push_back(make_pair(32, 72));
rs.push_back(make_pair(88, 96));
rs.push_back(make_pair(16, 56));
// {{88, 96}, {72, 96}, {80, 96}, {24, 64}, {80, 96}, {32, 72},
// {88, 96}, {16, 56}};
for(int i=0; i < rs.size(); i++) {
ss.add( boost::icl::interval<unsigned>::right_open(rs[i].first, rs[i].second) );
}
boost::icl::split_interval_map<unsigned, unsigned> im
= boost::icl::split_interval_map<unsigned, unsigned>();
for(int i=0; i < rs.size(); i++) {
im.add( make_pair( boost::icl::interval<unsigned>::right_open(rs[i].first, rs[i].second), 1 ) );
}
BOOST_CHECK_EQUAL(interval_count(ss), interval_count(im));
BOOST_CHECK_EQUAL(size(ss), size(im));
BOOST_CHECK_EQUAL(size(ss), size(im));
BOOST_CHECK_EQUAL(hull(ss), hull(im));
}