Clingo
Loading...
Searching...
No Matches
CppClingo::Util::interval_set< T > Class Template Reference

A set of intervals. More...

#include <interval_set.hh>

Classes

struct  interval
 An interval determined by a left and a right bound. More...
 
struct  left_bound
 A left bound of an interval. More...
 
struct  right_bound
 A right bound of an interval. More...
 

Public Types

using value_type = T
 The value type used as bounds.
 
using interval_vector = small_vector< interval >
 The vector used to store intervals.
 
using iterator = typename interval_vector::const_iterator
 An iterator over the intervals in the set.
 

Public Member Functions

 interval_set ()=default
 Construct an empty interval set.
 
 ~interval_set ()=default
 Destroy the interval set.
 
 interval_set (interval_set const &other)=default
 The default copy constructor.
 
auto operator= (interval_set const &other) -> interval_set &=default
 The default copy assignment.
 
 interval_set (interval_set &&other) noexcept=default
 The default move constructor.
 
auto operator= (interval_set &&other) noexcept -> interval_set &=default
 The default copy assignment.
 
 interval_set (std::initializer_list< interval > list)
 Construct an interval set containing the given intervals.
 
void reserve (size_t n)
 Reserve space for at least n elements.
 
auto release () -> interval_vector
 Releases the underlying vector.
 
auto add (interval const &x) -> interval_set &
 Add the given interval to the set.
 
auto remove (interval const &x) -> interval_set &
 Subtract the given interval from the set.
 
auto contains (interval const &x) const -> bool
 Check if the set contains the given interval.
 
auto contains (T const &x) const -> bool
 Check if the set contains the given value.
 
auto intersects (interval const &x) const -> bool
 Check if the set intersects the given interval.
 
auto empty () const -> bool
 Check if the set is empty.
 
auto size () const -> size_t
 Get the size of the set.
 
auto front () const -> interval const &
 Get the first interval in the set.
 
auto back () const -> interval const &
 Get the last interval in the set.
 
auto begin () const -> iterator
 Get an iterator to the beginning of the set.
 
auto end () const -> iterator
 Get an iterator to the end of the set.
 
void clear ()
 Clear the set.
 
auto intersect (interval_set const &set) const -> interval_set
 Compute the intersection of two interval sets.
 
auto difference (interval_set const &set) const -> interval_set
 Compute the difference between two interval sets.
 

Friends

auto operator< (left_bound const &x, left_bound const &y) -> bool
 Left bound x is smaller than left bound y.
 
auto operator<= (left_bound const &x, left_bound const &y) -> bool
 Left bound x is smaller than or equal to left bound y.
 
auto operator< (left_bound const &x, right_bound const &y) -> bool
 There is a gap between x and y.
 
auto operator< (right_bound const &x, right_bound const &y) -> bool
 Right bound x is smaller than right bound y.
 
auto operator<= (right_bound const &x, right_bound const &y) -> bool
 Right bound x is smaller than or equal to right bound y.
 
auto operator< (right_bound const &x, left_bound const &y) -> bool
 There is a gap between x and y.
 
auto operator< (interval const &x, interval const &y) -> bool
 Interval x is before interval y.
 
auto operator< (value_type const &x, interval const &y) -> bool
 Value x is before interval y.
 
auto operator< (interval const &x, value_type const &y) -> bool
 Interval x is before value y.
 

Detailed Description

template<class T>
class CppClingo::Util::interval_set< T >

A set of intervals.

Closed and open intervals of bounds are supported.

Note that intervals involving discrete values should be closed in a post-processing step to obtain a canonical set representation, e.g., the inteval (1,2) should be removed and (1,3) be represented as [2].

Member Function Documentation

◆ add()

template<class T >
auto CppClingo::Util::interval_set< T >::add ( interval const &  x) -> interval_set &
inline

Add the given interval to the set.

Parameters
xthe interval to add
Returns
a reference to the set

◆ contains() [1/2]

template<class T >
auto CppClingo::Util::interval_set< T >::contains ( interval const &  x) const -> bool
inline

Check if the set contains the given interval.

Parameters
xthe interval to check
Returns
whether the set contains the interval

◆ contains() [2/2]

template<class T >
auto CppClingo::Util::interval_set< T >::contains ( T const &  x) const -> bool
inline

Check if the set contains the given value.

Parameters
xthe value to check
Returns
whether the set contains the value

◆ intersects()

template<class T >
auto CppClingo::Util::interval_set< T >::intersects ( interval const &  x) const -> bool
inline

Check if the set intersects the given interval.

Parameters
xthe interval to check
Returns
whether the set intersects the interval

◆ remove()

template<class T >
auto CppClingo::Util::interval_set< T >::remove ( interval const &  x) -> interval_set &
inline

Subtract the given interval from the set.

Parameters
xthe interval to subtract
Returns
a reference to the set

◆ reserve()

template<class T >
void CppClingo::Util::interval_set< T >::reserve ( size_t  n)
inline

Reserve space for at least n elements.

Calls the reserve method of the underlying vector.

Parameters
nthe number of elements to reserve space for

Friends And Related Symbol Documentation

◆ operator< [1/2]

template<class T >
auto operator< ( left_bound const &  x,
right_bound const &  y 
) -> bool
friend

There is a gap between x and y.

For example, two intervals with bounds x and y overlap.

x: [---
y: ---]

Can be used to check whether an interval is empty.

◆ operator< [2/2]

template<class T >
auto operator< ( right_bound const &  x,
left_bound const &  y 
) -> bool
friend

There is a gap between x and y.

For example, two intervals with bounds x and y do not overlap:

x: ---)
y: (---

Can be used to check whether two intervals can be merged.


The documentation for this class was generated from the following file: