#include <iostream>
#include "trie.hpp" struct Key { static constexpr size_t size() { return ('Z' - 'A' + 1); } static constexpr size_t map(char c) { assert(c>='a' && c<='z' || c>='A' && c<='Z'); if (c>='a' && c<='z') { c = c - 'a' + 'A'; } return c - 'A'; } static constexpr char unmap(size_t key) { assert(key<size()); return 'a' + key; } }; int main() { Trie<double, Key> trie; trie.insert("lbur", 42); trie.insert("lbru", 42); trie.insert("lxvz", 123); trie.insert("le", 666); std::string key = "lbru"; Trie<double, Key>::Pointer ptr = trie.descend(); if (ptr.defined()) { for (char ch: key) { if (!ptr.descend(ch)) break; if (ptr.exists()) { std::cout << *ptr << std::endl; } } std::cout << "continuation possible with: "; /* for (char ch: ptr) { std::cout << ch << ", "; } */ for (auto it = ptr.begin(); it != ptr.end(); ++it) { std::cout << *it << ", "; } std::cout << std::endl; } } |