You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2020/06/23 00:40:07 UTC

[incubator-datasketches-cpp] branch tuple_sketch updated (eed2eb9 -> ee3d2e2)

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

alsay pushed a change to branch tuple_sketch
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git.


    from eed2eb9  fixed initial size
     new d5261a6  fixed sequence of operations
     new ee3d2e2  test allocations

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 common/test/test_allocator.cpp              |  4 ++
 common/test/test_allocator.hpp              |  3 ++
 tuple/include/tuple_sketch_impl.hpp         |  7 +++-
 tuple/test/CMakeLists.txt                   |  1 +
 tuple/test/tuple_sketch_allocation_test.cpp | 61 +++++++++++++++++++++++++++++
 5 files changed, 74 insertions(+), 2 deletions(-)
 create mode 100644 tuple/test/tuple_sketch_allocation_test.cpp


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org


[incubator-datasketches-cpp] 01/02: fixed sequence of operations

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d5261a6c076bd2899a5afdb3c93df184a73effb2
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Jun 22 17:38:58 2020 -0700

    fixed sequence of operations
---
 tuple/include/tuple_sketch_impl.hpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tuple/include/tuple_sketch_impl.hpp b/tuple/include/tuple_sketch_impl.hpp
index c6bb323..14dfa5c 100644
--- a/tuple/include/tuple_sketch_impl.hpp
+++ b/tuple/include/tuple_sketch_impl.hpp
@@ -106,9 +106,12 @@ void update_tuple_sketch<S, U, P, SD, A>::update(const void* key, size_t length,
   if (hash >= map_.theta_ || hash == 0) return; // hash == 0 is reserved to mark empty slots in the table
   auto result = map_.find(hash);
   if (!result.second) {
-    map_.insert(result.first, Entry(hash, policy_.create()));
+    S summary = policy_.create();
+    policy_.update(summary, std::forward<UU>(value));
+    map_.insert(result.first, Entry(hash, std::move(summary)));
+  } else {
+    policy_.update((*result.first).second, std::forward<UU>(value));
   }
-  policy_.update((*result.first).second, std::forward<UU>(value));
 }
 
 template<typename S, typename U, typename P, typename SD, typename A>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org


[incubator-datasketches-cpp] 02/02: test allocations

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ee3d2e20af647f169544e6e84c87773594ebd918
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Jun 22 17:39:54 2020 -0700

    test allocations
---
 common/test/test_allocator.cpp              |  4 ++
 common/test/test_allocator.hpp              |  3 ++
 tuple/test/CMakeLists.txt                   |  1 +
 tuple/test/tuple_sketch_allocation_test.cpp | 61 +++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+)

diff --git a/common/test/test_allocator.cpp b/common/test/test_allocator.cpp
index 02c5654..47389ff 100644
--- a/common/test/test_allocator.cpp
+++ b/common/test/test_allocator.cpp
@@ -24,4 +24,8 @@ namespace datasketches {
 // global variable to keep track of allocated size
 long long test_allocator_total_bytes = 0;
 
+// global variable to keep track of net allocations
+// (number of allocations minus number of deallocations)
+long long test_allocator_net_allocations = 0;
+
 } /* namespace datasketches */
diff --git a/common/test/test_allocator.hpp b/common/test/test_allocator.hpp
index 41dacfd..8b5481b 100644
--- a/common/test/test_allocator.hpp
+++ b/common/test/test_allocator.hpp
@@ -28,6 +28,7 @@
 namespace datasketches {
 
 extern long long test_allocator_total_bytes;
+extern long long test_allocator_net_allocations;
 
 template <class T> class test_allocator {
 public:
@@ -57,12 +58,14 @@ public:
     void* p = new char[n * sizeof(value_type)];
     if (!p) throw std::bad_alloc();
     test_allocator_total_bytes += n * sizeof(value_type);
+    ++test_allocator_net_allocations;
     return static_cast<pointer>(p);
   }
 
   void deallocate(pointer p, size_type n) {
     if (p) delete[] (char*) p;
     test_allocator_total_bytes -= n * sizeof(value_type);
+    --test_allocator_net_allocations;
   }
 
   size_type max_size() const {
diff --git a/tuple/test/CMakeLists.txt b/tuple/test/CMakeLists.txt
index 29f9c75..9c6a3a3 100644
--- a/tuple/test/CMakeLists.txt
+++ b/tuple/test/CMakeLists.txt
@@ -39,6 +39,7 @@ add_test(
 target_sources(tuple_test
   PRIVATE
     tuple_sketch_test.cpp
+    tuple_sketch_allocation_test.cpp
     tuple_union_test.cpp
     theta_sketch_experimental_test.cpp
     theta_union_experimental_test.cpp
diff --git a/tuple/test/tuple_sketch_allocation_test.cpp b/tuple/test/tuple_sketch_allocation_test.cpp
new file mode 100644
index 0000000..b9f969d
--- /dev/null
+++ b/tuple/test/tuple_sketch_allocation_test.cpp
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <iostream>
+
+#include <catch.hpp>
+#include <tuple_sketch.hpp>
+#include <test_allocator.hpp>
+
+namespace datasketches {
+
+using update_tuple_sketch_int_alloc =
+    update_tuple_sketch<int, int, default_update_policy<int, int>, serde<int>, test_allocator<int>>;
+
+TEST_CASE("tuple sketch with test allocator: exact mode", "[tuple_sketch]") {
+  test_allocator_total_bytes = 0;
+  test_allocator_net_allocations = 0;
+  {
+    auto update_sketch = update_tuple_sketch_int_alloc::builder().build();
+    for (int i = 0; i < 10000; ++i) update_sketch.update(i, 1);
+    for (int i = 0; i < 10000; ++i) update_sketch.update(i, 1);
+    REQUIRE(!update_sketch.is_empty());
+    REQUIRE(update_sketch.is_estimation_mode());
+    unsigned count = 0;
+    for (const auto& entry: update_sketch) {
+      REQUIRE(entry.second == 2);
+      ++count;
+    }
+    REQUIRE(count == update_sketch.get_num_retained());
+
+    auto compact_sketch = update_sketch.compact();
+    REQUIRE(!compact_sketch.is_empty());
+    REQUIRE(compact_sketch.is_estimation_mode());
+    count = 0;
+    for (const auto& entry: compact_sketch) {
+      REQUIRE(entry.second == 2);
+      ++count;
+    }
+    REQUIRE(count == update_sketch.get_num_retained());
+  }
+  REQUIRE(test_allocator_total_bytes == 0);
+  REQUIRE(test_allocator_net_allocations == 0);
+}
+
+} /* namespace datasketches */


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org