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/04/29 22:04:48 UTC
[incubator-datasketches-postgresql] 01/01: updated serde api
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch new_serde
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-postgresql.git
commit 08d21c5a81d449cbc8718129875e976bd81fcf91
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Wed Apr 29 15:03:55 2020 -0700
updated serde api
---
src/cpc_sketch_c_adapter.cpp | 2 +-
src/frequent_strings_sketch_c_adapter.cpp | 32 +++++++------------------------
2 files changed, 8 insertions(+), 26 deletions(-)
diff --git a/src/cpc_sketch_c_adapter.cpp b/src/cpc_sketch_c_adapter.cpp
index c61ddd8..6ed5d75 100644
--- a/src/cpc_sketch_c_adapter.cpp
+++ b/src/cpc_sketch_c_adapter.cpp
@@ -87,7 +87,7 @@ Datum* cpc_sketch_get_estimate_and_bounds(const void* sketchptr, unsigned num_st
void cpc_sketch_to_string(const void* sketchptr, char* buffer, unsigned length) {
try {
std::stringstream s;
- static_cast<const cpc_sketch_pg*>(sketchptr)->to_stream(s);;
+ static_cast<const cpc_sketch_pg*>(sketchptr)->to_stream(s);
snprintf(buffer, length, "%s", s.str().c_str());
} catch (std::exception& e) {
pg_error(e.what());
diff --git a/src/frequent_strings_sketch_c_adapter.cpp b/src/frequent_strings_sketch_c_adapter.cpp
index b77e49c..7146625 100644
--- a/src/frequent_strings_sketch_c_adapter.cpp
+++ b/src/frequent_strings_sketch_c_adapter.cpp
@@ -36,33 +36,14 @@ struct hash_string {
};
struct serde_string {
- void serialize(std::ostream& os, const string* items, unsigned num) {
- for (unsigned i = 0; i < num; i++) {
- uint32_t length = items[i].size();
- os.write((char*)&length, sizeof(length));
- os.write(items[i].c_str(), length);
- }
- }
- void deserialize(std::istream& is, string* items, unsigned num) {
- for (unsigned i = 0; i < num; i++) {
- uint32_t length;
- is.read((char*)&length, sizeof(length));
- new (&items[i]) string;
- items[i].reserve(length);
- auto it = std::istreambuf_iterator<char>(is);
- for (uint32_t j = 0; j < length; j++) {
- items[i].push_back(*it);
- ++it;
- }
- }
- }
size_t size_of_item(const string& item) {
return sizeof(uint32_t) + item.size();
}
- size_t serialize(void* ptr, const string* items, unsigned num) {
+
+ size_t serialize(void* ptr, size_t capacity, const string* items, unsigned num) {
size_t size = sizeof(uint32_t) * num;
for (unsigned i = 0; i < num; i++) {
- uint32_t length = items[i].size();
+ const uint32_t length = items[i].size();
memcpy(ptr, &length, sizeof(length));
ptr = static_cast<char*>(ptr) + sizeof(uint32_t);
memcpy(ptr, items[i].c_str(), length);
@@ -71,7 +52,8 @@ struct serde_string {
}
return size;
}
- size_t deserialize(const void* ptr, string* items, unsigned num) {
+
+ size_t deserialize(const void* ptr, size_t capacity, string* items, unsigned num) {
size_t size = sizeof(uint32_t) * num;
for (unsigned i = 0; i < num; i++) {
uint32_t length;
@@ -142,7 +124,7 @@ ptr_with_size frequent_strings_sketch_serialize(const void* sketchptr, unsigned
static_cast<const frequent_strings_sketch*>(sketchptr)->serialize(header_size)
);
p.ptr = bytes->data();
- p.size = bytes->size();;
+ p.size = bytes->size();
return p;
} catch (std::exception& e) {
pg_error(e.what());
@@ -187,7 +169,7 @@ frequent_strings_sketch_result* frequent_strings_sketch_get_frequent_items(void*
rows[i].upper_bound = it.get_upper_bound();
++i;
}
- auto result = (frequent_strings_sketch_result*) palloc(sizeof(frequent_strings_sketch_result));;
+ auto result = (frequent_strings_sketch_result*) palloc(sizeof(frequent_strings_sketch_result));
result->rows = rows;
result->num = data.size();
return result;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org