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/11 19:13:10 UTC
[datasketches-cpp] branch no_sstream_in_to_string updated: no
sstream in to_string
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
The following commit(s) were added to refs/heads/no_sstream_in_to_string by this push:
new c0d8cb8 no sstream in to_string
c0d8cb8 is described below
commit c0d8cb8c3fb35c282c415298b14fb2cbe34b0355
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Oct 11 12:13:00 2021 -0700
no sstream in to_string
---
tuple/include/tuple_sketch.hpp | 10 +++-----
tuple/include/tuple_sketch_impl.hpp | 51 ++++++++++++++++++++-----------------
2 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/tuple/include/tuple_sketch.hpp b/tuple/include/tuple_sketch.hpp
index 7777606..cfa8a94 100644
--- a/tuple/include/tuple_sketch.hpp
+++ b/tuple/include/tuple_sketch.hpp
@@ -124,6 +124,7 @@ public:
* @param print_items if true include the list of items retained by the sketch
* @return sketch summary as a string
*/
+ template<typename ToStr = ostream_based_to_string<Summary>>
string<Allocator> to_string(bool print_items = false) const;
/**
@@ -153,8 +154,7 @@ public:
virtual const_iterator end() const = 0;
protected:
- using ostrstream = std::basic_ostringstream<char, std::char_traits<char>, AllocChar<Allocator>>;
- virtual void print_specifics(ostrstream& os) const = 0;
+ virtual string<Allocator> print_specifics() const = 0;
static uint16_t get_seed_hash(uint64_t seed);
@@ -344,8 +344,7 @@ protected:
// for builder
update_tuple_sketch(uint8_t lg_cur_size, uint8_t lg_nom_size, resize_factor rf, uint64_t theta, uint64_t seed, const Policy& policy, const Allocator& allocator);
- using ostrstream = typename Base::ostrstream;
- virtual void print_specifics(ostrstream& os) const;
+ virtual string<Allocator> print_specifics() const;
};
// compact sketch
@@ -473,8 +472,7 @@ protected:
bool destroy_;
};
- using ostrstream = typename Base::ostrstream;
- virtual void print_specifics(ostrstream& os) const;
+ virtual string<Allocator> print_specifics() const;
};
diff --git a/tuple/include/tuple_sketch_impl.hpp b/tuple/include/tuple_sketch_impl.hpp
index 1eba1e6..2b52e69 100644
--- a/tuple/include/tuple_sketch_impl.hpp
+++ b/tuple/include/tuple_sketch_impl.hpp
@@ -52,29 +52,30 @@ double tuple_sketch<S, A>::get_upper_bound(uint8_t num_std_devs) const {
}
template<typename S, typename A>
+template<typename ToStr>
string<A> tuple_sketch<S, A>::to_string(bool detail) const {
- ostrstream os;
- os << "### Tuple sketch summary:" << std::endl;
- os << " num retained entries : " << get_num_retained() << std::endl;
- os << " seed hash : " << get_seed_hash() << std::endl;
- os << " empty? : " << (is_empty() ? "true" : "false") << std::endl;
- os << " ordered? : " << (is_ordered() ? "true" : "false") << std::endl;
- os << " estimation mode? : " << (is_estimation_mode() ? "true" : "false") << std::endl;
- os << " theta (fraction) : " << get_theta() << std::endl;
- os << " theta (raw 64-bit) : " << get_theta64() << std::endl;
- os << " estimate : " << this->get_estimate() << std::endl;
- os << " lower bound 95% conf : " << this->get_lower_bound(2) << std::endl;
- os << " upper bound 95% conf : " << this->get_upper_bound(2) << std::endl;
- print_specifics(os);
- os << "### End sketch summary" << std::endl;
+ string<A> str(get_allocator());
+ str.append("### Tuple sketch summary:\n");
+ str.append(" num retained entries : ").append(std::to_string(get_num_retained())).append("\n");
+ str.append(" seed hash : ").append(std::to_string(get_seed_hash())).append("\n");
+ str.append(" empty? : ").append(is_empty() ? "true\n" : "false\n");
+ str.append(" ordered? : ").append(is_ordered() ? "true\n" : "false\n");
+ str.append(" estimation mode? : ").append(is_estimation_mode() ? "true\n" : "false\n");
+ str.append(" theta (fraction) : ").append(std::to_string(get_theta())).append("\n");
+ str.append(" theta (raw 64-bit) : ").append(std::to_string(get_theta64())).append("\n");
+ str.append(" estimate : ").append(std::to_string(this->get_estimate())).append("\n");
+ str.append(" lower bound 95% conf : ").append(std::to_string(this->get_lower_bound(2))).append("\n");
+ str.append(" upper bound 95% conf : ").append(std::to_string(this->get_upper_bound(2))).append("\n");
+ str.append(print_specifics());
+ str.append("### End sketch summary\n");
if (detail) {
- os << "### Retained entries" << std::endl;
+ str.append("### Retained entries\n");
for (const auto& it: *this) {
- os << it.first << ": " << it.second << std::endl;
+ str.append(std::to_string(it.first)).append(": ").append(ToStr()(it.second)).append("\n");
}
- os << "### End retained entries" << std::endl;
+ str.append("### End retained entries\n");
}
- return os.str();
+ return str;
}
// update sketch
@@ -238,10 +239,12 @@ compact_tuple_sketch<S, A> update_tuple_sketch<S, U, P, A>::compact(bool ordered
}
template<typename S, typename U, typename P, typename A>
-void update_tuple_sketch<S, U, P, A>::print_specifics(ostrstream& os) const {
- os << " lg nominal size : " << (int) map_.lg_nom_size_ << std::endl;
- os << " lg current size : " << (int) map_.lg_cur_size_ << std::endl;
- os << " resize factor : " << (1 << map_.rf_) << std::endl;
+string<A> update_tuple_sketch<S, U, P, A>::print_specifics() const {
+ string<A> str(get_allocator());
+ str.append(" lg nominal size : ").append(std::to_string(map_.lg_nom_size_)).append("\n");
+ str.append(" lg current size : ").append(std::to_string(map_.lg_cur_size_)).append("\n");
+ str.append(" resize factor : ").append(std::to_string(1 << map_.rf_)).append("\n");
+ return str;
}
// compact sketch
@@ -554,7 +557,9 @@ auto compact_tuple_sketch<S, A>::end() const -> const_iterator {
}
template<typename S, typename A>
-void compact_tuple_sketch<S, A>::print_specifics(ostrstream&) const {}
+string<A> compact_tuple_sketch<S, A>::print_specifics() const {
+ return string<A>(get_allocator());
+}
// builder
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org