Add given code
This commit is contained in:
parent
c4d81c4e81
commit
3c0ddf3021
1 changed files with 26 additions and 0 deletions
|
|
@ -1 +1,27 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
namespace amby {
|
||||||
|
|
||||||
|
template <typename K, typename V> class interval_map {
|
||||||
|
public:
|
||||||
|
interval_map(V const& init) : init_(init) {}
|
||||||
|
|
||||||
|
void assign(K const& begin, K const& end, V const& val) {
|
||||||
|
// TODO: implement
|
||||||
|
}
|
||||||
|
|
||||||
|
V const& operator[](K const& key) const {
|
||||||
|
auto it = underlying_.upper_bound(key);
|
||||||
|
if (it == underlying_.begin())
|
||||||
|
return init_;
|
||||||
|
return std::prev(it)->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
V init_;
|
||||||
|
std::map<K, V> underlying_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace amby
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue