A library for working with phylogenetic and population genetic data.
v0.27.0
utils/containers/interval_tree/functions.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_CONTAINERS_INTERVAL_TREE_FUNCTIONS_H_
2 #define GENESIS_UTILS_CONTAINERS_INTERVAL_TREE_FUNCTIONS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2022 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lczech@carnegiescience.edu>
23  Department of Plant Biology, Carnegie Institution For Science
24  260 Panama Street, Stanford, CA 94305, USA
25 */
26 
34 #include <algorithm>
35 
37 
38 namespace genesis {
39 namespace utils {
40 
41 // =================================================================================================
42 // Make Safe Interval
43 // =================================================================================================
44 
50 template <
51  typename DataType = EmptyIntervalData,
52  typename NumericalType = DefaultIntervalNumericalType,
53  typename IntervalKind = IntervalClosed
54 >
55 #if __cplusplus >= 201703L
56  constexpr
57 #endif
59  NumericalType lhs,
60  NumericalType rhs
61 ) {
63  std::min(lhs, rhs), std::max(lhs, rhs)
64  };
65 }
66 
72 template <
73  typename DataType = EmptyIntervalData,
74  typename NumericalType = DefaultIntervalNumericalType,
75  typename IntervalKind = IntervalClosed
76 >
77 #if __cplusplus >= 201703L
78  constexpr
79 #endif
81  NumericalType lhs,
82  NumericalType rhs,
83  DataType const& data
84 ) {
86  std::min(lhs, rhs), std::max(lhs, rhs), data
87  };
88 }
89 
95 template <
96  typename DataType = EmptyIntervalData,
97  typename NumericalType = DefaultIntervalNumericalType,
98  typename IntervalKind = IntervalClosed
99 >
100 #if __cplusplus >= 201703L
101  constexpr
102 #endif
104  NumericalType lhs,
105  NumericalType rhs,
106  DataType&& data
107 ) {
109  std::min(lhs, rhs), std::max(lhs, rhs), std::move(data)
110  };
111 }
112 
113 // =================================================================================================
114 // Join
115 // =================================================================================================
116 
122 template <
123  typename DataType = EmptyIntervalData,
124  typename NumericalType = DefaultIntervalNumericalType,
125  typename IntervalKind = IntervalClosed
126 >
130 ) {
131  return { std::min(a.low(), b.low()), std::max(a.high(), b.high()) };
132 }
133 
139 template <
140  typename DataType = EmptyIntervalData,
141  typename NumericalType = DefaultIntervalNumericalType,
142  typename IntervalKind = IntervalClosed
143 >
147  DataType const& data
148 ) {
149  return { std::min(a.low(), b.low()), std::max(a.high(), b.high()), data };
150 }
151 
157 template <
158  typename DataType = EmptyIntervalData,
159  typename NumericalType = DefaultIntervalNumericalType,
160  typename IntervalKind = IntervalClosed
161 >
165  DataType&& data
166 ) {
167  return { std::min(a.low(), b.low()), std::max(a.high(), b.high()), std::move(data) };
168 }
169 
170 } // namespace utils
171 } // namespace genesis
172 
173 #endif // include guard
genesis::utils::Interval
Type to store an interval (range) between two numbers, as used in the IntervalTree.
Definition: fwd.hpp:42
genesis::utils::DefaultIntervalNumericalType
int DefaultIntervalNumericalType
Default numerical type to use in an Interval.
Definition: interval.hpp:61
genesis::utils::make_safe_interval
Interval< DataType, NumericalType, IntervalKind > make_safe_interval(NumericalType lhs, NumericalType rhs)
Definition: utils/containers/interval_tree/functions.hpp:58
genesis::utils::Interval::high
numerical_type high() const
Return the upper bound of the interval.
Definition: interval.hpp:472
genesis::utils::Interval::low
numerical_type low() const
Return the lower bound of the interval.
Definition: interval.hpp:464
genesis::utils::join
Interval< DataType, NumericalType, IntervalKind > join(Interval< DataType, NumericalType, IntervalKind > const &a, Interval< DataType, NumericalType, IntervalKind > const &b)
Creates a new Interval that contains both intervals and whatever is between.
Definition: utils/containers/interval_tree/functions.hpp:127
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
interval.hpp