aboutsummaryrefslogtreecommitdiff
path: root/v0_1_5/lib/marisa_alpha/key.h~
blob: 51d1601bf9c6287607303a497542db2a0be08d4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef MARISA_ALPHA_KEY_H_
#define MARISA_ALPHA_KEY_H_

#include "string.h"

namespace marisa_alpha {

template <typename T>
class Key {
 public:
  Key() : str_(), weight_(0.0), id_(0), terminal_(0) {}

  void set_str(const T &str) {
    str_ = str;
  }
  void set_weight(double weight) {
    weight_ = weight;
  }
  void set_id(UInt32 id) {
    id_ = id;
  }
  void set_terminal(UInt32 terminal) {
    terminal_ = terminal;
  }

  const T &str() const {
    return str_;
  }
  double weight() const {
    return weight_;
  }
  UInt32 id() const {
    return id_;
  }
  UInt32 terminal() const {
    return terminal_;
  }

 private:
  T str_;
  double weight_;
  UInt32 id_;
  UInt32 terminal_;
};

template <typename T>
inline bool operator<(const Key<T> &lhs, const T &rhs) {
  return lhs.str() < rhs;
}

template <typename T>
inline bool operator<(const T &lhs, const Key<T> &rhs) {
  return lhs < rhs.str();
}

template <typename T>
inline bool operator<(const Key<T> &lhs, const Key<T> &rhs) {
  return lhs.str() < rhs.str();
}

template <typename T>
inline bool operator==(const Key<T> &lhs, const Key<T> &rhs) {
  return lhs.str() == rhs.str();
}

}  // namespace marisa_alpha

#endif  // MARISA_ALPHA_KEY_H_