Skip to content

Commit 8c49d18

Browse files
committed
Fixes, Optimizations, FindAll, Doc.
1 parent 1ee4199 commit 8c49d18

File tree

6 files changed

+543
-110
lines changed

6 files changed

+543
-110
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ __history/
99
main.hpp
1010
main.cpp
1111
*.png
12+
.vscode
1213

1314
tests/bin/*
1415
tests/build/*

README.md

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ int main()
4242
Having googletest (find here on github) installed / built is a requirement to run the tests.
4343
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.
4444

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>
4650
### iterator insert(interval_type const& ival)
4751
Adds an interval into the tree.
4852
#### Parameters
@@ -76,7 +80,7 @@ Returns the amount of nodes in the tree.
7680
**Returns**: The amount of tree nodes.
7781

7882
---
79-
### iterator find(interval_type const& ival)
83+
### (const)iterator find(interval_type const& ival)
8084
Finds the first interval in the interval tree that has an exact match.
8185
**WARNING**: There is no special handling for floats.
8286
#### Parameters
@@ -85,7 +89,7 @@ Finds the first interval in the interval tree that has an exact match.
8589
**Returns**: An iterator to the found element, or std::end(tree).
8690

8791
---
88-
### iterator find(interval_type const& ival, CompareFunctionT const& compare)
92+
### (const)iterator find(interval_type const& ival, CompareFunctionT const& compare)
8993
Finds the first interval in the interval tree that has the following statement evaluate to true: compare(ival, interval_in_tree);
9094
Allows for propper float comparisons.
9195
#### Parameters
@@ -95,17 +99,40 @@ Allows for propper float comparisons.
9599
**Returns**: An iterator to the found element, or std::end(tree).
96100

97101
---
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.
100126
#### Parameters
101127
* `from` The iterator to start from. (including this iterator!)
102128
* `ival` The interval to find.
103129

104130
**Returns**: An iterator to the found element, or std::end(tree).
105131

106132
---
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.
109136
#### Parameters
110137
* `from` The iterator to start from (including this iterator!)
111138
* `ival` The interval to find.
@@ -114,10 +141,31 @@ Finds the next exact match INCLUDING from.
114141
**Returns**: An iterator to the found element, or std::end(tree).
115142

116143
---
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)
118154
Finds the first interval in the interval tree that overlaps the given interval.
119155
#### Parameters
120156
* `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.
121169
* `exclusive` Exclude borders from overlap check. Defaults to false.
122170

123171
**Returns**: An iterator to the found element, or std::end(tree).
@@ -167,3 +215,37 @@ Returns a past the end iterator.
167215
**Returns**: past the end iterator.
168216

169217
---
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

Comments
 (0)