|
typedef T | bound_type |
| Type of the bounds. More...
|
|
typedef std::set< std::pair< T, T >, range_compare< T > > | container_type |
| Synonym type defining the base class container std::set. More...
|
|
typedef container_type::value_type | value_type |
| Synonym type defining the base class container std::set::value_type. More...
|
|
typedef container_type::key_compare | key_compare |
| Synonym type defining the key/value comparison std::set::key_compare. More...
|
|
typedef container_type::value_compare | value_compare |
|
typedef container_type::iterator | iterator |
| Synonym type defining the base class container std::set::iterator. More...
|
|
typedef container_type::const_iterator | const_iterator |
| Synonym type defining the base class container std::set::iterator. More...
|
|
template<typename T>
class reflex::Ranges< T >
RE/flex Ranges template class.
The std::set
container is a base class of this Ranges class. Value ranges [lo,hi] are stored in the underlying std::set
container as std::pair(lo, hi)
pairs of bounds.
Ranges in the set are mutually disjoint (i.e. non-overlapping). This property is maintained by the reflex::Ranges
methods.
The Ranges::value_type
is std::pair<bound_type,bound_type>
with Ranges::bound_type
the template parameter type T
.
The reflexx::Ranges
class introduces several new methods in addition to the inherited std::set
methods:
std::pair<iterator,bool> insert(const bound_type& lo, const bound_type& hi)
updates ranges to include the range [lo,hi]. Returns an iterator to the range that contains [lo,hi] and a flag indicating that ranges was updated (true) or if the new range was subsumed by current ranges (false).
std::pair<iterator,bool> insert(const bound_type& val)
updates ranges to include the value [val,val]. Returns an iterator to the range that contains val and a flag indicating that ranges was updated (true) or if the new range was subsumed by current ranges (false).
const_iterator find(const bound_type& lo, const bound_type& hi) const
searches for the first range that overlaps with [lo,hi]. Returns an iterator to the range found or the end iterator.
const_iterator find(const bound_type& val) const
searches for the range that includes the given value. Returns an iterator to the range found or the end iterator.
Ranges& operator|=(const Ranges& rs)
inserts ranges rs. Returns reference to this object.
Ranges& operator+=(const Ranges& rs)
same as above.
Ranges& operator&=(const Ranges& rs)
update ranges to intersect with ranges rs. Returns reference to this object.
Ranges operator|(const Ranges& rs) const
returns union of ranges.
Ranges operator+(const Ranges& rs) const
same as above.
Ranges operator&(const Ranges& rs) const
returns intersection of ranges.
bool any() const
returns true if this set of ranges contains at least one range, i.e. is not empty.
bool intersects(const Ranges& rs) const
returns true if ranges intersects with ranges rs, i.e. has at least one range that overlaps with ranges rs.
bool contains(const Ranges& rs) const
returns true if this set of ranges contains all ranges rs, i.e. ranges rs is a subset.
- Warning
- Using
std::set::insert()
instead of Ranges::insert()
may result in overlapping ranges rather than merging ranges to produce disjoint non-overlapping ranges.
Example:
std::cout << "Set of " << intervals.size() << " intervals:" << std::endl;
std::cout << "[" << i->first << "," << i->second << "]" << std::endl;
if (intervals.
find(2.5) != intervals.end())
std::cout << "2.5 is in intervals" << std::endl;
std::cout << "[" << i->first << "," << i->second << "] overlaps with [0.0,1.0]" << std::endl;
std::cout << "intersects [2.5,10.0]" << std::endl;
std::cout << "contains [1.0,2.5]" << std::endl;
Output:
Set of 2 intervals:
[-1,0]
[1,3]
2.5 is in intervals
[-1,0] overlaps with [0.0,1.0]
[1,3] overlaps with [0.0,1.0]
intersects [2.5,10.0]
contains [1.0,2.5]