@@ -42,7 +42,11 @@ int main()
42
42
Having googletest (find here on github) installed / built is a requirement to run the tests.
43
43
Navigate into the tests folder and build the source using the CMakeLists. You might have to adapt the linker line for gtest, if you built it yourself and didn't install it into your system.
44
44
45
- ## Members
45
+ ## Free Functions
46
+ ### interval<NumericT, Kind> make_safe_interval(NumericT border1, NumericT border2)
47
+ Creates an interval where the borders are sorted so the lower border is the first one.
48
+
49
+ ## Members of IntervalTree<Interval >
46
50
### iterator insert(interval_type const& ival)
47
51
Adds an interval into the tree.
48
52
#### Parameters
@@ -76,7 +80,7 @@ Returns the amount of nodes in the tree.
76
80
** Returns** : The amount of tree nodes.
77
81
78
82
---
79
- ### iterator find(interval_type const& ival)
83
+ ### (const) iterator find(interval_type const& ival)
80
84
Finds the first interval in the interval tree that has an exact match.
81
85
** WARNING** : There is no special handling for floats.
82
86
#### Parameters
@@ -85,7 +89,7 @@ Finds the first interval in the interval tree that has an exact match.
85
89
** Returns** : An iterator to the found element, or std::end(tree).
86
90
87
91
---
88
- ### iterator find(interval_type const& ival, CompareFunctionT const& compare)
92
+ ### (const) iterator find(interval_type const& ival, CompareFunctionT const& compare)
89
93
Finds the first interval in the interval tree that has the following statement evaluate to true: compare(ival, interval_in_tree);
90
94
Allows for propper float comparisons.
91
95
#### Parameters
@@ -95,17 +99,40 @@ Allows for propper float comparisons.
95
99
** Returns** : An iterator to the found element, or std::end(tree).
96
100
97
101
---
98
- ### iterator find_next(iterator from, interval_type const& ival)
99
- Finds the next exact match INCLUDING from.
102
+ ### (const)iterator find_all(interval_type const& ival, OnFindFunctionT const& on_find)
103
+ Find all intervals in the tree matching ival.
104
+ #### Parameters
105
+ * ` ival ` The interval to find.
106
+ * ` on_find ` A function of type bool(iterator) that is called when an interval was found.
107
+ Return true to continue, false to preemptively abort search.
108
+
109
+ ** Returns** : An iterator to the found element, or std::end(tree).
110
+
111
+ ---
112
+ ### (const)iterator find_all(interval_type const& ival, OnFindFunctionT const& on_find, CompareFunctionT const& compare)
113
+ Find all intervals in the tree that the compare function returns true for.
114
+ #### Parameters
115
+ * ` ival ` The interval to find.
116
+ * ` compare ` The compare function to compare intervals with.
117
+ * ` on_find ` A function of type bool(iterator) that is called when an interval was found.
118
+ Return true to continue, false to preemptively abort search.
119
+
120
+ ** Returns** : An iterator to the found element, or std::end(tree).
121
+
122
+ ---
123
+ ### (const)iterator find_next_in_subtree(iterator from, interval_type const& ival)
124
+ Finds the next exact match EXCLUDING from in the subtree originating from "from".
125
+ You cannot find all matches this way, use find_all for that.
100
126
#### Parameters
101
127
* ` from ` The iterator to start from. (including this iterator!)
102
128
* ` ival ` The interval to find.
103
129
104
130
** Returns** : An iterator to the found element, or std::end(tree).
105
131
106
132
---
107
- ### iterator find_next(iterator from, interval_type const& ival, CompareFunctionT const& compare)
108
- Finds the next exact match INCLUDING from.
133
+ ### (const)iterator find_next(iterator from, interval_type const& ival, CompareFunctionT const& compare)
134
+ Finds the next exact match EXCLUDING from in the subtree originating from "from".
135
+ You cannot find all matches this way, use find_all for that.
109
136
#### Parameters
110
137
* ` from ` The iterator to start from (including this iterator!)
111
138
* ` ival ` The interval to find.
@@ -114,10 +141,31 @@ Finds the next exact match INCLUDING from.
114
141
** Returns** : An iterator to the found element, or std::end(tree).
115
142
116
143
---
117
- ### iterator overlap_find(interval_type const& ival, bool exclusive)
144
+ ### (const)iterator overlap_find(interval_type const& ival, bool exclusive)
145
+ Finds the first interval in the interval tree that overlaps the given interval.
146
+ #### Parameters
147
+ * ` ival ` The interval to find an overlap for.
148
+ * ` exclusive ` Exclude borders from overlap check. Defaults to false.
149
+
150
+ ** Returns** : An iterator to the found element, or std::end(tree).
151
+
152
+ ---
153
+ ### (const)iterator overlap_find_all(interval_type const& ival, OnFindFunctionT const& on_find, bool exclusive)
118
154
Finds the first interval in the interval tree that overlaps the given interval.
119
155
#### Parameters
120
156
* ` ival ` The interval to find an overlap for.
157
+ * ` on_find ` A function of type bool(iterator) that is called when an interval was found.
158
+ Return true to continue, false to preemptively abort search.
159
+ * ` exclusive ` Exclude borders from overlap check. Defaults to false.
160
+
161
+ ** Returns** : An iterator to the found element, or std::end(tree).
162
+
163
+ ---
164
+ ### (const)iterator overlap_find_next_in_subtree(interval_type const& ival, bool exclusive)
165
+ Finds the next interval in the subtree originating in ival that overlaps the given interval.
166
+ You cannot find all matches this way, use overlap_find_all for that.
167
+ #### Parameters
168
+ * ` ival ` The interval to find an overlap for.
121
169
* ` exclusive ` Exclude borders from overlap check. Defaults to false.
122
170
123
171
** Returns** : An iterator to the found element, or std::end(tree).
@@ -167,3 +215,37 @@ Returns a past the end iterator.
167
215
** Returns** : past the end iterator.
168
216
169
217
---
218
+
219
+ ## Members of Interval
220
+ You can implement your own interval if you provide all the same functions.
221
+ ### using value_type
222
+ The underlying interval numerical type
223
+ ### using interval_kind
224
+ The interval kind. You dont need to provides this typedef in your interval class.
225
+ ### friend bool operator==(interval const& lhs, interval const& other)
226
+ Comparison operator.
227
+ ### friend bool operator!=(interval const& lhs, interval const& other)
228
+ Comparison operator.
229
+ ### value_type low() const
230
+ Lower bound.
231
+ ### value_type high() const
232
+ Upper bound.
233
+ ### bool overlaps(value_type l, value_type h) const
234
+ Overlap these bounds with this interval (closed)?
235
+ ### bool overlaps_exclusive(value_type l, value_type h) const
236
+ Overlap these bounds with this interval excluding borders?
237
+ ### bool overlaps(interval const& other) const
238
+ Like overlaps with lower and upper bound.
239
+ ### bool overlaps_exclusive(interval const& other) const
240
+ Like overlaps with lower and upper bound.
241
+ ### bool within(value_type value) const
242
+ Is the value within the interval (closed)?
243
+ ### bool within(interval const& other) const
244
+ Is the interval within the interval?
245
+ ### value_type operator-(interval const& other) const
246
+ Calculates the distance between the two intervals.
247
+ Overlapping intervals have 0 distance.
248
+ ### value_type size() const
249
+ Returns high - low.
250
+ ### interval join(interval const& other) const
251
+ Joins 2 intervals and whatever is inbetween.
0 commit comments