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

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

commit 7104dc450c85834a6fc8c9ecc9332c2cfc3aa0f1
Author: Rusty Conover <[email protected]>
AuthorDate: Wed Oct 28 10:52:44 2026 -0400

    fix: ebpps_sketch::merge(const&) called an unqualified swap (#557)
    
    (cherry picked from commit 7a08fe4080d45a34dd90e1886ae2eb57b258f25a, the 
merge of #557)
---
 sampling/include/ebpps_sketch_impl.hpp  |  2 +-
 sampling/test/ebpps_allocation_test.cpp | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/sampling/include/ebpps_sketch_impl.hpp 
b/sampling/include/ebpps_sketch_impl.hpp
index 299b7f5c..36a7b926 100644
--- a/sampling/include/ebpps_sketch_impl.hpp
+++ b/sampling/include/ebpps_sketch_impl.hpp
@@ -202,7 +202,7 @@ void ebpps_sketch<T, A>::merge(const ebpps_sketch<T, A>& 
sk) {
     // need to swap this with sk to merge, so make a copy, swap,
     // and use that to merge
     ebpps_sketch sk_copy(sk);
-    swap(*this, sk_copy);
+    std::swap(*this, sk_copy);
     internal_merge(sk_copy);
   } else {
     internal_merge(sk);
diff --git a/sampling/test/ebpps_allocation_test.cpp 
b/sampling/test/ebpps_allocation_test.cpp
index e249ac1f..59294997 100644
--- a/sampling/test/ebpps_allocation_test.cpp
+++ b/sampling/test/ebpps_allocation_test.cpp
@@ -25,6 +25,26 @@
 
 #include <sstream>
 
+// An allocator outside the datasketches namespace, as an application's would 
be: argument-dependent
+// lookup finds no swap() in its namespace.
+namespace ebpps_test_alloc {
+
+template<typename T>
+struct plain_allocator {
+  using value_type = T;
+  plain_allocator() = default;
+  template<typename U>
+  plain_allocator(const plain_allocator<U>&) {}
+  T* allocate(std::size_t n) { return static_cast<T*>(::operator new(n * 
sizeof(T))); }
+  void deallocate(T* p, std::size_t) { ::operator delete(p); }
+};
+template<typename T, typename U>
+bool operator==(const plain_allocator<T>&, const plain_allocator<U>&) { return 
true; }
+template<typename T, typename U>
+bool operator!=(const plain_allocator<T>&, const plain_allocator<U>&) { return 
false; }
+
+} // namespace ebpps_test_alloc
+
 namespace datasketches {
 
 using ebpps_test_sketch = ebpps_sketch<test_type, test_allocator<test_type>>;
@@ -93,4 +113,17 @@ TEST_CASE( "ebpps merge", "[ebpps_sketch][test_type]") {
   REQUIRE(test_allocator_net_allocations == 0);
 }
 
+TEST_CASE("ebpps merge heavier sketch by const reference with an application 
allocator", "[ebpps_sketch]") {
+  using sketch = ebpps_sketch<int, ebpps_test_alloc::plain_allocator<int>>;
+  sketch light(5);
+  sketch heavy(5);
+  for (int i = 0; i < 10; ++i) light.update(i);
+  for (int i = 0; i < 100; ++i) heavy.update(i, 2.0);
+  const sketch& heavy_ref = heavy;
+  light.merge(heavy_ref);
+  REQUIRE(light.get_n() == 110);
+  REQUIRE(light.get_cumulative_weight() == Approx(210.0));
+  REQUIRE(heavy.get_n() == 100);
 }
+
+} // namespace datasketches


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

Reply via email to