31 template <
class Element,
size_t k>
39 explicit Tree(
size_t height) : height_(height) {
42 this->leaf_count_ =
static_cast<size_t>(std::pow(k, height_ - 1));
43 size_t const total_nodes = (k * this->leaf_count_ - 1) / (k - 1);
45 this->nodes_.resize(total_nodes);
46 this->mark_.resize(total_nodes);
61 return this->nodes_.size() - this->leaf_count_;
67 size_t GetLastLeaf()
const {
return this->nodes_.size() - 1; }
85 size_t GetChild(
size_t parent,
size_t child_index)
const {
86 assert(child_index < k);
87 assert(parent < this->nodes_.size());
89 return k * parent + 1 + child_index;
97 assert(child < this->nodes_.size());
100 return (child - 1) / k;
107 assert(index < this->nodes_.size());
109 return this->nodes_.at(index);
117 assert(node < this->mark_.size());
119 return this->mark_[node];
127 assert(node < this->mark_.size());
129 this->mark_[node] =
true;
135 void Unmark() { this->mark_.assign(this->mark_.size(),
false); }
147 size_t leaf_count_ = 0;
148 std::vector<Element> nodes_;
149 std::vector<bool> mark_;