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 2022/09/13 18:33:00 UTC
[datasketches-cpp] branch serialization_fix created (now 60b104b)
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a change to branch serialization_fix
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git
at 60b104b fixed problem introduced by #301
This branch includes the following new commits:
new 60b104b fixed problem introduced by #301
The 1 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.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
[datasketches-cpp] 01/01: fixed problem introduced by #301
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch serialization_fix
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git
commit 60b104bf7b1b7c8001a2506fe294a6559616a472
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Sep 13 11:32:34 2022 -0700
fixed problem introduced by #301
---
theta/include/theta_sketch_impl.hpp | 40 ++++++++++++++-----------------------
1 file changed, 15 insertions(+), 25 deletions(-)
diff --git a/theta/include/theta_sketch_impl.hpp b/theta/include/theta_sketch_impl.hpp
index b7ea693..2e06b89 100644
--- a/theta/include/theta_sketch_impl.hpp
+++ b/theta/include/theta_sketch_impl.hpp
@@ -341,8 +341,7 @@ void compact_theta_sketch_alloc<A>::print_specifics(std::ostringstream&) const {
template<typename A>
void compact_theta_sketch_alloc<A>::serialize(std::ostream& os) const {
- const bool is_single_item = entries_.size() == 1 && !this->is_estimation_mode();
- const uint8_t preamble_longs = this->is_empty() || is_single_item ? 1 : this->is_estimation_mode() ? 3 : 2;
+ const uint8_t preamble_longs = this->is_estimation_mode() ? 3 : this->is_empty() || entries_.size() == 1 ? 1 : 2;
write(os, preamble_longs);
const uint8_t serial_version = SERIAL_VERSION;
write(os, serial_version);
@@ -359,24 +358,19 @@ void compact_theta_sketch_alloc<A>::serialize(std::ostream& os) const {
write(os, flags_byte);
const uint16_t seed_hash = get_seed_hash();
write(os, seed_hash);
- if (entries_.size() > 0) {
- if (!is_single_item) {
- const uint32_t num_entries = static_cast<uint32_t>(entries_.size());
- write(os, num_entries);
- const uint32_t unused32 = 0;
- write(os, unused32);
- if (this->is_estimation_mode()) {
- write(os, this->theta_);
- }
- }
- write(os, entries_.data(), entries_.size() * sizeof(uint64_t));
+ if (preamble_longs > 1) {
+ const uint32_t num_entries = static_cast<uint32_t>(entries_.size());
+ write(os, num_entries);
+ const uint32_t unused32 = 0;
+ write(os, unused32);
}
+ if (this->is_estimation_mode()) write(os, this->theta_);
+ if (entries_.size() > 0) write(os, entries_.data(), entries_.size() * sizeof(uint64_t));
}
template<typename A>
auto compact_theta_sketch_alloc<A>::serialize(unsigned header_size_bytes) const -> vector_bytes {
- const bool is_single_item = entries_.size() == 1 && !this->is_estimation_mode();
- const uint8_t preamble_longs = this->is_empty() || is_single_item ? 1 : this->is_estimation_mode() ? 3 : 2;
+ const uint8_t preamble_longs = this->is_estimation_mode() ? 3 : this->is_empty() || entries_.size() == 1 ? 1 : 2;
const size_t size = header_size_bytes + sizeof(uint64_t) * preamble_longs
+ sizeof(uint64_t) * entries_.size();
vector_bytes bytes(size, 0, entries_.get_allocator());
@@ -397,17 +391,13 @@ auto compact_theta_sketch_alloc<A>::serialize(unsigned header_size_bytes) const
ptr += copy_to_mem(flags_byte, ptr);
const uint16_t seed_hash = get_seed_hash();
ptr += copy_to_mem(seed_hash, ptr);
- if (entries_.size() > 0) {
- if (!is_single_item) {
- const uint32_t num_entries = static_cast<uint32_t>(entries_.size());
- ptr += copy_to_mem(num_entries, ptr);
- ptr += sizeof(uint32_t);
- if (this->is_estimation_mode()) {
- ptr += copy_to_mem(theta_, ptr);
- }
- }
- ptr += copy_to_mem(entries_.data(), ptr, entries_.size() * sizeof(uint64_t));
+ if (preamble_longs > 1) {
+ const uint32_t num_entries = static_cast<uint32_t>(entries_.size());
+ ptr += copy_to_mem(num_entries, ptr);
+ ptr += sizeof(uint32_t); // unused
}
+ if (this->is_estimation_mode()) ptr += copy_to_mem(theta_, ptr);
+ if (entries_.size() > 0) ptr += copy_to_mem(entries_.data(), ptr, entries_.size() * sizeof(uint64_t));
return bytes;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org