Interval-Map is a C++ implementation of an interval map data structure. It allows you to associate values with intervals and perform efficient lookups based on a key within those intervals.
To build the project, you can use the provided Makefile. The project uses CMake for building and Catch2 for testing. Make sure you have CMake installed on your system.
make
This will create a build directory, generate the build files using CMake, and build the IntervalMap executable.
make test
This command builds and runs the tests using the Catch2 framework.
make clean
This command cleans up the build directory and removes any generated files.
The main component of this project is the interval_map class defined in interval_map.hpp
. You can include this header file in your project and use the interval_map
class to create and manipulate interval maps.
#include "interval_map.hpp"
int main() {
// Example usage of the interval_map class
interval_map<int, std::string> myIntervalMap("default_value");
// Assigning a value to the interval [1, 5)
myIntervalMap.assign(1, 5, "assigned_value");
// Accessing the value at key 3
std::cout << "Value at key 3: " << myIntervalMap[3] << std::endl;
return 0;
}
The assign operation in the interval_map class has a time complexity of
The space complexity of the interval_map
class is primarily determined by the size of the underlying std::map
(m_map
). Assuming the number of intervals is
Additionally, the m_valBegin
variable, which stores the value associated with intervals that extend to negative infinity, contributes to the overall space complexity. However, its impact is constant, so it does not change the asymptotic space complexity.
In summary, the space complexity of the interval_map
class is