apache-datasketches-sys 0.2.2

Raw cxx bridge to Apache DataSketches C++ (do not use directly; see apache-datasketches)
Documentation
#include "hll_union_shim.h"
#include "hll.rs.h" // generated by cxx from src/hll.rs (Task 7); provides the full TargetHllType enum definition

namespace apache_datasketches_rs {

HllUnionShim::HllUnionShim(uint8_t lg_max_k) : u_(lg_max_k) {}

void HllUnionShim::update_sketch(const HllSketchShim& sketch) {
  u_.update(sketch.inner());
}
void HllUnionShim::update_u64(uint64_t value) { u_.update(value); }
void HllUnionShim::update_i64(int64_t value) { u_.update(value); }
void HllUnionShim::update_f64(double value) { u_.update(value); }
void HllUnionShim::update_str(rust::Str value) {
  // See HllSketchShim::update_str: no std::string copy, and the empty guard
  // has to be replicated here because it lives in the bypassed overload --
  // two hops down, in fact: hll_union::update(const std::string&) just
  // forwards to the gadget, and the guard is on hll_sketch's overload.
  if (value.empty()) return;
  u_.update(value.data(), value.size());
}
void HllUnionShim::update_bytes(rust::Slice<const uint8_t> value) {
  u_.update(value.data(), value.size());
}

std::unique_ptr<HllSketchShim> HllUnionShim::get_result(TargetHllType tgt_type) const {
  return std::make_unique<HllSketchShim>(u_.get_result(to_cpp_target_type(tgt_type)));
}

// Returned as a heap std::vector rather than a rust::Vec built by hand.
// rust::Vec::push_back goes through emplace_back, which makes two
// non-inlinable extern "C" calls back into Rust per element; over a
// serialized buffer that is two boundary crossings per byte, and it dominated
// everything else the call does. A unique_ptr hands the buffer over whole and
// leaves the Rust side one memcpy to do.
std::unique_ptr<std::vector<uint8_t>> HllUnionShim::serialize_compact(TargetHllType tgt_type) const {
  return std::make_unique<std::vector<uint8_t>>(
      u_.get_result(to_cpp_target_type(tgt_type)).serialize_compact());
}

std::unique_ptr<std::vector<uint8_t>> HllUnionShim::serialize_updatable(TargetHllType tgt_type) const {
  return std::make_unique<std::vector<uint8_t>>(
      u_.get_result(to_cpp_target_type(tgt_type)).serialize_updatable());
}

double HllUnionShim::get_estimate() const { return u_.get_estimate(); }
double HllUnionShim::get_lower_bound(uint8_t num_std_dev) const {
  return u_.get_lower_bound(num_std_dev);
}
double HllUnionShim::get_upper_bound(uint8_t num_std_dev) const {
  return u_.get_upper_bound(num_std_dev);
}
bool HllUnionShim::is_empty() const { return u_.is_empty(); }
void HllUnionShim::reset() { u_.reset(); }

std::unique_ptr<HllUnionShim> new_hll_union(uint8_t lg_max_k) {
  return std::make_unique<HllUnionShim>(lg_max_k);
}

} // namespace apache_datasketches_rs