@@ -61,6 +61,11 @@ Create a build folder, navigate there, run cmake and build the tree-tests target
61
61
You might have to adapt the linker line for gtest, if you built it yourself and didn't install it into your system.
62
62
If you want to generate the pretty drawings, install cairo, pull the submodule and pass INT_TREE_DRAW_EXAMPLES=on to the cmake command line to generate a drawings/make_drawings executeable.
63
63
64
+ Some features of this library require the presence of an optional type.
65
+ If you are using C++17 and up, it will be std::optional.
66
+ Otherwise you can specify INTERVAL_TREE_HAVE_BOOST_OPTIONAL to use boost::optional.
67
+ And if neither, a reduced version of optional is provided in the library, not perfectly exchangeable with std::optional, but sufficient for the library to work.
68
+
64
69
## Draw Dot Graph
65
70
This draws a dot graph of the tree:
66
71
``` c++
@@ -137,37 +142,75 @@ Options are:
137
142
138
143
## Members of IntervalTree<Interval >
139
144
140
- - [ Members of IntervalTree<Interval >] ( #members-of-intervaltreeinterval )
141
- - [ iterator insert(interval_type const& ival)] ( #iterator-insertinterval_type-const-ival )
142
- - [ iterator insert_overlap(interval_type const& ival, bool, bool)] ( #iterator-insert_overlapinterval_type-const-ival-bool-bool )
145
+ - [ interval-tree] ( #interval-tree )
146
+ - [ How an interval tree looks like:] ( #how-an-interval-tree-looks-like )
147
+ - [ Example] ( #example )
148
+ - [ Compile \& Run Testing] ( #compile--run-testing )
149
+ - [ Draw Dot Graph] ( #draw-dot-graph )
150
+ - [ Free Functions] ( #free-functions )
151
+ - [ interval\< NumericT, Kind\> make\_ safe\_ interval(NumericT border1, NumericT border2)] ( #intervalnumerict-kind-make_safe_intervalnumerict-border1-numerict-border2 )
152
+ - [ draw\_ dot\_ graph(std::ostream\& os, interval\_ tree\_ t const\& tree, DrawOptions const\& options)] ( #draw_dot_graphstdostream-os-interval_tree_t-const-tree-drawoptions-const-options )
153
+ - [ Members of IntervalTree] ( #members-of-intervaltree )
154
+ - [ iterator insert(interval\_ type const\& ival)] ( #iterator-insertinterval_type-const-ival )
155
+ - [ Parameters] ( #parameters )
156
+ - [ iterator insert\_ overlap(interval\_ type const\& ival, bool, bool)] ( #iterator-insert_overlapinterval_type-const-ival-bool-bool )
157
+ - [ Parameters] ( #parameters-1 )
143
158
- [ iterator erase(iterator iter)] ( #iterator-eraseiterator-iter )
144
- - [ size_type size() const] ( #size_type-size-const )
145
- - [ (const)iterator find(interval_type const& ival)] ( #constiterator-findinterval_type-const-ival )
146
- - [ (const)iterator find(interval_type const& ival, CompareFunctionT const& compare)] ( #constiterator-findinterval_type-const-ival-comparefunctiont-const-compare )
147
- - [ (const)iterator find_all(interval_type const& ival, OnFindFunctionT const& on_find)] ( #constiterator-find_allinterval_type-const-ival-onfindfunctiont-const-on_find )
159
+ - [ Parameters] ( #parameters-2 )
160
+ - [ size\_ type size() const] ( #size_type-size-const )
161
+ - [ (const)iterator find(interval\_ type const\& ival)] ( #constiterator-findinterval_type-const-ival )
162
+ - [ Parameters] ( #parameters-3 )
163
+ - [ (const)iterator find(interval\_ type const\& ival, CompareFunctionT const\& compare)] ( #constiterator-findinterval_type-const-ival-comparefunctiont-const-compare )
164
+ - [ Parameters] ( #parameters-4 )
165
+ - [ (const)iterator find\_ all(interval\_ type const\& ival, OnFindFunctionT const\& on\_ find)] ( #constiterator-find_allinterval_type-const-ival-onfindfunctiont-const-on_find )
166
+ - [ Parameters] ( #parameters-5 )
148
167
- [ Example] ( #example-1 )
149
- - [ (const)iterator find_all(interval_type const& ival, OnFindFunctionT const& on_find, CompareFunctionT const& compare)] ( #constiterator-find_allinterval_type-const-ival-onfindfunctiont-const-on_find-comparefunctiont-const-compare )
150
- - [ (const)iterator find_next_in_subtree(iterator from, interval_type const& ival)] ( #constiterator-find_next_in_subtreeiterator-from-interval_type-const-ival )
151
- - [ (const)iterator find_next_in_subtree(iterator from, interval_type const& ival, CompareFunctionT const& compare)] ( #constiterator-find_next_in_subtreeiterator-from-interval_type-const-ival-comparefunctiont-const-compare )
152
- - [ (const)iterator overlap_find(interval_type const& ival, bool exclusive)] ( #constiterator-overlap_findinterval_type-const-ival-bool-exclusive )
153
- - [ (const)iterator overlap_find_all(interval_type const& ival, OnFindFunctionT const& on_find, bool exclusive)] ( #constiterator-overlap_find_allinterval_type-const-ival-onfindfunctiont-const-on_find-bool-exclusive )
168
+ - [ (const)iterator find\_ all(interval\_ type const\& ival, OnFindFunctionT const\& on\_ find, CompareFunctionT const\& compare)] ( #constiterator-find_allinterval_type-const-ival-onfindfunctiont-const-on_find-comparefunctiont-const-compare )
169
+ - [ Parameters] ( #parameters-6 )
170
+ - [ (const)iterator find\_ next\_ in\_ subtree(iterator from, interval\_ type const\& ival)] ( #constiterator-find_next_in_subtreeiterator-from-interval_type-const-ival )
171
+ - [ Parameters] ( #parameters-7 )
172
+ - [ (const)iterator find\_ next\_ in\_ subtree(iterator from, interval\_ type const\& ival, CompareFunctionT const\& compare)] ( #constiterator-find_next_in_subtreeiterator-from-interval_type-const-ival-comparefunctiont-const-compare )
173
+ - [ Parameters] ( #parameters-8 )
174
+ - [ (const)iterator overlap\_ find(interval\_ type const\& ival, bool exclusive)] ( #constiterator-overlap_findinterval_type-const-ival-bool-exclusive )
175
+ - [ Parameters] ( #parameters-9 )
176
+ - [ (const)iterator overlap\_ find\_ all(interval\_ type const\& ival, OnFindFunctionT const\& on\_ find, bool exclusive)] ( #constiterator-overlap_find_allinterval_type-const-ival-onfindfunctiont-const-on_find-bool-exclusive )
177
+ - [ Parameters] ( #parameters-10 )
154
178
- [ Example] ( #example-2 )
155
- - [ (const)iterator overlap_find_next_in_subtree(interval_type const& ival, bool exclusive)] ( #constiterator-overlap_find_next_in_subtreeinterval_type-const-ival-bool-exclusive )
156
- - [ interval_tree& deoverlap()] ( #interval_tree-deoverlap )
179
+ - [ (const)iterator overlap\_ find\_ next\_ in\_ subtree(interval\_ type const\& ival, bool exclusive)] ( #constiterator-overlap_find_next_in_subtreeinterval_type-const-ival-bool-exclusive )
180
+ - [ Parameters] ( #parameters-11 )
181
+ - [ interval\_ tree\& deoverlap()] ( #interval_tree-deoverlap )
157
182
- [ After deoverlap] ( #after-deoverlap )
158
- - [ interval_tree& deoverlap_copy()] ( #interval_tree-deoverlap_copy )
159
- - [ interval_tree punch(interval_type const& ival)] ( #interval_tree-punchinterval_type-const-ival )
160
- - [ After punching (with [ 0, 50] )] ( #after-punching-with-0-50 )
161
- - [ interval_tree punch()] ( #interval_tree-punch )
183
+ - [ interval\_ tree deoverlap\_ copy()] ( #interval_tree-deoverlap_copy )
184
+ - [ interval\_ tree punch(interval\_ type const\& ival)] ( #interval_tree-punchinterval_type-const-ival )
185
+ - [ Before punching (closed\_ adjacent intervals)] ( #before-punching-closed_adjacent-intervals )
186
+ - [ After punching (with \[ -10, 60\] )] ( #after-punching-with--10-60 )
187
+ - [ interval\_ tree punch()] ( #interval_tree-punch )
162
188
- [ bool empty() const noexcept] ( #bool-empty-const-noexcept )
163
189
- [ iterator begin()] ( #iterator-begin )
164
190
- [ iterator end()] ( #iterator-end )
165
191
- [ iterator cbegin()] ( #iterator-cbegin )
166
192
- [ iterator cend()] ( #iterator-cend )
167
- - [ reverse_iterator rbegin()] ( #reverse_iterator-rbegin )
168
- - [ reverse_iterator rend()] ( #reverse_iterator-rend )
169
- - [ reverse_iterator crbegin()] ( #reverse_iterator-crbegin )
170
- - [ reverse_iterator crend()] ( #reverse_iterator-crend )
193
+ - [ reverse\_ iterator rbegin()] ( #reverse_iterator-rbegin )
194
+ - [ reverse\_ iterator rend()] ( #reverse_iterator-rend )
195
+ - [ reverse\_ iterator crbegin()] ( #reverse_iterator-crbegin )
196
+ - [ reverse\_ iterator crend()] ( #reverse_iterator-crend )
197
+ - [ Members of Interval] ( #members-of-interval )
198
+ - [ using value\_ type] ( #using-value_type )
199
+ - [ using interval\_ kind] ( #using-interval_kind )
200
+ - [ friend bool operator==(interval const\& lhs, interval const\& other)] ( #friend-bool-operatorinterval-const-lhs-interval-const-other )
201
+ - [ friend bool operator!=(interval const\& lhs, interval const\& other)] ( #friend-bool-operatorinterval-const-lhs-interval-const-other-1 )
202
+ - [ value\_ type low() const] ( #value_type-low-const )
203
+ - [ value\_ type high() const] ( #value_type-high-const )
204
+ - [ \[\[ deprecated\]\] bool overlaps(value\_ type l, value\_ type h) const] ( #deprecated-bool-overlapsvalue_type-l-value_type-h-const )
205
+ - [ bool overlaps\_ exclusive(value\_ type l, value\_ type h) const] ( #bool-overlaps_exclusivevalue_type-l-value_type-h-const )
206
+ - [ bool overlaps(interval const\& other) const] ( #bool-overlapsinterval-const-other-const )
207
+ - [ bool overlaps\_ exclusive(interval const\& other) const] ( #bool-overlaps_exclusiveinterval-const-other-const )
208
+ - [ bool within(value\_ type value) const] ( #bool-withinvalue_type-value-const )
209
+ - [ bool within(interval const\& other) const] ( #bool-withininterval-const-other-const )
210
+ - [ value\_ type operator-(interval const\& other) const] ( #value_type-operator-interval-const-other-const )
211
+ - [ value\_ type size() const] ( #value_type-size-const )
212
+ - [ interval join(interval const\& other) const] ( #interval-joininterval-const-other-const )
213
+ - [ slice\_ type slice(interval const\& other) const] ( #slice_type-sliceinterval-const-other-const )
171
214
172
215
### iterator insert(interval_type const& ival)
173
216
Adds an interval into the tree.
@@ -326,13 +369,20 @@ Same as deoverlap, but not inplace
326
369
327
370
---
328
371
### interval_tree punch(interval_type const& ival)
329
- Removes all intervals from ` ival ` and produces a tree that contains the remaining intervals.
330
- ** The tree must be deoverlapped, or the result is undefined.**
331
- ` ival ` is expected to encompass the entire interval range.
372
+ Cuts the intervals of the tree out of the given interval. Like a cookie cutter cuts out of dough.
373
+ This will return a new interval_tree containing the gaps between the intervals in the tree and the given interval.
374
+ Closed adjacent intervals are treated as exclusive on the borders. [ 0,5] a[ 6,10] a will not produce another interval between 5 and 6 as they are considered within the intervals and nothing fits inbetween.
375
+ Regular closed intervals will not behave like this, so [ 0,5] [ 6,10 ] will produce a new interval [ 5,6] .
376
+ Open intervals with integral numbers will also not produce the gap (5, 6), because (5, 6) is empty for integers, not for floats.
377
+
378
+ ** IMPORTANT! The tree must be deoverlapped, or the result is undefined.**
379
+ ` ival ` can be any subrange of the tree, including encompassing the whole tree.
332
380
333
381
** Returns** : A new interval_tree containing the gaps.
334
- ### After punching (with [ 0, 50] )
335
- ![ AfterPunch] ( https://cloud.githubusercontent.com/assets/6238896/24613645/2dbf72e8-1889-11e7-813f-6d16fe0ad327.png )
382
+ ### Before punching (closed_adjacent intervals)
383
+ ![ BeforePunch] ( https://private-user-images.githubusercontent.com/6238896/471147224-5c631e00-dea4-4b75-a3bf-6fdd8ec1440b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTM1NjI1MzQsIm5iZiI6MTc1MzU2MjIzNCwicGF0aCI6Ii82MjM4ODk2LzQ3MTE0NzIyNC01YzYzMWUwMC1kZWE0LTRiNzUtYTNiZi02ZmRkOGVjMTQ0MGIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDcyNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTA3MjZUMjAzNzE0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZDQ0NWIwMTcwMjZhNDA1YmUwNGI1YTIzNTBhZTQ5OTNhMWFiOTU5ZmU0N2E3NDI0NTQ0MzYwODA4N2E2MGFiZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.P5zLeXg0-9bd20Thj6pfq_WxriMn4GC_lDSLzzGKMbw )
384
+ ### After punching (with [ -10, 60] )
385
+ ![ AfterPunch] ( https://private-user-images.githubusercontent.com/6238896/471147227-5c226d1d-d544-4a43-89a4-b3545145107d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTM1NjI1MzQsIm5iZiI6MTc1MzU2MjIzNCwicGF0aCI6Ii82MjM4ODk2LzQ3MTE0NzIyNy01YzIyNmQxZC1kNTQ0LTRhNDMtODlhNC1iMzU0NTE0NTEwN2QucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDcyNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTA3MjZUMjAzNzE0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NmE2ZDUzMjU2ZTNjZWQ0Y2QzYjQ3ZGUyYjgyNWM2NDViYTAxMTdlY2RjYmQyMzg4OWFmZDlhMWU5YjY4NjlmZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.Infe9i281LDOEC5GeBFuLHVE6Xjqw7KvcUo-gv3hjpk )
336
386
337
387
---
338
388
### interval_tree punch()
@@ -395,7 +445,7 @@ Returns a past the end const_iterator in reverse.
395
445
** Returns** : past the end const_iterator.
396
446
397
447
## Members of Interval
398
- ___ You can implement your own interval if you provide the same functions, except (operator-, size, operator!=).___
448
+ ___ You can implement your own interval if you provide the same functions, except (slice, operator-, size, operator!=).___
399
449
400
450
There are 6 types of intervals:
401
451
- open: (a, b)
@@ -457,3 +507,12 @@ Overlapping intervals have 0 distance.
457
507
Returns The amount of elements in the interval when integral, or the distance between the 2 bounds when floating point.
458
508
### interval join(interval const& other) const
459
509
Joins 2 intervals and whatever is inbetween.
510
+ ### slice_type<interval > slice(interval const& other) const
511
+ Removes other from this interval returning what is remaining.
512
+ The range of other going beyond the range of this is ignored.
513
+ Returns a struct with 2 members: left_slice and right_slice.
514
+ [ this interval ]
515
+ [ left] [ other ] [ right]
516
+
517
+ When the intervals are closed, adjacent results are differenty by 1.
518
+ [ 0, 9] .slice([ 5, 19] ) => left: [ 0, 4] , right: nullopt
0 commit comments