A library for working with phylogenetic and population genetic data.
v0.32.0
Interval< DataType, NumericalType, IntervalKind > Struct Template Reference

#include <genesis/utils/containers/interval_tree/fwd.hpp>

Detailed Description

template<typename DataType = EmptyIntervalData, typename NumericalType = DefaultIntervalNumericalType, typename IntervalKind = IntervalClosed>
struct genesis::utils::Interval< DataType, NumericalType, IntervalKind >

Type to store an interval (range) between two numbers, as used in the IntervalTree.

The implementation is based on interval-tree, which is published under the CC0-1.0 License (Creative Commons Zero v1.0 Universal); see our Acknowledgements for further details, and see IntervalTreeIterator, IntervalTreeNode, and IntervalTree for the other classes based on the original code. We changed the code to fit our standards, and in particular added support for per-interval data storage capability.

Definition at line 42 of file fwd.hpp.

Public Member Functions

 Interval (Interval &&)=default
 
 Interval (Interval const &)=default
 
 Interval (numerical_type low, numerical_type high)
 Construct an interval. More...
 
 Interval (numerical_type low, numerical_type high, data_type &&data)
 Construct an interval. More...
 
 Interval (numerical_type low, numerical_type high, data_type const &data)
 Construct an interval. More...
 
 ~Interval ()=default
 
data_typedata ()
 
data_type const & data () const
 
numerical_type high () const
 Return the upper bound of the interval. More...
 
numerical_type length () const
 Return the length of the interval. More...
 
numerical_type low () const
 Return the lower bound of the interval. More...
 
 operator std::string () const
 
numerical_type operator- (Interval const &other) const
 Calculates the distance between the two intervals. Overlapping intervals have 0 distance. More...
 
Intervaloperator= (Interval &&)=default
 
Intervaloperator= (Interval const &)=default
 
bool overlaps (Interval const &other) const
 Return whether the intervals overlap. More...
 
bool overlaps (numerical_type l, numerical_type h) const
 Return whether the intervals overlap. For when both intervals are closed. More...
 
bool overlaps_exclusive (Interval const &other) const
 Return whether the intervals overlap, excluding border. More...
 
bool overlaps_exclusive (numerical_type l, numerical_type h) const
 Return whether the intervals overlap, excluding border. For when at least one interval is open (l&r). More...
 
numerical_type size () const
 Return the size of the interval, that is, the distance between low and high. More...
 
std::string to_string (bool narrow=false) const
 
bool within (Interval const &other) const
 Return whether the given interval is in this. More...
 
bool within (numerical_type value) const
 Return whether the given value is in this. More...
 

Public Types

using data_type = DataType
 
using interval_kind = IntervalKind
 
using numerical_type = NumericalType
 
using value_type = NumericalType
 

Friends

bool operator!= (Interval const &lhs, Interval const &rhs)
 Return if both intervals are different. More...
 
bool operator== (Interval const &lhs, Interval const &rhs)
 Return if both intervals equal. More...
 

Constructor & Destructor Documentation

◆ Interval() [1/5]

Interval ( numerical_type  low,
numerical_type  high 
)
inline

Construct an interval.

The value low must be smaller than or equal to high, otherwise an exception is thrown.

Definition at line 301 of file interval.hpp.

◆ Interval() [2/5]

Interval ( numerical_type  low,
numerical_type  high,
data_type const &  data 
)
inline

Construct an interval.

The value low must be smaller than or equal to high, otherwise an exception is thrown. The data is copied over.

Definition at line 317 of file interval.hpp.

◆ Interval() [3/5]

Interval ( numerical_type  low,
numerical_type  high,
data_type &&  data 
)
inline

Construct an interval.

The value low must be smaller than or equal to high, otherwise an exception is thrown. The data is moved over.

Definition at line 327 of file interval.hpp.

◆ ~Interval()

~Interval ( )
default

◆ Interval() [4/5]

Interval ( Interval< DataType, NumericalType, IntervalKind > const &  )
default

◆ Interval() [5/5]

Interval ( Interval< DataType, NumericalType, IntervalKind > &&  )
default

Member Function Documentation

◆ data() [1/2]

data_type& data ( )
inline

Definition at line 354 of file interval.hpp.

◆ data() [2/2]

data_type const& data ( ) const
inline

Definition at line 349 of file interval.hpp.

◆ high()

numerical_type high ( ) const
inline

Return the upper bound of the interval.

Definition at line 472 of file interval.hpp.

◆ length()

numerical_type length ( ) const
inline

Return the length of the interval.

For integer types, this is the number of values in the interval, which depends on whether the interval is open, closed, or half-open (as determined by the IntervalKind template parameter):

  • [1, 3] has length 3
  • [1, 3) and (1, 3] have length 2
  • (1, 3) has length 1

For other numerical types (in particular floating points), the length is simply the distance between the high() and low(), and hence the same as size().

Definition at line 500 of file interval.hpp.

◆ low()

numerical_type low ( ) const
inline

Return the lower bound of the interval.

Definition at line 464 of file interval.hpp.

◆ operator std::string()

operator std::string ( ) const
inline

Definition at line 511 of file interval.hpp.

◆ operator-()

numerical_type operator- ( Interval< DataType, NumericalType, IntervalKind > const &  other) const
inline

Calculates the distance between the two intervals. Overlapping intervals have 0 distance.

Definition at line 446 of file interval.hpp.

◆ operator=() [1/2]

Interval& operator= ( Interval< DataType, NumericalType, IntervalKind > &&  )
default

◆ operator=() [2/2]

Interval& operator= ( Interval< DataType, NumericalType, IntervalKind > const &  )
default

◆ overlaps() [1/2]

bool overlaps ( Interval< DataType, NumericalType, IntervalKind > const &  other) const
inline

Return whether the intervals overlap.

Definition at line 406 of file interval.hpp.

◆ overlaps() [2/2]

bool overlaps ( numerical_type  l,
numerical_type  h 
) const
inline

Return whether the intervals overlap. For when both intervals are closed.

Definition at line 387 of file interval.hpp.

◆ overlaps_exclusive() [1/2]

bool overlaps_exclusive ( Interval< DataType, NumericalType, IntervalKind > const &  other) const
inline

Return whether the intervals overlap, excluding border.

Definition at line 414 of file interval.hpp.

◆ overlaps_exclusive() [2/2]

bool overlaps_exclusive ( numerical_type  l,
numerical_type  h 
) const
inline

Return whether the intervals overlap, excluding border. For when at least one interval is open (l&r).

Definition at line 397 of file interval.hpp.

◆ size()

numerical_type size ( ) const
inline

Return the size of the interval, that is, the distance between low and high.

Definition at line 480 of file interval.hpp.

◆ to_string()

std::string to_string ( bool  narrow = false) const
inline

Definition at line 506 of file interval.hpp.

◆ within() [1/2]

bool within ( Interval< DataType, NumericalType, IntervalKind > const &  other) const
inline

Return whether the given interval is in this.

Definition at line 431 of file interval.hpp.

◆ within() [2/2]

bool within ( numerical_type  value) const
inline

Return whether the given value is in this.

Definition at line 422 of file interval.hpp.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( Interval< DataType, NumericalType, IntervalKind > const &  lhs,
Interval< DataType, NumericalType, IntervalKind > const &  rhs 
)
friend

Return if both intervals are different.

Definition at line 376 of file interval.hpp.

◆ operator==

bool operator== ( Interval< DataType, NumericalType, IntervalKind > const &  lhs,
Interval< DataType, NumericalType, IntervalKind > const &  rhs 
)
friend

Return if both intervals equal.

Definition at line 366 of file interval.hpp.

Member Typedef Documentation

◆ data_type

using data_type = DataType

Definition at line 279 of file interval.hpp.

◆ interval_kind

using interval_kind = IntervalKind

Definition at line 282 of file interval.hpp.

◆ numerical_type

using numerical_type = NumericalType

Definition at line 280 of file interval.hpp.

◆ value_type

using value_type = NumericalType

Definition at line 281 of file interval.hpp.


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