1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
#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>::Pointer ptr;

    {

        Trie<double, Key>               trie;

        trie.insert("lbur"42);
        trie.insert("lbru"42);
        trie.insert("lxvz"123);
        trie.insert("foo",  111);
        trie.insert("le",   666);

        ptr = trie.descend();
    }

    std::cout << "Here" << std::endl;

    std::string key = "";

    do {
        if (ptr.defined()) {
            for (char ch: key) {
                std::cout << ch << ":" << std::endl;

                if (!ptr.descend(ch)) break;
                if (ptr.exists()) {
                    std::cout << "FOUND: " << *ptr << std::endl;
                }
            }
            std::cout << "continuation possible with: ";
            for (char ch: ptr) {
                std::cout << ch << ", ";
            }
            std::cout << std::endl;
        }
    } while (std::cin >> key);
}