Interval Trees
- You are given
IntervalTree.h. You should not modify this file.IntervalTree.hcontains the base classIntervalTree, which you will inherit.
- And interval has a lower and upper bound
- For the purposes of our lab, the lower bound is inclusive, and the upper bound is exclusive
- Logic defining the qualities of intervals can be found in the
Intervalstruct inIntervalTree.h
An Augmented Interval Tree (AIT) is a specialized Binary Search Tree (BST) that stores intervals instead of single values.
- Each AIT node also stores a "min-max" interval that defines the minimum lower bound and maximum upper bound of the local subtree.
- See
NodeinIntervalTree.h
- See
- Create a class called
AugmentedIntervalTreethat inherits fromIntervalTree(found inIntervalTree.h)- Your class should be stored in
AugmentedIntervalTree.h- You do not need to separate your code into separate
.hand.cppfiles, though you may choose to do so if you desire. - If you do write an
AugmentedIntervalTree.cpp, be sure to submit it in addition to the other files. - Note: it can be tricky to implement templated classes in a
.cpp, so only attempt this if you know the issues and their solutions.
- You do not need to separate your code into separate
- This class must implement all the pure virtual functions found in
IntervalTree.h - This class is expected to not have any memory leaks
- Your class should be stored in
- Write your own
tests.cpp- This file should contain a
int main() {...}method that runs your tests - You should include tests that exercise all the methods overridden in
AugmentedIntervalTree- You do not need to test large datasets, but you should try to verify that your code works properly
- This file should contain a
- Write a
makefile- Target
testshould build a clean copy of your test binary and run your tests with valgrind- IMPORTANT Do not include the
-sflag for valgrind. See example makefile below.
- IMPORTANT Do not include the
- Target
- Submit
AugmentedIntervalTree.h,tests.cpp, andmakefile
Be sure to use tabs and not spaces for indentation!
build:
g++ -g -std=c++11 -o test tests.cpp
test: build
valgrind --leak-check=full ./test- Download the lab files
- Create a file named
AugmentedIntervalTree.hAugmentedIntervalTreeshould extendIntervalTree
- Stub out implementations of the inherited virtual methods
- Simple
coutstatements and dummy return values
- Simple
- Create a file named
my_tests.cpp- Start with a simple
mainmethod that creates anAugmentedIntervalTree
- Start with a simple
- Create a
makefilethat looks like the example above - Make sure your code compiles before moving on!
make testshould run without errors
- For each of the following methods:
~AugmentedIntervalTree,is_empty,add,clear,query,remove- Write tests that exercise that method and assert the state of the tree after the method is called
- The new tests should fail
- Implement the method
- The tests should now pass
- Once the last feature is well tested, move to the next feature
- Keep the old tests: they will help you catch errors you introduce while implementing later features
- Write tests that exercise that method and assert the state of the tree after the method is called
- Things to test (not an exhaustive list):
- Adding duplicate intervals
- Remove intervals that aren't present
- Add after clear
- Query on empty
- Query on boundaries (inclusive vs exclusive)
- Remove on an empty tree
- Query after remove
- Structure after add and remove
- Empty after clear?
- Other things to remember:
- Make sure
queryuses an inoder traversal so the output is sorted - No memory leaks
- To refer to
rootin your child class, usethis->root. Do NOT overrideroot, or this will cause theto_stringmethod in the parent class to return the empty string.
- Make sure
- Turn in
AugmentedIntervalTree.h,my_tests.cpp, andmakefile
- 10 points for tests written by you
- 2 points each for
is_empty,add,clear,query, andremove
- 2 points each for
- 90 points for autograder tests
- 20 points for basic tests of
add,clearandis_empty - 20 points for basic tests of
addandquery - 20 points for basic tests of
add,query, andremove - 10 points for advanced tests
- 20 points for no memory leaks on all tests
- 20 points for basic tests of