54 std::cout <<
"[1] Insert/find/erase walkthrough\n";
58 word_count.
insert(
"apple", 3);
59 word_count.
insert(
"app", 1);
60 word_count.
insert(
"application", 7);
62 std::cout <<
"apple: " << *word_count.
find(
"apple") <<
" (expect 3)\n";
63 std::cout <<
"contains 'appl': " << std::boolalpha
64 << word_count.
contains(
"appl") <<
" (expect false)\n";
67 std::cout <<
"app after insert_or_assign: " << *word_count.
find(
"app")
70 word_count.
erase(
"application");
71 std::cout <<
"contains 'application' after erase: "
72 << word_count.
contains(
"application") <<
" (expect false)\n";
73 std::cout <<
"still contains 'app': " << word_count.
contains(
"app")
74 <<
" (expect true)\n\n";
79 std::cout <<
"[2] Prefix autocomplete (keys_with_prefix)\n";
83 for (
const auto &
word :
84 {
"cat",
"car",
"cart",
"carbon",
"care",
"dog",
"door"})
93 std::cout <<
"Words starting with \"car\": ";
95 std::cout <<
w <<
" ";
101 std::cout <<
"[3] Longest-prefix match (e.g. hierarchical route lookup)\n";
107 routes.insert(
"/api/users",
"users-handler");
108 routes.insert(
"/api/users/admin",
"admin-handler");
110 for (
const auto & path :
111 {
"/api/users/admin/settings",
"/api/users/42",
"/api/health"})
115 std::cout << path <<
" -> " << *
routes.find(*
matched) <<
" (matched \""
118 std::cout << path <<
" -> no route matched\n";
126 std::cout <<
"\n=== Aleph::RadixTree: compressed prefix tree ===\n\n";
132 std::cout <<
"Done.\n";
Compressed prefix tree mapping std::basic_string<Char> keys to values of type T.
const T * find(const Key &key) const noexcept
Look up key.
bool insert(const Key &key, const T &value)
Insert key with a copy of value, only if key is absent.
void insert_or_assign(const Key &key, T value)
Insert key with value, or overwrite the existing value if key is already present.
bool contains(const Key &key) const noexcept
Check whether key is present.
bool erase(const Key &key)
Remove key if present, merging any resulting single-child, valueless node back into a compressed edge...
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
void print_rule()
Prints a horizontal rule for example output separation.
Compressed prefix tree (Aleph::RadixTree) mapping string keys to values.