in sampling/include/var_opt_sketch_impl.hpp [774:810]
void var_opt_sketch<T, A>::update(O&& item, double weight, bool mark) {
if (weight < 0.0 || std::isnan(weight) || std::isinf(weight)) {
throw std::invalid_argument("Item weights must be nonnegative and finite. Found: "
+ std::to_string(weight));
} else if (weight == 0.0) {
return;
}
++n_;
if (r_ == 0) {
// exact mode
update_warmup_phase(std::forward<O>(item), weight, mark);
} else {
// sketch is in estimation mode so we can make the following check,
// although very conservative to check every time
if ((h_ != 0) && (peek_min() < get_tau()))
throw std::logic_error("sketch not in valid estimation mode");
// what tau would be if deletion candidates turn out to be R plus the new item
// note: (r_ + 1) - 1 is intentional
const double hypothetical_tau = (weight + total_wt_r_) / ((r_ + 1) - 1);
// is new item's turn to be considered for reservoir?
const double condition1 = (h_ == 0) || (weight <= peek_min());
// is new item light enough for reservoir?
const double condition2 = weight < hypothetical_tau;
if (condition1 && condition2) {
update_light(std::forward<O>(item), weight, mark);
} else if (r_ == 1) {
update_heavy_r_eq1(std::forward<O>(item), weight, mark);
} else {
update_heavy_general(std::forward<O>(item), weight, mark);
}
}
}