• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef MARISA_GRIMOIRE_TRIE_TAIL_H_
2 #define MARISA_GRIMOIRE_TRIE_TAIL_H_
3 
4 #include "marisa/agent.h"
5 #include "marisa/grimoire/vector.h"
6 #include "marisa/grimoire/trie/entry.h"
7 
8 namespace marisa {
9 namespace grimoire {
10 namespace trie {
11 
12 class Tail {
13  public:
14   Tail();
15 
16   void build(Vector<Entry> &entries, Vector<UInt32> *offsets,
17       TailMode mode);
18 
19   void map(Mapper &mapper);
20   void read(Reader &reader);
21   void write(Writer &writer) const;
22 
23   void restore(Agent &agent, std::size_t offset) const;
24   bool match(Agent &agent, std::size_t offset) const;
25   bool prefix_match(Agent &agent, std::size_t offset) const;
26 
27   const char &operator[](std::size_t offset) const {
28     MARISA_DEBUG_IF(offset >= buf_.size(), MARISA_BOUND_ERROR);
29     return buf_[offset];
30   }
31 
mode()32   TailMode mode() const {
33     return end_flags_.empty() ? MARISA_TEXT_TAIL : MARISA_BINARY_TAIL;
34   }
35 
empty()36   bool empty() const {
37     return buf_.empty();
38   }
size()39   std::size_t size() const {
40     return buf_.size();
41   }
total_size()42   std::size_t total_size() const {
43     return buf_.total_size() + end_flags_.total_size();
44   }
io_size()45   std::size_t io_size() const {
46     return buf_.io_size() + end_flags_.io_size();
47   }
48 
49   void clear();
50   void swap(Tail &rhs);
51 
52  private:
53   Vector<char> buf_;
54   BitVector end_flags_;
55 
56   void build_(Vector<Entry> &entries, Vector<UInt32> *offsets,
57       TailMode mode);
58 
59   void map_(Mapper &mapper);
60   void read_(Reader &reader);
61   void write_(Writer &writer) const;
62 
63   // Disallows copy and assignment.
64   Tail(const Tail &);
65   Tail &operator=(const Tail &);
66 };
67 
68 }  // namespace trie
69 }  // namespace grimoire
70 }  // namespace marisa
71 
72 #endif  // MARISA_GRIMOIRE_TRIE_TAIL_H_
73