Itoyori  v0.0.1
workhint_view.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ityr/common/util.hpp"
5 
6 namespace ityr {
7 
8 template <typename W>
9 class workhint_range;
10 
11 template <typename W>
13  using value_type = W;
14 
15 public:
16  struct bin_tree_node {
17  value_type left_work;
18  value_type right_work;
19  };
20 
21  constexpr workhint_range_view() noexcept {}
22 
24  : bin_tree_view_(s) {}
25 
27  return bin_tree_view_[0].get();
28  }
29 
30  void set_workhint(const value_type& v1, const value_type& v2) {
31  bin_tree_view_[0].put({v1, v2});
32  }
33 
34  std::pair<workhint_range_view, workhint_range_view> get_children() const {
35  auto n = bin_tree_view_.size() - 1;
36  ITYR_CHECK(n > 1);
37  ITYR_CHECK(n % 2 == 0);
38  return {workhint_range_view(bin_tree_view_.subspan(1 , n / 2)),
39  workhint_range_view(bin_tree_view_.subspan(n / 2 + 1, n / 2))};
40  }
41 
42  bool empty() const { return bin_tree_view_.empty(); }
43 
44  bool has_children() const { return bin_tree_view_.size() > 2; }
45 
46 private:
47  global_span<bin_tree_node> bin_tree_view_;
48 };
49 
50 template <>
51 class workhint_range_view<void> {};
52 
53 }
Global span to represent a view of a global memory range.
Definition: global_span.hpp:33
Definition: workhint_view.hpp:12
bin_tree_node get_workhint() const
Definition: workhint_view.hpp:26
bool has_children() const
Definition: workhint_view.hpp:44
bool empty() const
Definition: workhint_view.hpp:42
void set_workhint(const value_type &v1, const value_type &v2)
Definition: workhint_view.hpp:30
std::pair< workhint_range_view, workhint_range_view > get_children() const
Definition: workhint_view.hpp:34
constexpr workhint_range_view(global_span< bin_tree_node > s)
Definition: workhint_view.hpp:23
constexpr workhint_range_view() noexcept
Definition: workhint_view.hpp:21
#define ITYR_CHECK(cond)
Definition: util.hpp:48
Definition: allocator.hpp:16
Definition: workhint_view.hpp:16
value_type right_work
Definition: workhint_view.hpp:18
value_type left_work
Definition: workhint_view.hpp:17