5 #include <boost/container/detail/std_fwd.hpp>
6 #include <boost/icl/discrete_interval.hpp>
7 #include <boost/icl/interval_map.hpp>
8 #include <boost/icl/interval_set.hpp>
12 #include "../instance/job.hpp"
13 #include "generated_config.hpp"
14 #include "../util/log.hpp"
17 namespace level_tree {
19 class LinearLevelAssigner {
21 LinearLevelAssigner(
double min,
double max,
unsigned int levels);
22 unsigned int get_level(
double amount)
const;
24 bool operator==(
const LinearLevelAssigner & rhs)
const;
26 unsigned int level_count()
const;
36 template<
class Key,
class LevelAssigner>
39 using JobId = Job::JobId;
40 using Interval =
typename boost::icl::discrete_interval<Key>::type;
41 using LevelProfile = std::vector<std::tuple<const Interval, unsigned int, double>>;
42 using ContentData = std::vector<std::pair<const Interval, const JobSet>>;
44 LevelTree(LevelAssigner level_assigner, Interval horizon);
49 Intervals operator-(
const Intervals &rhs)
const;
50 Intervals operator+(
const Intervals &rhs)
const;
51 Intervals operator&(
const Intervals &rhs)
const;
52 Intervals operator!()
const;
54 Intervals extend(Key extend_left, Key extend_right)
const;
55 Intervals move_left(Key amount)
const;
57 void push_back(Interval interval);
58 const std::vector<Interval> & get()
const;
63 bool overlaps(
const Interval & interval)
const;
67 template<
class _CharT,
class _Traits>
68 friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& stream,
const typename LevelTree<Key, LevelAssigner>::Intervals & intervals) {
72 for (
const auto & interval : intervals.get()) {
87 std::vector<Interval> content;
90 Intervals operator_base(binop op,
const Intervals & rhs)
const;
93 static Interval make_interval(Key start, Key end)
95 #ifdef ENABLE_ASSERTIONS
98 return Interval(start, end);
102 void insert(
const Interval &interval, JobSet payload);
103 void remove(
const Interval &interval,
const JobSet &payload);
105 void insert(
const Interval &interval, JobId job,
double amount);
106 void remove(
const Interval &interval, JobId job,
double amount);
110 unsigned int level_at(Key point);
113 Intervals get_level(
unsigned int level);
114 LevelProfile get_profile(
const Interval &query);
115 LevelProfile get_profile();
116 ContentData get_content();
119 bool operator==(
const LevelTree<Key, LevelAssigner> & rhs);
126 template<
class _CharT,
class _Traits>
127 friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& stream,
const typename LevelTree<Key, LevelAssigner>::Interval & interval);
130 void update_levels(
const LevelProfile &oldp,
const LevelProfile &newp);
132 std::vector<boost::icl::interval_set<Key>> levels;
133 boost::icl::interval_map<Key, JobSet> content;
135 LevelAssigner level_assigner;
140 bool strictly_before(
const Interval &lhs,
const Interval &rhs);
141 bool strictly_after(
const Interval &lhs,
const Interval &rhs);
142 bool contains(
const Interval &lhs,
const Interval &rhs);
145 void dbg_verify_level_containment();
146 void dbg_verify_level_assignment();