51#include <gtest/gtest.h>
136 auto * child =
new Cnode(
'a');
137 root->insert_child(child);
258 root->insert_word(
"hello");
266 root->insert_word(
"hello");
268 auto result =
root->search_word(
"hello");
275 root->insert_word(
"hello");
288 auto [node, remaining] =
root->search_prefix(
"");
296 root->insert_word(
"hello");
298 auto [node, remaining] =
root->search_prefix(
"hel");
306 root->insert_word(
"hello");
308 auto [node, remaining] =
root->search_prefix(
"helping");
316 root->insert_word(
"hello");
318 auto [node, remaining] =
root->search_prefix(
"world");
330 auto words =
root->words();
336 root->insert_word(
"hello");
338 auto words =
root->words();
340 EXPECT_EQ(std::string(words[0]),
"hello");
345 root->insert_word(
"hello");
346 root->insert_word(
"help");
347 root->insert_word(
"world");
349 auto words =
root->words();
353 std::vector<std::string> v;
354 words.for_each([&v](
const std::string&
w) { v.push_back(
w); });
355 std::sort(v.begin(), v.end());
364 root->insert_word(
"a");
365 root->insert_word(
"ab");
366 root->insert_word(
"abc");
367 root->insert_word(
"abcd");
369 auto words =
root->words();
390 root->insert_word(
"hello");
391 root->insert_word(
"help");
392 root->insert_word(
"world");
402 root->insert_word(
"test");
416 std::string str =
root->to_str();
423 root->insert_word(
"ab");
424 std::string str =
root->to_str();
427 EXPECT_NE(str.find(
'a'), std::string::npos);
428 EXPECT_NE(str.find(
'b'), std::string::npos);
445 for (
int i = 0; i <
N; ++i)
446 root->insert_word(
"w" + std::to_string(i));
448 for (
int i = 0; i <
N; ++i)
451 auto words =
root->words();
487 root->insert_word(
"hello");
493 root->insert_word(
"hello");
494 root->insert_word(
"help");
495 root->insert_word(
"world");
501 root->insert_word(
"a");
502 root->insert_word(
"ab");
503 root->insert_word(
"abc");
513 root->insert_word(
"hello");
514 auto words =
root->words_with_prefix(
"xyz");
520 root->insert_word(
"hello");
521 root->insert_word(
"help");
522 root->insert_word(
"helicopter");
523 root->insert_word(
"world");
525 auto words =
root->words_with_prefix(
"hel");
531 root->insert_word(
"test");
532 root->insert_word(
"testing");
533 root->insert_word(
"tester");
535 const auto words =
root->words_with_prefix(
"test");
541 root->insert_word(
"apple");
542 root->insert_word(
"application");
544 auto words =
root->words_with_prefix(
"ban");
551 auto * tree =
new Cnode(
'\0');
552 tree->insert_word(
"hi");
553 tree->insert_word(
"bye");
570 ::testing::InitGoogleTest(&
argc,
argv);
Prefix tree (Trie) node for storing character sequences.
void destroy() noexcept
Destroy all children of this node.
void mark_end_word()
Mark this node as the end of a word.
bool is_end_word() const noexcept
Check if this node marks the end of a word.
char symbol() const noexcept
Return the character stored in this node.
DynList< Cnode * > children() const
Return a list of all child nodes.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Trie (prefix tree) implementation.
TEST_F(PrefixTreeTest, NodeConstruction)