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