21 #ifndef FST_PAIR_WEIGHT_H_ 22 #define FST_PAIR_WEIGHT_H_ 40 template <
class W1,
class W2>
48 PairWeight(W1 w1, W2 w2) : value1_(std::move(w1)), value2_(std::move(w2)) {}
51 static const PairWeight zero(W1::Zero(), W2::Zero());
56 static const PairWeight one(W1::One(), W2::One());
61 static const PairWeight no_weight(W1::NoWeight(), W2::NoWeight());
65 std::istream &
Read(std::istream &strm) {
67 return value2_.Read(strm);
70 std::ostream &
Write(std::ostream &strm)
const {
72 return value2_.Write(strm);
75 bool Member()
const {
return value1_.Member() && value2_.Member(); }
78 const auto h1 = value1_.Hash();
79 const auto h2 = value2_.Hash();
80 static constexpr
int lshift = 5;
81 static constexpr
int rshift = CHAR_BIT *
sizeof(size_t) - 5;
82 return h1 << lshift ^ h1 >> rshift ^ h2;
93 const W1 &
Value1()
const {
return value1_; }
95 const W2 &
Value2()
const {
return value2_; }
97 void SetValue1(
const W1 &weight) { value1_ = weight; }
99 void SetValue2(
const W2 &weight) { value2_ = weight; }
106 template <
class W1,
class W2>
112 template <
class W1,
class W2>
118 template <
class W1,
class W2>
125 template <
class W1,
class W2>
136 template <
class W1,
class W2>
153 template <
class W1,
class W2>
161 bool allow_zero =
true)
162 : generate1_(seed, allow_zero), generate2_(seed, allow_zero) {}
173 #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