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