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