1 #ifndef MARISA_TRIE_H_
2 #define MARISA_TRIE_H_
3 
4 #include "marisa/keyset.h"
5 #include "marisa/agent.h"
6 
7 namespace marisa {
8 namespace grimoire {
9 namespace trie {
10 
11 class LoudsTrie;
12 
13 }  // namespace trie
14 }  // namespace grimoire
15 
16 class Trie {
17   friend class TrieIO;
18 
19  public:
20   Trie();
21   ~Trie();
22 
23   void build(Keyset &keyset, int config_flags = 0);
24 
25   void mmap(const char *filename);
26   void map(const void *ptr, std::size_t size);
27 
28   void load(const char *filename);
29   void read(int fd);
30 
31   void save(const char *filename) const;
32   void write(int fd) const;
33 
34   bool lookup(Agent &agent) const;
35   void reverse_lookup(Agent &agent) const;
36   bool common_prefix_search(Agent &agent) const;
37   bool predictive_search(Agent &agent) const;
38 
39   std::size_t num_tries() const;
40   std::size_t num_keys() const;
41   std::size_t num_nodes() const;
42 
43   TailMode tail_mode() const;
44   NodeOrder node_order() const;
45 
46   bool empty() const;
47   std::size_t size() const;
48   std::size_t total_size() const;
49   std::size_t io_size() const;
50 
51   void clear();
52   void swap(Trie &rhs);
53 
54  private:
55   scoped_ptr<grimoire::trie::LoudsTrie> trie_;
56 
57   // Disallows copy and assignment.
58   Trie(const Trie &);
59   Trie &operator=(const Trie &);
60 };
61 
62 }  // namespace marisa
63 
64 #endif  // MARISA_TRIE_H_
65