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/07/07 01:26:43 UTC
[incubator-datasketches-cpp] branch tuple_sketch updated: checking
in deserialize
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
The following commit(s) were added to refs/heads/tuple_sketch by this push:
new fd663b7 checking in deserialize
fd663b7 is described below
commit fd663b7436348ac36ce44b172bff12f11eb876c7
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Jul 6 18:26:29 2020 -0700
checking in deserialize
---
tuple/include/theta_update_sketch_base_impl.hpp | 20 ++++++++++++++++++++
tuple/include/tuple_sketch.hpp | 3 +--
tuple/include/tuple_sketch_impl.hpp | 8 ++++----
3 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/tuple/include/theta_update_sketch_base_impl.hpp b/tuple/include/theta_update_sketch_base_impl.hpp
index 62a1e0f..bf66aef 100644
--- a/tuple/include/theta_update_sketch_base_impl.hpp
+++ b/tuple/include/theta_update_sketch_base_impl.hpp
@@ -262,4 +262,24 @@ auto theta_const_iterator<Entry, ExtractKey>::operator*() const -> const Entry&
return entries_[index_];
}
+// helpers
+
+static inline void check_sketch_type(uint8_t actual, uint8_t expected) {
+ if (actual != expected) {
+ throw std::invalid_argument("Sketch type mismatch: expected " + std::to_string((int)expected) + ", actual " + std::to_string((int)actual));
+ }
+}
+
+static inline void check_serial_version(uint8_t actual, uint8_t expected) {
+ if (actual != expected) {
+ throw std::invalid_argument("Sketch serial version mismatch: expected " + std::to_string((int)expected) + ", actual " + std::to_string((int)actual));
+ }
+}
+
+static inline void check_seed_hash(uint16_t actual, uint16_t expected) {
+ if (actual != expected) {
+ throw std::invalid_argument("Sketch seed hash mismatch: expected " + std::to_string(expected) + ", actual " + std::to_string(actual));
+ }
+}
+
} /* namespace datasketches */
diff --git a/tuple/include/tuple_sketch.hpp b/tuple/include/tuple_sketch.hpp
index af1a926..87d6dc9 100644
--- a/tuple/include/tuple_sketch.hpp
+++ b/tuple/include/tuple_sketch.hpp
@@ -42,8 +42,6 @@ public:
using ExtractKey = pair_extract_key<uint64_t, Summary>;
using const_iterator = theta_const_iterator<Entry, ExtractKey>;
- static const uint8_t SERIAL_VERSION = 3;
-
virtual ~tuple_sketch() = default;
/**
@@ -325,6 +323,7 @@ public:
using vector_bytes = std::vector<uint8_t, AllocBytes>;
using comparator = compare_by_key<Entry, ExtractKey>;
+ static const uint8_t SERIAL_VERSION = 3;
static const uint8_t SKETCH_TYPE = 3;
// Instances of this type can be obtained:
diff --git a/tuple/include/tuple_sketch_impl.hpp b/tuple/include/tuple_sketch_impl.hpp
index caa9dff..431ace8 100644
--- a/tuple/include/tuple_sketch_impl.hpp
+++ b/tuple/include/tuple_sketch_impl.hpp
@@ -330,7 +330,7 @@ auto compact_tuple_sketch<S, A>::serialize(unsigned header_size_bytes, const Ser
const uint8_t* end_ptr = ptr + size;
ptr += copy_to_mem(&preamble_longs, ptr, sizeof(preamble_longs));
- const uint8_t serial_version = Base::SERIAL_VERSION;
+ const uint8_t serial_version = SERIAL_VERSION;
ptr += copy_to_mem(&serial_version, ptr, sizeof(serial_version));
const uint8_t type = SKETCH_TYPE;
ptr += copy_to_mem(&type, ptr, sizeof(type));
@@ -383,10 +383,10 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(const void* b
ptr += copy_from_mem(ptr, &flags_byte, sizeof(flags_byte));
uint16_t seed_hash;
ptr += copy_from_mem(ptr, &seed_hash, sizeof(seed_hash));
-// theta_sketch_alloc<A>::check_sketch_type(type, SKETCH_TYPE);
-// theta_sketch_alloc<A>::check_serial_version(serial_version, theta_sketch_alloc<A>::SERIAL_VERSION);
+ check_sketch_type(type, SKETCH_TYPE);
+ check_serial_version(serial_version, SERIAL_VERSION);
const bool is_empty = flags_byte & (1 << Base::flags::IS_EMPTY);
-// if (!is_empty) theta_sketch_alloc<A>::check_seed_hash(seed_hash, theta_sketch_alloc<A>::get_seed_hash(seed));
+ if (!is_empty) check_seed_hash(seed_hash, compute_seed_hash(seed));
uint64_t theta = theta_constants::MAX_THETA;
uint32_t num_entries = 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org