68 const T&
value()
const
108 template <
typename T>
121 template <
typename Vect>
122 const TreeNode<T>*
find(
const Vect& concatenated_values,
bool partial_allowed =
false);
125 const TreeNode<T>*
croot()
const
136 friend std::ostream&
operator<<(std::ostream& os,
const Tree& _this)
138 _this.print_impl(os, _this.croot(), 0);
142 template <
class Functor>
143 void visit(Functor& func,
const TreeNode<T>* node)
const
146 for (
auto child : node->children())
153 void print_impl(std::ostream& os,
const TreeNode<T>* node,
int indent)
const;
155 std::unique_ptr<TreeNode<T>>
_root;
160 template <
typename T>
172 array[index++] = head;
174 while (!head || head != tail)
176 head = head->parent();
177 array[index++] = head;
179 array[index] =
nullptr;
186 os << array[index]->value();
195 template <
typename T>
199 for (
int i = 0; i < indent; i++)
201 os << node->value() << std::endl;
203 for (
const auto& child : node->children())
205 print_impl(os, &child, indent + 3);
209 template <
typename T>
214 template <
typename T>
215 inline TreeNode<T>* TreeNode<T>::addChild(
const T& value)
217 assert(_children.capacity() > _children.size());
218 _children.emplace_back(
this);
219 _children.back().setValue(value);
220 return &_children.back();
223 template <
typename T>
224 template <
typename Vect>
226 bool partial_allowed)
230 for (
const auto& value : concatenated_values)
233 for (
auto& child : (node->children()))
235 if (child.value() == value)
246 if (partial_allowed || node->children().empty())
257 #endif // STRINGTREE_H