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