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 2021/03/17 01:11:05 UTC

[datasketches-cpp] branch cleanup_warnings updated: explicit type casts and other cleanup

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

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


The following commit(s) were added to refs/heads/cleanup_warnings by this push:
     new 67ab84c  explicit type casts and other cleanup
67ab84c is described below

commit 67ab84c7b383039ef3ddc59a54946fb7f3f3732e
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Mar 16 18:10:57 2021 -0700

    explicit type casts and other cleanup
---
 common/include/count_zeros.hpp     |  4 ++--
 common/include/serde.hpp           | 12 ++++++------
 req/include/req_compactor_impl.hpp |  8 ++++----
 req/include/req_sketch.hpp         |  2 +-
 req/include/req_sketch_impl.hpp    | 10 +++++-----
 5 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/common/include/count_zeros.hpp b/common/include/count_zeros.hpp
index 0c9f6b4..cdd9940 100644
--- a/common/include/count_zeros.hpp
+++ b/common/include/count_zeros.hpp
@@ -94,7 +94,7 @@ static inline uint8_t count_leading_zeros_in_u64(uint64_t input) {
 static inline uint8_t count_trailing_zeros_in_u32(uint32_t input) {
   for (int i = 0; i < 4; i++) {
     const int byte = input & 0xff;
-    if (byte != 0) return (i << 3) + byte_trailing_zeros_table[byte];
+    if (byte != 0) return static_cast<uint8_t>((i << 3) + byte_trailing_zeros_table[byte]);
     input >>= 8;
   }
   return 32;
@@ -103,7 +103,7 @@ static inline uint8_t count_trailing_zeros_in_u32(uint32_t input) {
 static inline uint8_t count_trailing_zeros_in_u64(uint64_t input) {
   for (int i = 0; i < 8; i++) {
     const int byte = input & 0xff;
-    if (byte != 0) return (i << 3) + byte_trailing_zeros_table[byte];
+    if (byte != 0) return static_cast<uint8_t>((i << 3) + byte_trailing_zeros_table[byte]);
     input >>= 8;
   }
   return 64;
diff --git a/common/include/serde.hpp b/common/include/serde.hpp
index 73e0901..05a8a4e 100644
--- a/common/include/serde.hpp
+++ b/common/include/serde.hpp
@@ -51,7 +51,7 @@ struct serde<T, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
     bool failure = false;
     try {
       os.write(reinterpret_cast<const char*>(items), sizeof(T) * num);
-    } catch (std::ostream::failure& e) {
+    } catch (std::ostream::failure&) {
       failure = true;
     }
     if (failure || !os.good()) {
@@ -62,7 +62,7 @@ struct serde<T, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
     bool failure = false;
     try {
       is.read((char*)items, sizeof(T) * num);
-    } catch (std::istream::failure& e) {
+    } catch (std::istream::failure&) {
       failure = true;
     }
     if (failure || !is.good()) {
@@ -99,11 +99,11 @@ struct serde<std::string> {
     bool failure = false;
     try {
       for (; i < num && os.good(); i++) {
-        uint32_t length = items[i].size();
+        uint32_t length = static_cast<uint32_t>(items[i].size());
         os.write((char*)&length, sizeof(length));
         os.write(items[i].c_str(), length);
       }
-    } catch (std::ostream::failure& e) {
+    } catch (std::ostream::failure&) {
       failure = true;
     }
     if (failure || !os.good()) {
@@ -126,7 +126,7 @@ struct serde<std::string> {
         if (!is.good()) { break; }
         new (&items[i]) std::string(std::move(str));
       }
-    } catch (std::istream::failure& e) {
+    } catch (std::istream::failure&) {
       failure = true;
     }
     if (failure || !is.good()) {
@@ -143,7 +143,7 @@ struct serde<std::string> {
   size_t serialize(void* ptr, size_t capacity, const std::string* items, unsigned num) const {
     size_t bytes_written = 0;
     for (unsigned i = 0; i < num; ++i) {
-      const uint32_t length = items[i].size();
+      const uint32_t length = static_cast<uint32_t>(items[i].size());
       const size_t new_bytes = length + sizeof(length);
       check_memory_size(bytes_written + new_bytes, capacity);
       memcpy(ptr, &length, sizeof(length));
diff --git a/req/include/req_compactor_impl.hpp b/req/include/req_compactor_impl.hpp
index 2f6a4e3..d0c9613 100755
--- a/req/include/req_compactor_impl.hpp
+++ b/req/include/req_compactor_impl.hpp
@@ -38,7 +38,7 @@ lg_weight_(lg_weight),
 hra_(hra),
 coin_(false),
 sorted_(sorted),
-section_size_raw_(section_size),
+section_size_raw_(static_cast<float>(section_size)),
 section_size_(section_size),
 num_sections_(req_constants::INIT_NUM_SECTIONS),
 state_(0),
@@ -240,7 +240,7 @@ template<typename T, typename C, typename A>
 std::pair<uint32_t, uint32_t> req_compactor<T, C, A>::compact(req_compactor& next) {
   const uint32_t starting_nom_capacity = get_nom_capacity();
   // choose a part of the buffer to compact
-  const uint32_t secs_to_compact = std::min(static_cast<uint32_t>(count_trailing_zeros_in_u32(~state_) + 1), static_cast<uint32_t>(num_sections_));
+  const uint32_t secs_to_compact = std::min<uint32_t>(count_trailing_zeros_in_u32(~state_) + 1, num_sections_);
   auto compaction_range = compute_compaction_range(secs_to_compact);
   if (compaction_range.second - compaction_range.first < 2) throw std::logic_error("compaction range error");
 
@@ -267,9 +267,9 @@ std::pair<uint32_t, uint32_t> req_compactor<T, C, A>::compact(req_compactor& nex
 
 template<typename T, typename C, typename A>
 bool req_compactor<T, C, A>::ensure_enough_sections() {
-  const float ssr = section_size_raw_ / sqrt(2);
+  const float ssr = const_cast<float>(section_size_raw_ / sqrt(2));
   const uint32_t ne = nearest_even(ssr);
-  if (state_ >= static_cast<uint64_t>(1 << (num_sections_ - 1)) && ne >= req_constants::MIN_K) {
+  if (state_ >= static_cast<uint64_t>(1ULL << (num_sections_ - 1)) && ne >= req_constants::MIN_K) {
     section_size_raw_ = ssr;
     section_size_ = ne;
     num_sections_ <<= 1;
diff --git a/req/include/req_sketch.hpp b/req/include/req_sketch.hpp
index ca806cc..779caba 100755
--- a/req/include/req_sketch.hpp
+++ b/req/include/req_sketch.hpp
@@ -319,7 +319,7 @@ private:
 
   // for deserialization
   class item_deleter;
-  req_sketch(uint32_t k, bool hra, uint64_t n, std::unique_ptr<T, item_deleter> min_value, std::unique_ptr<T, item_deleter> max_value, std::vector<Compactor, AllocCompactor>&& compactors);
+  req_sketch(uint16_t k, bool hra, uint64_t n, std::unique_ptr<T, item_deleter> min_value, std::unique_ptr<T, item_deleter> max_value, std::vector<Compactor, AllocCompactor>&& compactors);
 
   static void check_preamble_ints(uint8_t preamble_ints, uint8_t num_levels);
   static void check_serial_version(uint8_t serial_version);
diff --git a/req/include/req_sketch_impl.hpp b/req/include/req_sketch_impl.hpp
index 3c90908..8b45bc9 100755
--- a/req/include/req_sketch_impl.hpp
+++ b/req/include/req_sketch_impl.hpp
@@ -28,7 +28,7 @@ namespace datasketches {
 template<typename T, typename C, typename S, typename A>
 req_sketch<T, C, S, A>::req_sketch(uint16_t k, bool hra, const A& allocator):
 allocator_(allocator),
-k_(std::max(static_cast<int>(k) & -2, static_cast<int>(req_constants::MIN_K))), //rounds down one if odd
+k_(std::max<uint8_t>(static_cast<int>(k) & -2, static_cast<int>(req_constants::MIN_K))), //rounds down one if odd
 hra_(hra),
 max_nom_size_(0),
 num_retained_(0),
@@ -401,7 +401,7 @@ void req_sketch<T, C, S, A>::serialize(std::ostream& os) const {
   write(os, k_);
   const uint8_t num_levels = is_empty() ? 0 : get_num_levels();
   write(os, num_levels);
-  const uint8_t num_raw_items = raw_items ? n_ : 0;
+  const uint8_t num_raw_items = raw_items ? static_cast<uint8_t>(n_) : 0;
   write(os, num_raw_items);
   if (is_empty()) return;
   if (is_estimation_mode()) {
@@ -440,7 +440,7 @@ auto req_sketch<T, C, S, A>::serialize(unsigned header_size_bytes) const -> vect
   ptr += copy_to_mem(k_, ptr);
   const uint8_t num_levels = is_empty() ? 0 : get_num_levels();
   ptr += copy_to_mem(num_levels, ptr);
-  const uint8_t num_raw_items = raw_items ? n_ : 0;
+  const uint8_t num_raw_items = raw_items ? static_cast<uint8_t>(n_) : 0;
   ptr += copy_to_mem(num_raw_items, ptr);
   if (!is_empty()) {
     if (is_estimation_mode()) {
@@ -620,7 +620,7 @@ void req_sketch<T, C, S, A>::grow() {
 
 template<typename T, typename C, typename S, typename A>
 uint8_t req_sketch<T, C, S, A>::get_num_levels() const {
-  return compactors_.size();
+  return static_cast<uint8_t>(compactors_.size());
 }
 
 template<typename T, typename C, typename S, typename A>
@@ -711,7 +711,7 @@ class req_sketch<T, C, S, A>::item_deleter {
 };
 
 template<typename T, typename C, typename S, typename A>
-req_sketch<T, C, S, A>::req_sketch(uint32_t k, bool hra, uint64_t n, std::unique_ptr<T, item_deleter> min_value, std::unique_ptr<T, item_deleter> max_value, std::vector<Compactor, AllocCompactor>&& compactors):
+req_sketch<T, C, S, A>::req_sketch(uint16_t k, bool hra, uint64_t n, std::unique_ptr<T, item_deleter> min_value, std::unique_ptr<T, item_deleter> max_value, std::vector<Compactor, AllocCompactor>&& compactors):
 allocator_(compactors.get_allocator()),
 k_(k),
 hra_(hra),


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