yat  0.21pre
Public Types | Public Member Functions | Related Functions | List of all members
theplu::yat::utility::Segment< T, Compare > Class Template Reference

a class for a Segment or Interval More...

#include <yat/utility/Segment.h>

Public Types

typedef T value_type
 

Public Member Functions

 Segment (void)
 default constructor
 
 Segment (const T &begin, const T &end)
 Constructor. More...
 
 Segment (T &&begin, T &&end)
 Constructor. More...
 
T & begin (void)
 
const T & begin (void) const
 
T & end (void)
 
const T & end (void) const
 

Related Functions

(Note that these are not member functions.)

template<typename T , class Compare >
bool operator!= (const Segment< T, Compare > &lhs, const Segment< T, Compare > &rhs)
 Inequality operator. More...
 
template<typename T , class Compare >
bool operator== (const Segment< T, Compare > &lhs, const Segment< T, Compare > &rhs)
 
template<typename T , class Compare >
bool compare (const Segment< T, Compare > &lhs, const Segment< T, Compare > &rhs)
 
template<typename T , class Compare >
int compare_3way (const Segment< T, Compare > &lhs, const Segment< T, Compare > &rhs)
 
template<typename T , class Compare >
int compare_3way (const T &element, const Segment< T, Compare > &segment)
 
template<typename T , class Compare >
int compare_3way (const Segment< T, Compare > &segment, const T &element)
 
template<typename T , class Compare >
Segment< T, Compare > intersection (const Segment< T, Compare > &a, const Segment< T, Compare > &b)
 
template<typename T , class Compare >
Segment< T, Compare > set_union (const Segment< T, Compare > &a, const Segment< T, Compare > &b)
 union of two segments More...
 

Detailed Description

template<typename T, class Compare = std::less<T>>
class theplu::yat::utility::Segment< T, Compare >

a class for a Segment or Interval

A Segment is defined by its begin and end. The end is not included in the Segment, i.e., you could write the Segment as [begin, end). Type T must be comparable, optionally with a comparator Compare, which should implement Strict Weak Ordering..

Since
new in yat 0.7

Member Typedef Documentation

◆ value_type

template<typename T, class Compare = std::less<T>>
typedef T theplu::yat::utility::Segment< T, Compare >::value_type

type the Segment holds

Constructor & Destructor Documentation

◆ Segment() [1/2]

template<typename T, class Compare = std::less<T>>
theplu::yat::utility::Segment< T, Compare >::Segment ( const T &  begin,
const T &  end 
)
inline

Constructor.

Creates a segment [begin, end)

◆ Segment() [2/2]

template<typename T, class Compare = std::less<T>>
theplu::yat::utility::Segment< T, Compare >::Segment ( T &&  begin,
T &&  end 
)
inline

Constructor.

Creates a segment [begin, end)

Since
New in yat 0.19

Member Function Documentation

◆ begin() [1/2]

template<typename T, class Compare = std::less<T>>
T& theplu::yat::utility::Segment< T, Compare >::begin ( void  )
inline
Returns
reference to first element in Segment

◆ begin() [2/2]

template<typename T, class Compare = std::less<T>>
const T& theplu::yat::utility::Segment< T, Compare >::begin ( void  ) const
inline
Returns
const reference to first element in Segment

◆ end() [1/2]

template<typename T, class Compare = std::less<T>>
T& theplu::yat::utility::Segment< T, Compare >::end ( void  )
inline
Returns
reference to first element greater than Segment

◆ end() [2/2]

template<typename T, class Compare = std::less<T>>
const T& theplu::yat::utility::Segment< T, Compare >::end ( void  ) const
inline
Returns
const reference to first element greater than Segment

Friends And Related Function Documentation

◆ compare()

template<typename T , class Compare >
bool compare ( const Segment< T, Compare > &  lhs,
const Segment< T, Compare > &  rhs 
)
related

This function takes two Segment and compare them with comparator Compare. If all elements in lhs is less than all elements in rhs, true is returned. In other words, false is returned if rhs.begin() is less than lhs.end().

The exception is if both lhs and rhs are empty Segment (i.e. begin equals end) and their begins and ends are equal, in which case false is returned. This exception implies that compare(x,x) always returns false.

Since
new in yat 0.7

◆ compare_3way() [1/3]

template<typename T , class Compare >
int compare_3way ( const Segment< T, Compare > &  lhs,
const Segment< T, Compare > &  rhs 
)
related
Returns
-1 if compare(lhs, rhs) is true, +1 if compare(rhs, lhs) is true, and 0 otherwise
See also
compare(const Segment<T, Compare>&, const Segment<T, Compare>&)
Since
new in yat 0.7

◆ compare_3way() [2/3]

template<typename T , class Compare >
int compare_3way ( const T &  element,
const Segment< T, Compare > &  segment 
)
related
Returns
-1 if element is less than all elements in segment, 0 if element overlaps with segment, and 1 otherwise.
Since
new in yat 0.7

◆ compare_3way() [3/3]

template<typename T , class Compare >
int compare_3way ( const Segment< T, Compare > &  segment,
const T &  element 
)
related
Returns
-1 if all elements in segment are less than element, 0 if if element overlaps with segment, and 1 otherwise.
Since
new in yat 0.14

◆ intersection()

template<typename T , class Compare >
Segment< T, Compare > intersection ( const Segment< T, Compare > &  a,
const Segment< T, Compare > &  b 
)
related
Returns
intersection of a and b. If a and b do not overlap an empty Section is returned (begin==end), but the exact value of begin is undefined.
Since
new in yat 0.7

◆ operator!=()

template<typename T , class Compare >
bool operator!= ( const Segment< T, Compare > &  lhs,
const Segment< T, Compare > &  rhs 
)
related

Inequality operator.

Inequality operator is defined via the operator< of T or in the general case Compare.

Returns
true if Compare returns true for either when comparing lhs.begin() and rhs.begin() or when comparing lhs.end() and rhs.end().
Since
New in yat 0.14

◆ operator==()

template<typename T , class Compare >
bool operator== ( const Segment< T, Compare > &  lhs,
const Segment< T, Compare > &  rhs 
)
related
Returns
true if Compare returns false when comparing lhs.begin() and rhs.begin() as well as when comparing lhs.end() and rhs.end().
Since
New in yat 0.14

◆ set_union()

template<typename T , class Compare >
Segment< T, Compare > set_union ( const Segment< T, Compare > &  a,
const Segment< T, Compare > &  b 
)
related

union of two segments

Returns
union of a and b. If the union of a and b is not a single segment, i.e., a.end() < b.begin() and b.end() < a.begin(), the result is undefined.
See also
SegmentSet
Since
new in yat 0.15

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

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14