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 02:17:28 UTC
[incubator-datasketches-cpp] branch tuple_sketch updated: helpers
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 c73593e helpers
c73593e is described below
commit c73593eb4901f9ea615082d991277ee2822713b9
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Jul 6 19:17:19 2020 -0700
helpers
---
tuple/include/theta_helpers.hpp | 52 +++++++++++++++++++++++++
tuple/include/theta_update_sketch_base_impl.hpp | 20 ----------
tuple/include/tuple_sketch_impl.hpp | 7 ++--
3 files changed, 56 insertions(+), 23 deletions(-)
diff --git a/tuple/include/theta_helpers.hpp b/tuple/include/theta_helpers.hpp
new file mode 100644
index 0000000..53ca01b
--- /dev/null
+++ b/tuple/include/theta_helpers.hpp
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+#ifndef THETA_HELPERS_HPP_
+#define THETA_HELPERS_HPP_
+
+#include <string>
+#include <stdexcept>
+
+namespace datasketches {
+
+template<bool dummy>
+class checker {
+public:
+ static 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 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 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 */
+
+#endif
diff --git a/tuple/include/theta_update_sketch_base_impl.hpp b/tuple/include/theta_update_sketch_base_impl.hpp
index bf66aef..62a1e0f 100644
--- a/tuple/include/theta_update_sketch_base_impl.hpp
+++ b/tuple/include/theta_update_sketch_base_impl.hpp
@@ -262,24 +262,4 @@ 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_impl.hpp b/tuple/include/tuple_sketch_impl.hpp
index 431ace8..2ae9f0b 100644
--- a/tuple/include/tuple_sketch_impl.hpp
+++ b/tuple/include/tuple_sketch_impl.hpp
@@ -20,6 +20,7 @@
#include <sstream>
#include "binomial_bounds.hpp"
+#include "theta_helpers.hpp"
namespace datasketches {
@@ -383,10 +384,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));
- check_sketch_type(type, SKETCH_TYPE);
- check_serial_version(serial_version, SERIAL_VERSION);
+ checker<true>::check_sketch_type(type, SKETCH_TYPE);
+ checker<true>::check_serial_version(serial_version, SERIAL_VERSION);
const bool is_empty = flags_byte & (1 << Base::flags::IS_EMPTY);
- if (!is_empty) check_seed_hash(seed_hash, compute_seed_hash(seed));
+ if (!is_empty) checker<true>::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