Pixie
Loading...
Searching...
No Matches
tree.h
Go to the documentation of this file.
1#pragma once
2
10
11#include <cstddef>
12
13namespace pixie {
14
18struct TreeNode {
20 std::size_t number;
21
23 std::size_t pos;
24
30 TreeNode(std::size_t node_number, std::size_t representation_position)
31 : number(node_number), pos(representation_position) {}
32};
33
42template <class Impl>
43class TreeBase {
44 public:
45 using Node = TreeNode;
46
51 Node root() const { return impl().root_impl(); }
52
57 std::size_t size() const { return impl().size_impl(); }
58
63 bool empty() const { return size() == 0; }
64
70 bool is_leaf(const Node& node) const { return impl().is_leaf_impl(node); }
71
77 bool is_root(const Node& node) const { return impl().is_root_impl(node); }
78
84 std::size_t degree(const Node& node) const {
85 return impl().degree_impl(node);
86 }
87
93 Node first_child(const Node& node) const {
94 return impl().first_child_impl(node);
95 }
96
103 Node child(const Node& node, std::size_t index) const {
104 return impl().child_impl(node, index);
105 }
106
112 Node parent(const Node& node) const { return impl().parent_impl(node); }
113
119 bool is_last_child(const Node& node) const {
120 return impl().is_last_child_impl(node);
121 }
122
128 Node next_sibling(const Node& node) const {
129 return impl().next_sibling_impl(node);
130 }
131
132 private:
134 const Impl& impl() const { return static_cast<const Impl&>(*this); }
135};
136
137} // namespace pixie
CRTP facade for rooted ordered trees.
Definition tree.h:43
bool is_leaf(const Node &node) const
Check whether node has no children.
Definition tree.h:70
bool is_root(const Node &node) const
Check whether node is the root.
Definition tree.h:77
Node first_child(const Node &node) const
Return the first child of node.
Definition tree.h:93
std::size_t degree(const Node &node) const
Return the number of children of node.
Definition tree.h:84
std::size_t size() const
Return the number of nodes.
Definition tree.h:57
Node next_sibling(const Node &node) const
Return the next sibling of node.
Definition tree.h:128
bool empty() const
Check whether the tree contains no nodes.
Definition tree.h:63
Node parent(const Node &node) const
Return the parent of node.
Definition tree.h:112
Node root() const
Return the root node.
Definition tree.h:51
bool is_last_child(const Node &node) const
Check whether node is its parent's last child.
Definition tree.h:119
Node child(const Node &node, std::size_t index) const
Return a child of node by zero-based index.
Definition tree.h:103
Logical node handle shared by succinct rooted-tree encodings.
Definition tree.h:18
std::size_t number
Logical node number in the encoding's traversal order.
Definition tree.h:20
std::size_t pos
Bit position representing the node in the succinct encoding.
Definition tree.h:23
TreeNode(std::size_t node_number, std::size_t representation_position)
Construct a node handle.
Definition tree.h:30