1 #ifndef MARISA_ALPHA_KEY_H_ 2 #define MARISA_ALPHA_KEY_H_ 3 4 #include "marisa-string.h" 5 6 namespace marisa_alpha { 7 8 template <typename T> 9 class Key { 10 public: Key()11 Key() : str_(), weight_(0.0), id_(0), terminal_(0) {} 12 set_str(const T & str)13 void set_str(const T &str) { 14 str_ = str; 15 } set_weight(double weight)16 void set_weight(double weight) { 17 weight_ = weight; 18 } set_id(UInt32 id)19 void set_id(UInt32 id) { 20 id_ = id; 21 } set_terminal(UInt32 terminal)22 void set_terminal(UInt32 terminal) { 23 terminal_ = terminal; 24 } 25 str()26 const T &str() const { 27 return str_; 28 } weight()29 double weight() const { 30 return weight_; 31 } id()32 UInt32 id() const { 33 return id_; 34 } terminal()35 UInt32 terminal() const { 36 return terminal_; 37 } 38 39 private: 40 T str_; 41 double weight_; 42 UInt32 id_; 43 UInt32 terminal_; 44 }; 45 46 template <typename T> 47 inline bool operator<(const Key<T> &lhs, const T &rhs) { 48 return lhs.str() < rhs; 49 } 50 51 template <typename T> 52 inline bool operator<(const T &lhs, const Key<T> &rhs) { 53 return lhs < rhs.str(); 54 } 55 56 template <typename T> 57 inline bool operator<(const Key<T> &lhs, const Key<T> &rhs) { 58 return lhs.str() < rhs.str(); 59 } 60 61 template <typename T> 62 inline bool operator==(const Key<T> &lhs, const Key<T> &rhs) { 63 return lhs.str() == rhs.str(); 64 } 65 66 } // namespace marisa_alpha 67 68 #endif // MARISA_ALPHA_KEY_H_ 69