1 #ifndef MARISA_ALPHA_RANK_H_ 2 #define MARISA_ALPHA_RANK_H_ 3 4 #include "base.h" 5 6 namespace marisa_alpha { 7 8 class Rank { 9 public: Rank()10 Rank() : abs_(0), rel_lo_(0), rel_hi_(0) {} 11 set_abs(UInt32 value)12 void set_abs(UInt32 value) { 13 abs_ = value; 14 } set_rel1(UInt32 value)15 void set_rel1(UInt32 value) { 16 MARISA_ALPHA_DEBUG_IF(value > 64, MARISA_ALPHA_PARAM_ERROR); 17 rel_lo_ = (rel_lo_ & ~0x7FU) | (value & 0x7FU); 18 } set_rel2(UInt32 value)19 void set_rel2(UInt32 value) { 20 MARISA_ALPHA_DEBUG_IF(value > 128, MARISA_ALPHA_PARAM_ERROR); 21 rel_lo_ = (rel_lo_ & ~(0xFFU << 7)) | ((value & 0xFFU) << 7); 22 } set_rel3(UInt32 value)23 void set_rel3(UInt32 value) { 24 MARISA_ALPHA_DEBUG_IF(value > 192, MARISA_ALPHA_PARAM_ERROR); 25 rel_lo_ = (rel_lo_ & ~(0xFFU << 15)) | ((value & 0xFFU) << 15); 26 } set_rel4(UInt32 value)27 void set_rel4(UInt32 value) { 28 MARISA_ALPHA_DEBUG_IF(value > 256, MARISA_ALPHA_PARAM_ERROR); 29 rel_lo_ = (rel_lo_ & ~(0x1FFU << 23)) | ((value & 0x1FFU) << 23); 30 } set_rel5(UInt32 value)31 void set_rel5(UInt32 value) { 32 MARISA_ALPHA_DEBUG_IF(value > 320, MARISA_ALPHA_PARAM_ERROR); 33 rel_hi_ = (rel_hi_ & ~0x1FFU) | (value & 0x1FFU); 34 } set_rel6(UInt32 value)35 void set_rel6(UInt32 value) { 36 MARISA_ALPHA_DEBUG_IF(value > 384, MARISA_ALPHA_PARAM_ERROR); 37 rel_hi_ = (rel_hi_ & ~(0x1FFU << 9)) | ((value & 0x1FFU) << 9); 38 } set_rel7(UInt32 value)39 void set_rel7(UInt32 value) { 40 MARISA_ALPHA_DEBUG_IF(value > 448, MARISA_ALPHA_PARAM_ERROR); 41 rel_hi_ = (rel_hi_ & ~(0x1FFU << 18)) | ((value & 0x1FFU) << 18); 42 } 43 abs()44 UInt32 abs() const { 45 return abs_; 46 } rel1()47 UInt32 rel1() const { 48 return rel_lo_ & 0x7FU; 49 } rel2()50 UInt32 rel2() const { 51 return (rel_lo_ >> 7) & 0xFFU; 52 } rel3()53 UInt32 rel3() const { 54 return (rel_lo_ >> 15) & 0xFFU; 55 } rel4()56 UInt32 rel4() const { 57 return rel_lo_ >> 23; 58 } rel5()59 UInt32 rel5() const { 60 return rel_hi_ & 0x1FFU; 61 } rel6()62 UInt32 rel6() const { 63 return (rel_hi_ >> 9) & 0x1FFU; 64 } rel7()65 UInt32 rel7() const { 66 return (rel_hi_ >> 18) & 0x1FFU; 67 } 68 69 private: 70 UInt32 abs_; 71 UInt32 rel_lo_; 72 UInt32 rel_hi_; 73 }; 74 75 } // namespace marisa_alpha 76 77 #endif // MARISA_ALPHA_RANK_H_ 78