21 #ifndef FST_PAIR_WEIGHT_H_ 22 #define FST_PAIR_WEIGHT_H_ 38 template <
class W1,
class W2>
46 PairWeight(W1 w1, W2 w2) : value1_(std::move(w1)), value2_(std::move(w2)) {}
49 static const PairWeight zero(W1::Zero(), W2::Zero());
54 static const PairWeight one(W1::One(), W2::One());
59 static const PairWeight no_weight(W1::NoWeight(), W2::NoWeight());
63 std::istream &
Read(std::istream &strm) {
65 return value2_.Read(strm);
68 std::ostream &
Write(std::ostream &strm)
const {
70 return value2_.Write(strm);
73 bool Member()
const {
return value1_.Member() && value2_.Member(); }
76 const auto h1 = value1_.Hash();
77 const auto h2 = value2_.Hash();
78 static constexpr
int lshift = 5;
79 static constexpr
int rshift = CHAR_BIT *
sizeof(size_t) - 5;
80 return h1 << lshift ^ h1 >> rshift ^ h2;
91 const W1 &
Value1()
const {
return value1_; }
93 const W2 &
Value2()
const {
return value2_; }
95 void SetValue1(
const W1 &weight) { value1_ = weight; }
97 void SetValue2(
const W2 &weight) { value2_ = weight; }
104 template <
class W1,
class W2>
110 template <
class W1,
class W2>
116 template <
class W1,
class W2>
123 template <
class W1,
class W2>
134 template <
class W1,
class W2>
151 template <
class W1,
class W2>
159 bool allow_zero =
true)
160 : generate1_(seed, allow_zero), generate2_(seed, allow_zero) {}
171 #endif // FST_PAIR_WEIGHT_H_ static const PairWeight< W1, W2 > & NoWeight()
ReverseWeight Reverse() const
static const PairWeight< W1, W2 > & One()
const W2 & Value2() const
PairWeight< typename W1::ReverseWeight, typename W2::ReverseWeight > ReverseWeight
void SetValue2(const W2 &weight)
static const PairWeight< W1, W2 > & Zero()
std::ostream & Write(std::ostream &strm) const
std::istream & operator>>(std::istream &strm, FloatWeightTpl< T > &w)
bool operator!=(const ErrorWeight &, const ErrorWeight &)
std::ostream & operator<<(std::ostream &strm, const ErrorWeight &)
WeightGenerate(uint64_t seed=std::random_device()(), bool allow_zero=true)
Weight operator()() const
bool ReadElement(T *comp, bool last=false)
PairWeight< W1, W2 > Quantize(float delta=kDelta) const
bool operator==(const ErrorWeight &, const ErrorWeight &)
std::istream & Read(std::istream &strm)
void WriteElement(const T &comp)
void SetValue1(const W1 &weight)
bool ApproxEqual(const ErrorWeight &, const ErrorWeight &, float)
const W1 & Value1() const