@@ -22,8 +22,13 @@ int main()
22
22
{
23
23
using namespace lib_interval_tree;
24
24
25
- // interval_tree <interval <int >>;
26
- interval_tree_t <int > tree;
25
+ // interval_tree<interval<int >>; // closed by default
26
+ // interval_tree<interval<int, open>>;
27
+ // interval_tree<interval<int, closed>>;
28
+ // interval_tree<interval<int, left_open>>;
29
+ // interval_tree<interval<int, right_open>>;
30
+ // interval_tree<interval<int, closed_adjacent>>; // counts adjacent intervals as overlapping
31
+ interval_tree_t<int > tree;
27
32
28
33
tree.insert(make_safe_interval<int >(21, 16)); // make_safe_interval swaps low and high if not in right order.
29
34
tree.insert({8, 9});
@@ -42,6 +47,12 @@ int main()
42
47
{
43
48
std::cout << "[ " << i.low() << ", " << i.high() << "] \n";
44
49
}
50
+
51
+ using lib_interval_tree::open;
52
+ // dynamic has some logic overhead.
53
+ interval_tree<interval<int, dynamic>> dynamicIntervals;
54
+ dynamicIntervals.insert({0, 1, interval_border::closed, interval_border::open});
55
+ dynamicIntervals.insert({7, 5, interval_border::open, interval_border::closed_adjacent});
45
56
}
46
57
```
47
58
@@ -315,7 +326,18 @@ Returns a past the end const_iterator in reverse.
315
326
** Returns** : past the end const_iterator.
316
327
317
328
## Members of Interval
318
- ___ You can implement your own interval if you provide all the same functions.___
329
+ ___ You can implement your own interval if you provide the same functions, except (within, operator-, size, operator!=).___
330
+
331
+ There are 6 types of intervals:
332
+ - open: (a, b)
333
+ - left_open: (a, b]
334
+ - right_open: [ a, b)
335
+ - closed: [ a, b]
336
+ - closed_adjacent: [ a, b] (counts adjacent intervals as overlapping)
337
+ - dynamic: Can be any of the above, depending on the input. Not supported for floating point.
338
+
339
+ Which can be picked with the second template parameter of interval:
340
+ ` lib_interval_tree::interval<int, lib_interval_tree::open> `
319
341
320
342
- [ Members of Interval] ( #members-of-interval )
321
343
- [ using value_type] ( #using-value_type )
@@ -324,7 +346,7 @@ ___You can implement your own interval if you provide all the same functions.___
324
346
- [ friend bool operator!=(interval const& lhs, interval const& other)] ( #friend-bool-operatorinterval-const-lhs-interval-const-other-1 )
325
347
- [ value_type low() const] ( #value_type-low-const )
326
348
- [ value_type high() const] ( #value_type-high-const )
327
- - [ bool overlaps(value_type l, value_type h) const] ( #bool-overlapsvalue_type-l-value_type-h-const )
349
+ - [ \[\[ deprecated \]\] bool overlaps(value_type l, value_type h) const] ( #bool-overlapsvalue_type-l-value_type-h-const )
328
350
- [ bool overlaps_exclusive(value_type l, value_type h) const] ( #bool-overlaps_exclusivevalue_type-l-value_type-h-const )
329
351
- [ bool overlaps(interval const& other) const] ( #bool-overlapsinterval-const-other-const )
330
352
- [ bool overlaps_exclusive(interval const& other) const] ( #bool-overlaps_exclusiveinterval-const-other-const )
@@ -346,22 +368,23 @@ Comparison operator.
346
368
Lower bound.
347
369
### value_type high() const
348
370
Upper bound.
349
- ### bool overlaps(value_type l, value_type h) const
371
+ ### \[\[ deprecated \]\] bool overlaps(value_type l, value_type h) const
350
372
Overlap these bounds with this interval (closed)?
373
+ Is deprecated because the overlapping only works with closed intervals.
351
374
### bool overlaps_exclusive(value_type l, value_type h) const
352
375
Overlap these bounds with this interval excluding borders?
353
376
### bool overlaps(interval const& other) const
354
377
Like overlaps with lower and upper bound.
355
378
### bool overlaps_exclusive(interval const& other) const
356
379
Like overlaps with lower and upper bound.
357
380
### bool within(value_type value) const
358
- Is the value within the interval (closed) ?
381
+ Is the value within the interval?
359
382
### bool within(interval const& other) const
360
383
Is the interval within the interval?
361
384
### value_type operator-(interval const& other) const
362
385
Calculates the distance between the two intervals.
363
386
Overlapping intervals have 0 distance.
364
387
### value_type size() const
365
- Returns high - low .
388
+ Returns The amount of elements in the interval when integral, or the distance between the 2 bounds when floating point .
366
389
### interval join(interval const& other) const
367
390
Joins 2 intervals and whatever is inbetween.
0 commit comments