1#ifndef MARISA_ALPHA_RANGE_H_
2#define MARISA_ALPHA_RANGE_H_
3
4#include "base.h"
5
6namespace marisa_alpha {
7
8class Range {
9 public:
10  Range() : begin_(0), end_(0), pos_(0) {}
11  Range(UInt32 begin, UInt32 end, UInt32 pos)
12      : begin_(begin), end_(end), pos_(pos) {}
13
14  void set_begin(UInt32 begin) {
15    begin_ = begin;
16  }
17  void set_end(UInt32 end) {
18    end_ = end;
19  }
20  void set_pos(UInt32 pos) {
21    pos_ = pos;
22  }
23
24  UInt32 begin() const {
25    return begin_;
26  }
27  UInt32 end() const {
28    return end_;
29  }
30  UInt32 pos() const {
31    return pos_;
32  }
33
34 private:
35  UInt32 begin_;
36  UInt32 end_;
37  UInt32 pos_;
38};
39
40class WRange {
41 public:
42  WRange() : range_(), weight_(0.0) {}
43  WRange(const Range &range, double weight)
44      : range_(range), weight_(weight) {}
45  WRange(UInt32 begin, UInt32 end, UInt32 pos, double weight)
46      : range_(begin, end, pos), weight_(weight) {}
47
48  void set_begin(UInt32 begin) {
49    range_.set_begin(begin);
50  }
51  void set_end(UInt32 end) {
52    range_.set_end(end);
53  }
54  void set_pos(UInt32 pos) {
55    range_.set_pos(pos);
56  }
57  void set_weight(double weight) {
58    weight_ = weight;
59  }
60
61  const Range &range() const {
62    return range_;
63  }
64  UInt32 begin() const {
65    return range_.begin();
66  }
67  UInt32 end() const {
68    return range_.end();
69  }
70  UInt32 pos() const {
71    return range_.pos();
72  }
73  double weight() const {
74    return weight_;
75  }
76
77 private:
78  Range range_;
79  double weight_;
80};
81
82inline bool operator>(const WRange &lhs, const WRange &rhs) {
83  return lhs.weight() > rhs.weight();
84}
85
86}  // namespace marisa_alpha
87
88#endif  // MARISA_ALPHA_RANGE_H_
89