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