Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some unit tests #14

Merged
merged 6 commits into from Dec 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions IntervalTree.h
Expand Up @@ -63,7 +63,7 @@ class IntervalTree {
{ }

private:
std::unique_ptr<intervalTree> copyTree(intervalTree& orig){
std::unique_ptr<intervalTree> copyTree(const intervalTree& orig){
return std::unique_ptr<intervalTree>(new intervalTree(orig));
}
public:
Expand All @@ -86,6 +86,7 @@ class IntervalTree {
return *this;
}

// Note: changes the order of ivals
IntervalTree<T,K>(
intervalVector& ivals,
std::size_t depth = 16,
Expand Down Expand Up @@ -131,8 +132,8 @@ class IntervalTree {
intervalVector lefts;
intervalVector rights;

for (typename intervalVector::iterator i = ivals.begin(); i != ivals.end(); ++i) {
interval& interval = *i;
for (typename intervalVector::const_iterator i = ivals.begin(); i != ivals.end(); ++i) {
const interval& interval = *i;
if (interval.stop < center) {
lefts.push_back(interval);
} else if (interval.start > center) {
Expand All @@ -151,6 +152,12 @@ class IntervalTree {
}
}

intervalVector findOverlapping(K start, K stop) const {
intervalVector ov;
this->findOverlapping(start, stop, ov);
return ov;
}

void findOverlapping(K start, K stop, intervalVector& overlapping) const {
if (!intervals.empty() && ! (stop < intervals.front().start)) {
for (typename intervalVector::const_iterator i = intervals.begin(); i != intervals.end(); ++i) {
Expand All @@ -171,6 +178,12 @@ class IntervalTree {

}

intervalVector findContained(K start, K stop) const {
intervalVector contained;
this->findContained(start, stop, contained);
return contained;
}

void findContained(K start, K stop, intervalVector& contained) const {
if (!intervals.empty() && ! (stop < intervals.front().start)) {
for (typename intervalVector::const_iterator i = intervals.begin(); i != intervals.end(); ++i) {
Expand Down