7#include "utility/module.hpp"
10namespace hi::inline
v1 {
18template<
typename Key,
typename T,
typename Compare = std::less<Key>>
24 constexpr ~tree() =
default;
25 constexpr tree(
tree const&)
noexcept =
default;
26 constexpr tree(
tree&&)
noexcept =
default;
27 constexpr tree& operator=(
tree const&)
noexcept =
default;
28 constexpr tree& operator=(
tree&&)
noexcept =
default;
29 constexpr tree()
noexcept =
default;
38 value_type&
operator()(
auto path_first,
auto path_last)
noexcept
40 auto *ptr = find_or_create(path_first, path_last);
53 value_type
const&
operator()(
auto path_first,
auto path_last)
const noexcept
55 auto *ptr = find(path_first, path_last, [](value_type
const&) ->
void {});
69 return this->operator()(cbegin(key), cend(key));
78 value_type
const&
operator[](
auto const& path)
const noexcept
82 return this->operator()(cbegin(path), cend(path));
91 void walk(
auto path_first,
auto path_last,
auto&& func)
noexcept
93 if (
auto element = find(path_first, path_last, [](value_type&) ->
void {})) {
104 void walk(
auto path_first,
auto path_last,
auto&& func)
const noexcept
106 if (
auto element =
find(path_first, path_last, [](value_type
const&) ->
void {})) {
116 void walk(
auto const& key,
auto&& func)
noexcept
120 return walk(cbegin(key), cend(key),
hi_forward(func));
128 void walk(
auto const& key,
auto&& func)
const noexcept
132 return walk(cbegin(key), cend(key),
hi_forward(func));
144 if (
auto element = find(path_first, path_last, func)) {
145 _walk(element, func);
158 if (
auto element = find(path_first, path_last, func)) {
159 _walk(element, func);
173 return walk_including_path(cbegin(path), cend(path),
hi_forward(func));
186 return walk_including_path(cbegin(path), cend(path),
hi_forward(func));
193 void walk(
auto&& func)
noexcept
202 void walk(
auto&& func)
const noexcept
222 [[nodiscard]]
constexpr node_type *find(
auto path_first,
auto path_last,
auto const& func)
noexcept
225 for (
auto path_it = path_first; path_it != path_last; ++path_it) {
228 if (
auto node_it = node->children.find(*path_it); node_it != node->children.end()) {
229 node = &node_it->second;
244 [[nodiscard]]
constexpr node_type
const *
find(
auto path_first,
auto path_last,
auto const& func)
const noexcept
247 for (
auto path_it = path_first; path_it != path_last; ++path_it) {
250 if (
auto node_it = node->children.find(*path_it); node_it != node->children.end()) {
259 [[nodiscard]]
constexpr node_type *find_or_create(
auto path_first,
auto path_last)
noexcept
262 for (
auto path_it = path_first; path_it != path_last; ++path_it) {
263 node = &node->children[*path_it];
273 constexpr void _walk(node_type *node,
auto const& func)
noexcept
276 for (
auto& child : node->children) {
277 _walk(&child.second, func);
286 constexpr void _walk(node_type
const *node,
auto const& func)
const noexcept
289 for (
auto& child : node->children) {
290 _walk(&child.second, func);
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:223
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
DOXYGEN BUG.
Definition algorithm.hpp:13
A tree container.
Definition tree.hpp:19
void walk(auto &&func) const noexcept
Walk the full tree.
Definition tree.hpp:202
value_type const & operator()(auto path_first, auto path_last) const noexcept
Find the node and return the value of the node.
Definition tree.hpp:53
void walk_including_path(auto const &path, auto &&func) const noexcept
Walk the tree starting at path, and also for each node along the path.
Definition tree.hpp:182
value_type & operator[](auto const &key) noexcept
Find or create the node and return the value of the node.
Definition tree.hpp:65
void walk_including_path(auto path_first, auto path_last, auto const &func) const noexcept
Walk the tree starting at path, and also for each node along the path.
Definition tree.hpp:156
value_type const & operator[](auto const &path) const noexcept
Find the node and return the value of the node.
Definition tree.hpp:78
void walk_including_path(auto const &path, auto &&func) noexcept
Walk the tree starting at path, and also for each node along the path.
Definition tree.hpp:169
void walk_including_path(auto path_first, auto path_last, auto const &func) noexcept
Walk the tree starting at path, and also for each node along the path.
Definition tree.hpp:142
value_type & operator()(auto path_first, auto path_last) noexcept
Find or create the node and return the value of the node.
Definition tree.hpp:38
void walk(auto &&func) noexcept
Walk the full tree.
Definition tree.hpp:193