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/10/12 01:54:20 UTC
[datasketches-cpp] branch no_sstream_in_to_string updated (dc455f9
-> e604d4e)
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a change to branch no_sstream_in_to_string
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git.
from dc455f9 no sstream in to_string
new 5bee996 no sstream in to_string()
new 1bff55d no sstream in to_string()
new 226899f no sstream in to_string()
new e604d4e no sstream in to_string()
The 4 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.
Summary of changes:
cpc/include/cpc_sketch_impl.hpp | 30 +++++------
fi/include/frequent_items_sketch.hpp | 1 +
fi/include/frequent_items_sketch_impl.hpp | 29 ++++++-----
hll/include/HllSketch-internal.hpp | 85 +++++++++++++------------------
req/include/req_sketch.hpp | 1 +
req/include/req_sketch_impl.hpp | 53 +++++++++----------
6 files changed, 94 insertions(+), 105 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
[datasketches-cpp] 03/04: no sstream in to_string()
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch no_sstream_in_to_string
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git
commit 226899fb4433eede9bff9a7a71e30b4f978c8624
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Oct 11 18:20:06 2021 -0700
no sstream in to_string()
---
hll/include/HllSketch-internal.hpp | 85 ++++++++++++++++----------------------
1 file changed, 35 insertions(+), 50 deletions(-)
diff --git a/hll/include/HllSketch-internal.hpp b/hll/include/HllSketch-internal.hpp
index c048039..26bca7a 100644
--- a/hll/include/HllSketch-internal.hpp
+++ b/hll/include/HllSketch-internal.hpp
@@ -31,7 +31,6 @@
#include <cstdlib>
#include <string>
#include <iostream>
-#include <sstream>
#include <iomanip>
namespace datasketches {
@@ -246,99 +245,85 @@ string<A> hll_sketch_alloc<A>::to_string(const bool summary,
const bool detail,
const bool aux_detail,
const bool all) const {
- std::basic_ostringstream<char, std::char_traits<char>, AllocChar<A>> os;
+ string<A> str(sketch_impl->getAllocator());
if (summary) {
- os << "### HLL sketch summary:" << std::endl
- << " Log Config K : " << std::to_string(get_lg_config_k()) << std::endl
- << " Hll Target : " << type_as_string() << std::endl
- << " Current Mode : " << mode_as_string() << std::endl
- << " LB : " << get_lower_bound(1) << std::endl
- << " Estimate : " << get_estimate() << std::endl
- << " UB : " << get_upper_bound(1) << std::endl
- << " OutOfOrder flag: " << (is_out_of_order_flag() ? "true" : "false") << std::endl;
+ str.append("### HLL sketch summary:\n");
+ str.append(" Log Config K : ").append(std::to_string(get_lg_config_k())).append("\n");
+ str.append(" Hll Target : ").append(type_as_string()).append("\n");
+ str.append(" Current Mode : ").append(mode_as_string()).append("\n");
+ str.append(" LB : ").append(std::to_string(get_lower_bound(1))).append("\n");
+ str.append(" Estimate : ").append(std::to_string(get_estimate())).append("\n");
+ str.append(" UB : ").append(std::to_string(get_upper_bound(1))).append("\n");
+ str.append(" OutOfOrder flag: ").append(is_out_of_order_flag() ? "true\n" : "false\n");
if (get_current_mode() == HLL) {
HllArray<A>* hllArray = (HllArray<A>*) sketch_impl;
- os << " CurMin : " << std::to_string(hllArray->getCurMin()) << std::endl
- << " NumAtCurMin : " << hllArray->getNumAtCurMin() << std::endl
- << " HipAccum : " << hllArray->getHipAccum() << std::endl
- << " KxQ0 : " << hllArray->getKxQ0() << std::endl
- << " KxQ1 : " << hllArray->getKxQ1() << std::endl;
+ str.append(" CurMin : ").append(std::to_string(hllArray->getCurMin())).append("\n");
+ str.append(" NumAtCurMin : ").append(std::to_string(hllArray->getNumAtCurMin())).append("\n");
+ str.append(" HipAccum : ").append(std::to_string(hllArray->getHipAccum())).append("\n");
+ str.append(" KxQ0 : ").append(std::to_string(hllArray->getKxQ0())).append("\n");
+ str.append(" KxQ1 : ").append(std::to_string(hllArray->getKxQ1())).append("\n");
if (get_target_type() == HLL_4) {
const Hll4Array<A>* hll4_ptr = static_cast<const Hll4Array<A>*>(sketch_impl);
- os << " Aux table? : " << (hll4_ptr->getAuxHashMap() != nullptr ? "true" : "false") << std::endl;
+ str.append(" Aux table? : ").append(hll4_ptr->getAuxHashMap() != nullptr ? "true\n" : "false\n");
}
} else {
- os << " Coupon count : "
- << std::to_string(((CouponList<A>*) sketch_impl)->getCouponCount()) << std::endl;
+ str.append(" Coupon count : ").append(std::to_string(((CouponList<A>*) sketch_impl)->getCouponCount())).append("\n");
}
- os << "### End HLL sketch summary" << std::endl;
+ str.append("### End HLL sketch summary\n");
}
if (detail) {
- os << "### HLL sketch data detail:" << std::endl;
+ str.append("### HLL sketch data detail:\n");
if (get_current_mode() == HLL) {
const HllArray<A>* hll_ptr = static_cast<const HllArray<A>*>(sketch_impl);
- os << std::left << std::setw(10) << "Slot" << std::setw(6) << "Value" << std::endl;
+ str.append("Slot: Value\n");
auto it = hll_ptr->begin(all);
while (it != hll_ptr->end()) {
- os << std::setw(10) << HllUtil<A>::getLow26(*it);
- os << std::setw(6) << HllUtil<A>::getValue(*it);
- os << std::endl;
+ str.append(std::to_string(HllUtil<A>::getLow26(*it))).append(": ")
+ .append(std::to_string(HllUtil<A>::getValue(*it))).append("\n");
++it;
}
} else {
const CouponList<A>* list_ptr = static_cast<const CouponList<A>*>(sketch_impl);
- os << std::left;
- os << std::setw(10) << "Index";
- os << std::setw(10) << "Key";
- os << std::setw(10) << "Slot";
- os << std::setw(6) << "Value";
- os << std::endl;
+ str.append("Index, Key, Slot, Value\n");
auto it = list_ptr->begin(all);
int i = 0;
int mask = (1 << get_lg_config_k()) - 1;
while (it != list_ptr->end()) {
- os << std::setw(10) << i;
- os << std::setw(10) << HllUtil<A>::getLow26(*it);
- os << std::setw(10) << (HllUtil<A>::getLow26(*it) & mask);
- os << std::setw(6) << HllUtil<A>::getValue(*it);
- os << std::endl;
+ str.append(std::to_string(i)).append(", ")
+ .append(std::to_string(HllUtil<A>::getLow26(*it))).append(", ")
+ .append(std::to_string(HllUtil<A>::getLow26(*it) & mask)).append(", ")
+ .append(std::to_string(HllUtil<A>::getValue(*it))).append("\n");
++it;
++i;
}
}
- os << "### End HLL sketch data detail" << std::endl;
+ str.append("### End HLL sketch data detail\n");
}
if (aux_detail) {
if ((get_current_mode() == HLL) && (get_target_type() == HLL_4)) {
const Hll4Array<A>* hll4_ptr = static_cast<const Hll4Array<A>*>(sketch_impl);
const AuxHashMap<A>* aux_ptr = hll4_ptr->getAuxHashMap();
if (aux_ptr != nullptr) {
- os << "### HLL sketch aux detail:" << std::endl;
- os << std::left;
- os << std::setw(10) << "Index";
- os << std::setw(10) << "Key";
- os << std::setw(10) << "Slot";
- os << std::setw(6) << "Value";
- os << std::endl;
+ str.append("### HLL sketch aux detail:\n");
+ str.append("Index, Key, Slot, Value\n");
auto it = aux_ptr->begin(all);
int i = 0;
int mask = (1 << get_lg_config_k()) - 1;
while (it != aux_ptr->end()) {
- os << std::setw(10) << i;
- os << std::setw(10) << HllUtil<A>::getLow26(*it);
- os << std::setw(10) << (HllUtil<A>::getLow26(*it) & mask);
- os << std::setw(6) << HllUtil<A>::getValue(*it);
- os << std::endl;
+ str.append(std::to_string(i)).append(", ")
+ .append(std::to_string(HllUtil<A>::getLow26(*it))).append(", ")
+ .append(std::to_string(HllUtil<A>::getLow26(*it) & mask)).append(", ")
+ .append(std::to_string(HllUtil<A>::getValue(*it))).append("\n");
++it;
++i;
}
- os << "### End HLL sketch aux detail" << std::endl;
+ str.append("### End HLL sketch aux detail\n");
}
}
}
- return os.str();
+ return str;
}
template<typename A>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
[datasketches-cpp] 02/04: no sstream in to_string()
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch no_sstream_in_to_string
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git
commit 1bff55d5c3d747843b296beb4dd4a0346a4cddc3
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Oct 11 15:01:51 2021 -0700
no sstream in to_string()
---
cpc/include/cpc_sketch_impl.hpp | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/cpc/include/cpc_sketch_impl.hpp b/cpc/include/cpc_sketch_impl.hpp
index 2ad977a..0b570a2 100644
--- a/cpc/include/cpc_sketch_impl.hpp
+++ b/cpc/include/cpc_sketch_impl.hpp
@@ -381,25 +381,25 @@ void cpc_sketch_alloc<A>::refresh_kxp(const uint64_t* bit_matrix) {
template<typename A>
string<A> cpc_sketch_alloc<A>::to_string() const {
- std::basic_ostringstream<char, std::char_traits<char>, AllocChar<A>> os;
- os << "### CPC sketch summary:" << std::endl;
- os << " lg_k : " << std::to_string(lg_k) << std::endl;
- os << " seed hash : " << std::hex << compute_seed_hash(seed) << std::dec << std::endl;
- os << " C : " << num_coupons << std::endl;
- os << " flavor : " << determine_flavor() << std::endl;
- os << " merged : " << (was_merged ? "true" : "false") << std::endl;
+ string<A> str(sliding_window.get_allocator());
+ str.append("### CPC sketch summary:\n");
+ str.append(" lg_k : ").append(std::to_string(lg_k)).append("\n");
+ str.append(" seed hash : ").append(std::to_string(compute_seed_hash(seed))).append("\n");
+ str.append(" C : ").append(std::to_string(num_coupons)).append("\n");
+ str.append(" flavor : ").append(std::to_string(determine_flavor())).append("\n");
+ str.append(" merged : ").append(was_merged ? "true\n" : "false\n");
if (!was_merged) {
- os << " HIP estimate : " << hip_est_accum << std::endl;
- os << " kxp : " << kxp << std::endl;
+ str.append(" HIP estimate : ").append(std::to_string(hip_est_accum)).append("\n");
+ str.append(" kxp : ").append(std::to_string(kxp)).append("\n");
}
- os << " intresting col : " << std::to_string(first_interesting_column) << std::endl;
- os << " table entries : " << surprising_value_table.get_num_items() << std::endl;
- os << " window : " << (sliding_window.size() == 0 ? "not " : "") << "allocated" << std::endl;
+ str.append(" intresting col : ").append(std::to_string(first_interesting_column)).append("\n");
+ str.append(" table entries : ").append(std::to_string(surprising_value_table.get_num_items())).append("\n");
+ str.append(" window : ").append(sliding_window.size() == 0 ? "not " : "").append("allocated\n");
if (sliding_window.size() > 0) {
- os << " window offset : " << std::to_string(window_offset) << std::endl;
+ str.append(" window offset : ").append(std::to_string(window_offset)).append("\n");
}
- os << "### End sketch summary" << std::endl;
- return os.str();
+ str.append("### End sketch summary\n");
+ return str;
}
template<typename A>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
[datasketches-cpp] 04/04: no sstream in to_string()
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch no_sstream_in_to_string
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git
commit e604d4e413aaa7cd42228188e0591500d4919840
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Oct 11 18:54:12 2021 -0700
no sstream in to_string()
---
req/include/req_sketch.hpp | 1 +
req/include/req_sketch_impl.hpp | 53 +++++++++++++++++++++--------------------
2 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/req/include/req_sketch.hpp b/req/include/req_sketch.hpp
index 779caba..1e2a4ca 100755
--- a/req/include/req_sketch.hpp
+++ b/req/include/req_sketch.hpp
@@ -273,6 +273,7 @@ public:
* @param print_levels if true include information about levels
* @param print_items if true include sketch data
*/
+ template<typename ToStr = ostream_based_to_string<T>>
string<Allocator> to_string(bool print_levels = false, bool print_items = false) const;
class const_iterator;
diff --git a/req/include/req_sketch_impl.hpp b/req/include/req_sketch_impl.hpp
index ee6d9e1..238fc66 100755
--- a/req/include/req_sketch_impl.hpp
+++ b/req/include/req_sketch_impl.hpp
@@ -20,7 +20,6 @@
#ifndef REQ_SKETCH_IMPL_HPP_
#define REQ_SKETCH_IMPL_HPP_
-#include <sstream>
#include <stdexcept>
namespace datasketches {
@@ -652,48 +651,50 @@ void req_sketch<T, C, S, A>::compress() {
}
template<typename T, typename C, typename S, typename A>
+template<typename ToStr>
string<A> req_sketch<T, C, S, A>::to_string(bool print_levels, bool print_items) const {
- std::basic_ostringstream<char, std::char_traits<char>, AllocChar<A>> os;
- os << "### REQ sketch summary:" << std::endl;
- os << " K : " << k_ << std::endl;
- os << " High Rank Acc : " << (hra_ ? "true" : "false") << std::endl;
- os << " Empty : " << (is_empty() ? "true" : "false") << std::endl;
- os << " Estimation mode: " << (is_estimation_mode() ? "true" : "false") << std::endl;
- os << " Sorted : " << (compactors_[0].is_sorted() ? "true" : "false") << std::endl;
- os << " N : " << n_ << std::endl;
- os << " Levels : " << compactors_.size() << std::endl;
- os << " Retained items : " << num_retained_ << std::endl;
- os << " Capacity items : " << max_nom_size_ << std::endl;
+ string<A> str(allocator_);
+ str.append("### REQ sketch summary:\n");
+ str.append(" K : ").append(std::to_string(k_)).append("\n");
+ str.append(" High Rank Acc : ").append(hra_ ? "true\n" : "false\n");
+ str.append(" Empty : ").append(is_empty() ? "true\n" : "false\n");
+ str.append(" Estimation mode: ").append(is_estimation_mode() ? "true\n" : "false\n");
+ str.append(" Sorted : ").append(compactors_[0].is_sorted() ? "true\n" : "false\n");
+ str.append(" N : ").append(std::to_string(n_)).append("\n");
+ str.append(" Levels : ").append(std::to_string(compactors_.size())).append("\n");
+
+ str.append(" Retained items : ").append(std::to_string(num_retained_)).append("\n");
+ str.append(" Capacity items : ").append(std::to_string(max_nom_size_)).append("\n");
if (!is_empty()) {
- os << " Min value : " << *min_value_ << std::endl;
- os << " Max value : " << *max_value_ << std::endl;
+ str.append(" Min value : ").append(ToStr()(*min_value_)).append("\n");
+ str.append(" Max value : ").append(ToStr()(*max_value_)).append("\n");
}
- os << "### End sketch summary" << std::endl;
+ str.append("### End sketch summary\n");
if (print_levels) {
- os << "### REQ sketch levels:" << std::endl;
- os << " index: nominal capacity, actual size" << std::endl;
+ str.append("### REQ sketch levels:\n");
+ str.append(" index: nominal capacity, actual size\n");
for (uint8_t i = 0; i < compactors_.size(); i++) {
- os << " " << (unsigned int) i << ": "
- << compactors_[i].get_nom_capacity() << ", "
- << compactors_[i].get_num_items() << std::endl;
+ str.append(" ").append(std::to_string(i)).append(": ")
+ .append(std::to_string(compactors_[i].get_nom_capacity())).append(", ")
+ .append(std::to_string(compactors_[i].get_num_items())).append("\n");
}
- os << "### End sketch levels" << std::endl;
+ str.append("### End sketch levels\n");
}
if (print_items) {
- os << "### REQ sketch data:" << std::endl;
+ str.append("### REQ sketch data:\n");
unsigned level = 0;
for (const auto& compactor: compactors_) {
- os << " level " << level << ": " << std::endl;
+ str.append(" level ").append(std::to_string(level)).append(":\n");
for (auto it = compactor.begin(); it != compactor.end(); ++it) {
- os << " " << *it << std::endl;
+ str.append(" ").append(ToStr()(*it)).append("\n");
}
++level;
}
- os << "### End sketch data" << std::endl;
+ str.append("### End sketch data\n");
}
- return os.str();
+ return str;
}
template<typename T, typename C, typename S, typename A>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
[datasketches-cpp] 01/04: no sstream in to_string()
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch no_sstream_in_to_string
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git
commit 5bee9963160375e6dd3c49e57a9e6d316e6296a7
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Oct 11 15:01:07 2021 -0700
no sstream in to_string()
---
fi/include/frequent_items_sketch.hpp | 1 +
fi/include/frequent_items_sketch_impl.hpp | 29 +++++++++++++++--------------
2 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/fi/include/frequent_items_sketch.hpp b/fi/include/frequent_items_sketch.hpp
index 6efe2b9..b1f966f 100644
--- a/fi/include/frequent_items_sketch.hpp
+++ b/fi/include/frequent_items_sketch.hpp
@@ -269,6 +269,7 @@ public:
* Returns a human readable summary of this sketch
* @param print_items if true include the list of items retained by the sketch
*/
+ template<typename ToStr = ostream_based_to_string<T>>
string<A> to_string(bool print_items = false) const;
private:
diff --git a/fi/include/frequent_items_sketch_impl.hpp b/fi/include/frequent_items_sketch_impl.hpp
index e7db449..a7e1d1d 100644
--- a/fi/include/frequent_items_sketch_impl.hpp
+++ b/fi/include/frequent_items_sketch_impl.hpp
@@ -420,15 +420,16 @@ void frequent_items_sketch<T, W, H, E, S, A>::check_size(uint8_t lg_cur_size, ui
}
template<typename T, typename W, typename H, typename E, typename S, typename A>
+template<typename ToStr>
string<A> frequent_items_sketch<T, W, H, E, S, A>::to_string(bool print_items) const {
- std::basic_ostringstream<char, std::char_traits<char>, AllocChar<A>> os;
- os << "### Frequent items sketch summary:" << std::endl;
- os << " lg cur map size : " << (int) map.get_lg_cur_size() << std::endl;
- os << " lg max map size : " << (int) map.get_lg_max_size() << std::endl;
- os << " num active items : " << get_num_active_items() << std::endl;
- os << " total weight : " << get_total_weight() << std::endl;
- os << " max error : " << get_maximum_error() << std::endl;
- os << "### End sketch summary" << std::endl;
+ string<A> str(map.get_allocator());
+ str.append("### Frequent items sketch summary:\n");
+ str.append(" lg cur map size : ").append(std::to_string(map.get_lg_cur_size())).append("\n");
+ str.append(" lg max map size : ").append(std::to_string(map.get_lg_max_size())).append("\n");
+ str.append(" num active items : ").append(std::to_string(get_num_active_items())).append("\n");
+ str.append(" total weight : ").append(std::to_string(get_total_weight())).append("\n");
+ str.append(" max error : ").append(std::to_string(get_maximum_error())).append("\n");
+ str.append("### End sketch summary\n");
if (print_items) {
vector_row items;
for (auto it: map) {
@@ -436,15 +437,15 @@ string<A> frequent_items_sketch<T, W, H, E, S, A>::to_string(bool print_items) c
}
// sort by estimate in descending order
std::sort(items.begin(), items.end(), [](row a, row b){ return a.get_estimate() > b.get_estimate(); });
- os << "### Items in descending order by estimate" << std::endl;
- os << " item, estimate, lower bound, upper bound" << std::endl;
+ str.append("### Items in descending order by estimate\n");
+ str.append(" item, estimate, lower bound, upper bound");
for (auto it: items) {
- os << " " << it.get_item() << ", " << it.get_estimate() << ", "
- << it.get_lower_bound() << ", " << it.get_upper_bound() << std::endl;
+ str.append(" ").append(ToStr()(it.get_item())).append(", ").append(std::to_string(it.get_estimate())).append(", ")
+ .append(std::to_string(it.get_lower_bound())).append(", ").append(std::to_string(it.get_upper_bound())).append("\n");
}
- os << "### End items" << std::endl;
+ str.append("### End items\n");
}
- return os.str();
+ return str;
}
// version for integral signed type
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org