Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Interval< T > Struct Template Reference

Closed interval [low, high]. More...

#include <tpl_interval_tree.H>

Public Member Functions

 Interval () noexcept(std::is_nothrow_default_constructible_v< T >)
 Initializes the interval as [T{}, T{}].
 
 Interval (const T &lo, const T &hi) noexcept(std::is_nothrow_copy_constructible_v< T >)
 Construct interval [lo, hi].
 
 Interval (T &&lo, T &&hi) noexcept(std::is_nothrow_move_constructible_v< T >)
 Construct interval [lo, hi] (move version).
 
template<class Compare = Aleph::less<T>>
bool overlaps (const Interval &other, const Compare &cmp=Compare()) const noexcept(std::is_nothrow_invocable_v< const Compare &, const T &, const T & >)
 Return true if this interval overlaps with other.
 
template<class Compare = Aleph::less<T>>
bool contains (const T &p, const Compare &cmp=Compare()) const noexcept(std::is_nothrow_invocable_v< const Compare &, const T &, const T & >)
 Return true if this interval contains the point p.
 
template<class Compare = Aleph::less<T>>
bool is_valid (const Compare &cmp=Compare()) const noexcept(std::is_nothrow_invocable_v< const Compare &, const T &, const T & >)
 Return true if low <= high.
 
bool operator== (const Interval &other) const noexcept(noexcept(std::declval< const T & >()==std::declval< const T & >()))
 Equality operator.
 
bool operator!= (const Interval &other) const noexcept(noexcept(*this==other))
 Inequality operator.
 

Static Public Member Functions

static Interval point (const T &p) noexcept(std::is_nothrow_copy_constructible_v< T >)
 Construct a point interval [p, p].
 

Public Attributes

T low
 Lower endpoint.
 
T high
 Upper endpoint.
 

Detailed Description

template<typename T>
struct Aleph::Interval< T >

Closed interval [low, high].

Represents a closed interval with endpoints of type T. All comparisons use a functor so custom types work.

Template Parameters
TEndpoint type (must be totally ordered).

Definition at line 90 of file tpl_interval_tree.H.

Constructor & Destructor Documentation

◆ Interval() [1/3]

template<typename T >
Aleph::Interval< T >::Interval ( )
inlinenoexcept

Initializes the interval as [T{}, T{}].

Exceptions
none

Definition at line 98 of file tpl_interval_tree.H.

◆ Interval() [2/3]

template<typename T >
Aleph::Interval< T >::Interval ( const T lo,
const T hi 
)
inlinenoexcept

Construct interval [lo, hi].

Parameters
[in]loLower endpoint.
[in]hiUpper endpoint.
Exceptions
none

Definition at line 107 of file tpl_interval_tree.H.

◆ Interval() [3/3]

template<typename T >
Aleph::Interval< T >::Interval ( T &&  lo,
T &&  hi 
)
inlinenoexcept

Construct interval [lo, hi] (move version).

Parameters
[in]loLower endpoint.
[in]hiUpper endpoint.
Exceptions
none

Definition at line 116 of file tpl_interval_tree.H.

Member Function Documentation

◆ contains()

template<typename T >
template<class Compare = Aleph::less<T>>
bool Aleph::Interval< T >::contains ( const T p,
const Compare &  cmp = Compare() 
) const
inlinenoexcept

Return true if this interval contains the point p.

Template Parameters
CompareComparison functor type (must represent ascending less-than).
Parameters
[in]pthe query point.
[in]cmpComparison functor for endpoints.
Returns
true if p is in [low, high], false otherwise.
Exceptions
none

Definition at line 155 of file tpl_interval_tree.H.

References Aleph::and, cmp(), Aleph::divide_and_conquer_partition_dp(), Aleph::Interval< T >::high, and Aleph::Interval< T >::low.

Referenced by TEST_F().

◆ is_valid()

template<typename T >
template<class Compare = Aleph::less<T>>
bool Aleph::Interval< T >::is_valid ( const Compare &  cmp = Compare()) const
inlinenoexcept

Return true if low <= high.

Template Parameters
CompareComparison functor type (must represent ascending less-than).
Parameters
[in]cmpComparison functor for endpoints.
Returns
true if low <= high according to cmp.
Exceptions
none

Definition at line 169 of file tpl_interval_tree.H.

References cmp(), Aleph::divide_and_conquer_partition_dp(), Aleph::Interval< T >::high, and Aleph::Interval< T >::low.

Referenced by TEST_F().

◆ operator!=()

template<typename T >
bool Aleph::Interval< T >::operator!= ( const Interval< T > &  other) const
inlinenoexcept

Inequality operator.

Parameters
[in]otherInterval to compare with.
Returns
true if endpoints differ.
Exceptions
none

Definition at line 191 of file tpl_interval_tree.H.

References Aleph::divide_and_conquer_partition_dp().

◆ operator==()

template<typename T >
bool Aleph::Interval< T >::operator== ( const Interval< T > &  other) const
inlinenoexcept

Equality operator.

Parameters
[in]otherInterval to compare with.
Returns
true if endpoints are equal.
Exceptions
none

Definition at line 180 of file tpl_interval_tree.H.

References Aleph::and, Aleph::divide_and_conquer_partition_dp(), Aleph::Interval< T >::high, and Aleph::Interval< T >::low.

◆ overlaps()

template<typename T >
template<class Compare = Aleph::less<T>>
bool Aleph::Interval< T >::overlaps ( const Interval< T > &  other,
const Compare &  cmp = Compare() 
) const
inlinenoexcept

Return true if this interval overlaps with other.

Template Parameters
CompareComparison functor type (must represent ascending less-than).
Parameters
[in]otherThe other interval.
[in]cmpComparison functor for endpoints.
Returns
true if intervals overlap, false otherwise.
Exceptions
none

Definition at line 139 of file tpl_interval_tree.H.

References Aleph::and, cmp(), Aleph::divide_and_conquer_partition_dp(), Aleph::Interval< T >::high, and Aleph::Interval< T >::low.

Referenced by TEST_F().

◆ point()

template<typename T >
static Interval Aleph::Interval< T >::point ( const T p)
inlinestaticnoexcept

Construct a point interval [p, p].

Parameters
[in]pThe point value.
Returns
An interval where low == high == p.
Exceptions
none

Definition at line 125 of file tpl_interval_tree.H.

Referenced by Aleph::Gen_Interval_Tree< NodeType, T, Compare >::find_stab(), Aleph::Gen_Interval_Tree< NodeType, T, Compare >::stab(), TEST_F(), and TEST_F().

Member Data Documentation

◆ high

◆ low


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