explicit type casts and other cleanup
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_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_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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
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 @@
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 @@
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 @@
};
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),