117 explicit Cnode(
const char c)
noexcept
168 if (
child ==
nullptr)
170 return child->get_key() ==
'$';
194 if (
child->get_key() == c)
211 if (
child->get_key() > c)
224 [[
nodiscard]] std::tuple<const Cnode *, const char *>
230 return std::make_tuple(
this,
"");
234 return std::make_tuple(
this,
prefix);
287 const std::string &
prefix,
293 if (*remaining !=
'\0')
301 for (
size_t i = 0; i + 1 <
prefix.size(); ++i)
304 node->words_impl(stack,
ret_val);
344 if (
pp->is_end_word())
351 auto *parent =
const_cast<Cnode *
>(
pp);
352 for (
const char *ptr =
rem; *ptr; ++ptr)
376 const char *ptr = &stack.
base();
377 const char *
last = &stack.
top();
427 std::cout <<
w <<
'\n';
Exception handling system with formatted messages for Aleph-w.
Prefix tree (Trie) node for storing character sequences.
Cnode(const char c) noexcept
Construct a node with the given character.
static std::string extract_word_from_stack(FixedStack< char > &stack)
size_t count() const noexcept
Count total words stored in this subtree.
static void clone(const Tree_Node< char > *src, Tree_Node< char > *tgt)
Clone helper - copies children from src to tgt.
Cnode * clone() const
Create a deep copy of this subtree.
bool contains(const std::string &word) const noexcept
Check if a word exists in the tree.
void destroy() noexcept
Destroy all children of this node.
void words_impl(FixedStack< char > &stack, DynArray< std::string > &l) const
std::string to_str() const
Convert the subtree to a string representation.
std::tuple< const Cnode *, const char * > search_prefix(const char *prefix) const noexcept
Search for a prefix in the tree.
const Cnode * search_word(const char *word) const noexcept
Search for a complete word in the tree.
void mark_end_word()
Mark this node as the end of a word.
void print_words(const size_t max_word_length=2048) const
Print all words to stdout.
bool is_end_word() const noexcept
Check if this node marks the end of a word.
Cnode * insert_child(Cnode *child)
Insert a child node in sorted order.
char symbol() const noexcept
Return the character stored in this node.
bool insert_word(const std::string &word)
Insert a word into the tree.
Cnode * search_child(const char c) const noexcept
Search for a child with the given character.
Cnode * greater_child(const char c) const noexcept
Find the first child with a character greater than c.
DynArray< std::string > words(size_t max_word_length=2048) const
Get all words stored in this subtree.
DynArray< std::string > words_with_prefix(const std::string &prefix, const size_t max_word_length=2048) const
Get all words starting with a given prefix.
DynList< Cnode * > children() const
Return a list of all child nodes.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
T & push(const T &data) noexcept
Push a copy of data
size_t size() const noexcept
Return the number of elements stored in the stack.
T & base() const noexcept
Return the internal array base.
T & top() const noexcept
Return a modifiable referemce to stack's top.
T pop() noexcept
Pop by moving the top of stack.
Container< __Type > maps(Operation &operation) const
Transform elements using a mapping function.
const Type * last() const
Get the last element.
Tree_Node * get_left_child() const noexcept
Returns the leftmost child of this.
void insert_leftmost_child(Tree_Node *p) noexcept
Inserts p as the leftmost child of this.
void insert_rightmost_child(Tree_Node *p) noexcept
Inserts p as the rightmost child of this.
void for_each_child(Operation &op) const
Visits each child of this and executes the operation on the child node.
char & get_key() noexcept
Returns a modifiable reference to the node contents.
void destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
Main namespace for Aleph-w library functions.
static void prefix(Node *root, DynList< Node * > &acc)
Stack implementations backed by dynamic or fixed arrays.
Lazy and scalable dynamic array implementation.
Alias for htlist.H (DynList implementation).
General tree (n-ary tree) node.