|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_UTILS_CONTAINERS_INTERVAL_TREE_INTERVAL_H_
2 #define GENESIS_UTILS_CONTAINERS_INTERVAL_TREE_INTERVAL_H_
47 #include <type_traits>
86 template <
typename NumericalType>
87 static inline bool within(NumericalType b, NumericalType e, NumericalType p)
90 return (b < p) && (p <= e);
93 template <
typename NumericalType>
94 static inline std::string
to_string(NumericalType b, NumericalType e,
bool narrow =
false)
103 template<
typename NumericalType>
104 static inline size_t length(NumericalType b, NumericalType e)
120 template <
typename NumericalType>
121 static inline bool within(NumericalType b, NumericalType e, NumericalType p)
124 return (b <= p) && (p < e);
127 template <
typename NumericalType>
128 static inline std::string
to_string(NumericalType b, NumericalType e,
bool narrow =
false)
137 template<
typename NumericalType>
138 static inline size_t length(NumericalType b, NumericalType e)
154 template <
typename NumericalType>
155 static inline bool within(NumericalType b, NumericalType e, NumericalType p)
158 return (b < p) && (p < e);
161 template <
typename NumericalType>
162 static inline std::string
to_string(NumericalType b, NumericalType e,
bool narrow =
false)
172 typename NumericalType,
173 typename std::enable_if< std::is_integral<NumericalType>::value >::type = 0
175 static inline size_t length(NumericalType b, NumericalType e)
180 throw std::invalid_argument(
181 "Invalid open interval with the same integer for the low and high values."
189 typename NumericalType,
190 typename std::enable_if< ! std::is_integral<NumericalType>::value >::type = 0
192 static inline size_t length(NumericalType b, NumericalType e)
210 template <
typename NumericalType>
211 static inline bool within(NumericalType b, NumericalType e, NumericalType p)
214 return (b <= p) && (p <= e);
217 template <
typename NumericalType>
218 static inline std::string
to_string(NumericalType b, NumericalType e,
bool narrow =
false)
228 typename NumericalType,
229 typename std::enable_if< std::is_integral<NumericalType>::value >::type = 0
231 static inline size_t length(NumericalType b, NumericalType e)
240 typename NumericalType,
241 typename std::enable_if< ! std::is_integral<NumericalType>::value >::type = 0
243 static inline size_t length(NumericalType b, NumericalType e)
267 typename DataType = EmptyIntervalData,
269 typename IntervalKind = IntervalClosed
285 std::is_arithmetic<numerical_type>::value,
286 "Interval can only be constructued with an arithmetic numerical type."
298 #if __cplusplus >= 201703L
330 , data_{std::move(
data)}
333 throw std::invalid_argument(
"Cannot construct Interval with low > high." );
368 assert( lhs.low_ <= lhs.high_ );
369 assert( rhs.low_ <= rhs.high_ );
370 return lhs.low_ == rhs.low_ && lhs.high_ == rhs.high_;
378 assert( lhs.low_ <= rhs.high_ );
379 assert( rhs.low_ <= rhs.high_ );
380 return lhs.low_ != rhs.low_ || lhs.high_ != rhs.high_;
389 assert( low_ <= high_ );
390 return low_ <= h && l <= high_;
399 assert( low_ <= high_ );
400 return low_ < h && l < high_;
408 return overlaps(other.low_, other.high_);
424 assert( low_ <= high_ );
425 return interval_kind::within(low_, high_, value);
433 assert( low_ <= high_ );
434 assert( other.low_ <= other.high_ );
435 return low_ <= other.low_ && high_ >= other.high_;
452 assert( low_ <= high_ );
453 assert( other.low_ <= other.high_ );
454 if( high_ < other.low_ ) {
455 return other.low_ - high_;
457 return low_ - other.high_;
482 assert( low_ <= high_ );
502 assert( low_ <= high_ );
511 operator std::string()
const
530 #endif // include guard
Type to store an interval (range) between two numbers, as used in the IntervalTree.
bool within(numerical_type value) const
Return whether the given value is in this.
int DefaultIntervalNumericalType
Default numerical type to use in an Interval.
static size_t length(NumericalType b, NumericalType e)
DefaultIntervalNumericalType value_type
static std::string to_string(NumericalType b, NumericalType e, bool narrow=false)
numerical_type size() const
Return the size of the interval, that is, the distance between low and high.
Empty class used as default for Interval data.
Interval & operator=(Interval const &)=default
static bool within(NumericalType b, NumericalType e, NumericalType p)
bool within(Interval const &other) const
Return whether the given interval is in this.
static std::string to_string(NumericalType b, NumericalType e, bool narrow=false)
bool overlaps(Interval const &other) const
Return whether the intervals overlap.
static std::string to_string(NumericalType b, NumericalType e, bool narrow=false)
double length(Tree const &tree)
Get the length of the tree, i.e., the sum of all branch lengths.
friend bool operator==(Interval const &lhs, Interval const &rhs)
Return if both intervals equal.
Interval(numerical_type low, numerical_type high, data_type &&data)
Construct an interval.
bool overlaps_exclusive(Interval const &other) const
Return whether the intervals overlap, excluding border.
static bool within(NumericalType b, NumericalType e, NumericalType p)
std::string to_string(GenomeLocus const &locus)
static bool within(NumericalType b, NumericalType e, NumericalType p)
numerical_type high() const
Return the upper bound of the interval.
std::string to_string(bool narrow=false) const
Helper type to define a closed [] Interval.
static size_t length(NumericalType b, NumericalType e)
numerical_type low() const
Return the lower bound of the interval.
data_type const & data() const
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
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).
DefaultIntervalNumericalType numerical_type
static size_t length(NumericalType b, NumericalType e)
Helper type to define a left open (] Interval.
Interval(numerical_type low, numerical_type high, data_type const &data)
Construct an interval.
static size_t length(NumericalType b, NumericalType e)
bool overlaps(numerical_type l, numerical_type h) const
Return whether the intervals overlap. For when both intervals are closed.
static std::string to_string(NumericalType b, NumericalType e, bool narrow=false)
Interval(numerical_type low, numerical_type high)
Construct an interval.
Helper type to define an open () Interval.
static bool within(NumericalType b, NumericalType e, NumericalType p)
Helper type to define a right open [) Interval.
numerical_type length() const
Return the length of the interval.
friend bool operator!=(Interval const &lhs, Interval const &rhs)
Return if both intervals are different.
numerical_type operator-(Interval const &other) const
Calculates the distance between the two intervals. Overlapping intervals have 0 distance.