This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git

commit cf01240757ec719ab5c087a619157fd8b54600c7
Merge: f3df34da 43e27ba2
Author: Lee Rhodes <[email protected]>
AuthorDate: Sun Nov 15 10:07:18 2026 -0800

    Merge pull request #558 from rustyconover/feat/kll-lazy-items
    
    perf: kll_sketch allocates its items on first use

 kll/include/kll_sketch.hpp               |  32 ++++-
 kll/include/kll_sketch_impl.hpp          |  45 ++++--
 kll/test/CMakeLists.txt                  |   1 +
 kll/test/kll_sketch_allocation_test.cpp  | 230 +++++++++++++++++++++++++++++++
 kll/test/kll_sketch_custom_type_test.cpp | 105 ++++++++++++++
 kll/test/kll_sketch_test.cpp             |   4 +
 6 files changed, 405 insertions(+), 12 deletions(-)

diff --cc kll/include/kll_sketch_impl.hpp
index 65a4c95d,acd6f0df..6a7cdcbf
--- a/kll/include/kll_sketch_impl.hpp
+++ b/kll/include/kll_sketch_impl.hpp
@@@ -180,16 -179,10 +179,17 @@@ template<typename T, typename C, typena
  template<typename FwdT>
  void kll_sketch<T, C, A>::update(FwdT&& item) {
    if (!check_update_item(item)) { return; }
+   allocate_items(); // first, so that a failure leaves the sketch unchanged
    update_min_max(static_cast<const T&>(item)); // min and max are always 
copies
 -  const uint32_t index = internal_update();
 -  new (&items_[index]) T(std::forward<FwdT>(item));
 +  if (levels_[0] == 0) {
 +    // item can refer into items_, and internal_update() can destroy it
 +    T copy(std::forward<FwdT>(item));
 +    const uint32_t index = internal_update();
 +    new (&items_[index]) T(std::move(copy));
 +  } else {
 +    const uint32_t index = internal_update();
 +    new (&items_[index]) T(std::forward<FwdT>(item));
 +  }
    reset_sorted_view();
  }
  
diff --cc kll/test/CMakeLists.txt
index 6fb7e715,72b57e62..165456e2
--- a/kll/test/CMakeLists.txt
+++ b/kll/test/CMakeLists.txt
@@@ -39,9 -39,9 +39,10 @@@ target_sources(kll_tes
    PRIVATE
      kll_sketch_test.cpp
      kll_sketch_custom_type_test.cpp
+     kll_sketch_allocation_test.cpp
      kll_sketch_validation.cpp
      kolmogorov_smirnov_test.cpp
 +    kll_sketch_merge_failure_test.cpp
  )
  
  if (SERDE_COMPAT)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to