sclass WithProbability extends Var implements Comparable> {
double probability; // assumed between 0 and 1
*() {}
*(A a) { this(1, a); }
*(double *probability, A a) { super(a); }
toString {
ret "p=" + renderedProbability() + ": " + str(get());
}
S renderedProbability() {
ret formatDouble_noLeadingZero(probability, 2);
}
double probability() { ret probability; }
public int hashCode() {
ret boostHashCombine(main hashCode(probability), main hashCode(get()));
}
public bool equals(O o) {
if (o cast WithProbability) {
ret probability == o.probability && eq(get(), o!);
}
false;
}
// Higher probability comes first!
public int compareTo(WithProbability wp) {
ret wp == null ? 1
: cmp(wp.probability, probability);
}
}