@@ -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,49 @@ 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
+ #### Example
109
+ ``` c++
110
+ tree.insert({3, 7});
111
+ tree.insert({3, 7});
112
+ tree.insert({8, 9});
113
+ tree.find_all({3, 7}, [ ] (auto iter) /* iter will be const_iterator if tree is const * / {
114
+ // will find all intervals that are exactly {3,7} here.
115
+ });
116
+ ```
117
+
118
+ ** Returns** : An iterator to the found element, or std::end(tree).
119
+
120
+ ---
121
+ ### (const)iterator find_all(interval_type const& ival, OnFindFunctionT const& on_find, CompareFunctionT const& compare)
122
+ Find all intervals in the tree that the compare function returns true for.
123
+ #### Parameters
124
+ * ` ival ` The interval to find.
125
+ * ` compare ` The compare function to compare intervals with.
126
+ * ` on_find ` A function of type bool(iterator) that is called when an interval was found.
127
+ Return true to continue, false to preemptively abort search.
128
+
129
+ ** Returns** : An iterator to the found element, or std::end(tree).
130
+
131
+ ---
132
+ ### (const)iterator find_next_in_subtree(iterator from, interval_type const& ival)
133
+ Finds the next exact match EXCLUDING from in the subtree originating from "from".
134
+ You cannot find all matches this way, use find_all for that.
100
135
#### Parameters
101
136
* ` from ` The iterator to start from. (including this iterator!)
102
137
* ` ival ` The interval to find.
103
138
104
139
** Returns** : An iterator to the found element, or std::end(tree).
105
140
106
141
---
107
- ### iterator find_next(iterator from, interval_type const& ival, CompareFunctionT const& compare)
108
- Finds the next exact match INCLUDING from.
142
+ ### (const)iterator find_next(iterator from, interval_type const& ival, CompareFunctionT const& compare)
143
+ Finds the next exact match EXCLUDING from in the subtree originating from "from".
144
+ You cannot find all matches this way, use find_all for that.
109
145
#### Parameters
110
146
* ` from ` The iterator to start from (including this iterator!)
111
147
* ` ival ` The interval to find.
@@ -114,10 +150,40 @@ Finds the next exact match INCLUDING from.
114
150
** Returns** : An iterator to the found element, or std::end(tree).
115
151
116
152
---
117
- ### iterator overlap_find(interval_type const& ival, bool exclusive)
153
+ ### (const)iterator overlap_find(interval_type const& ival, bool exclusive)
154
+ Finds the first interval in the interval tree that overlaps the given interval.
155
+ #### Parameters
156
+ * ` ival ` The interval to find an overlap for.
157
+ * ` exclusive ` Exclude borders from overlap check. Defaults to false.
158
+
159
+ ** Returns** : An iterator to the found element, or std::end(tree).
160
+
161
+ ---
162
+ ### (const)iterator overlap_find_all(interval_type const& ival, OnFindFunctionT const& on_find, bool exclusive)
118
163
Finds the first interval in the interval tree that overlaps the given interval.
119
164
#### Parameters
120
165
* ` ival ` The interval to find an overlap for.
166
+ * ` on_find ` A function of type bool(iterator) that is called when an interval was found.
167
+ Return true to continue, false to preemptively abort search.
168
+ * ` exclusive ` Exclude borders from overlap check. Defaults to false.
169
+ #### Example
170
+ ``` c++
171
+ tree.insert({0, 5});
172
+ tree.insert({5, 10});
173
+ tree.insert({10, 15});
174
+ tree.overlap_find_all({5, 5}, [ ] (auto iter) /* iter will be const_iterator if tree is const * / {
175
+ // called with {0, 5} and {5, 10} in unspecified order.
176
+ });
177
+ ```
178
+
179
+ ** Returns** : An iterator to the found element, or std::end(tree).
180
+
181
+ ---
182
+ ### (const)iterator overlap_find_next_in_subtree(interval_type const& ival, bool exclusive)
183
+ Finds the next interval in the subtree originating in ival that overlaps the given interval.
184
+ You cannot find all matches this way, use overlap_find_all for that.
185
+ #### Parameters
186
+ * ` ival ` The interval to find an overlap for.
121
187
* ` exclusive ` Exclude borders from overlap check. Defaults to false.
122
188
123
189
** Returns** : An iterator to the found element, or std::end(tree).
@@ -167,3 +233,37 @@ Returns a past the end iterator.
167
233
** Returns** : past the end iterator.
168
234
169
235
---
236
+
237
+ ## Members of Interval
238
+ You can implement your own interval if you provide all the same functions.
239
+ ### using value_type
240
+ The underlying interval numerical type
241
+ ### using interval_kind
242
+ The interval kind. You dont need to provides this typedef in your interval class.
243
+ ### friend bool operator==(interval const& lhs, interval const& other)
244
+ Comparison operator.
245
+ ### friend bool operator!=(interval const& lhs, interval const& other)
246
+ Comparison operator.
247
+ ### value_type low() const
248
+ Lower bound.
249
+ ### value_type high() const
250
+ Upper bound.
251
+ ### bool overlaps(value_type l, value_type h) const
252
+ Overlap these bounds with this interval (closed)?
253
+ ### bool overlaps_exclusive(value_type l, value_type h) const
254
+ Overlap these bounds with this interval excluding borders?
255
+ ### bool overlaps(interval const& other) const
256
+ Like overlaps with lower and upper bound.
257
+ ### bool overlaps_exclusive(interval const& other) const
258
+ Like overlaps with lower and upper bound.
259
+ ### bool within(value_type value) const
260
+ Is the value within the interval (closed)?
261
+ ### bool within(interval const& other) const
262
+ Is the interval within the interval?
263
+ ### value_type operator-(interval const& other) const
264
+ Calculates the distance between the two intervals.
265
+ Overlapping intervals have 0 distance.
266
+ ### value_type size() const
267
+ Returns high - low.
268
+ ### interval join(interval const& other) const
269
+ Joins 2 intervals and whatever is inbetween.
0 commit comments