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/07/14 23:11:53 UTC

[incubator-datasketches-cpp] branch tuple_sketch updated: common to_string

This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch tuple_sketch
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git


The following commit(s) were added to refs/heads/tuple_sketch by this push:
     new 70ac43a  common to_string
70ac43a is described below

commit 70ac43a4e6092bffe161d40477dca5e0cd964c1b
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Jul 14 16:11:42 2020 -0700

    common to_string
---
 tuple/include/theta_update_sketch_base.hpp      |  1 -
 tuple/include/theta_update_sketch_base_impl.hpp |  1 -
 tuple/include/tuple_sketch.hpp                  | 14 ++--
 tuple/include/tuple_sketch_impl.hpp             | 86 +++++++++++--------------
 4 files changed, 48 insertions(+), 54 deletions(-)

diff --git a/tuple/include/theta_update_sketch_base.hpp b/tuple/include/theta_update_sketch_base.hpp
index 1356c21..46d9cf6 100644
--- a/tuple/include/theta_update_sketch_base.hpp
+++ b/tuple/include/theta_update_sketch_base.hpp
@@ -73,7 +73,6 @@ struct theta_update_sketch_base {
   uint8_t lg_cur_size_;
   uint8_t lg_nom_size_;
   resize_factor rf_;
-  float p_;
   uint32_t num_entries_;
   uint64_t theta_;
   uint64_t seed_;
diff --git a/tuple/include/theta_update_sketch_base_impl.hpp b/tuple/include/theta_update_sketch_base_impl.hpp
index 78b4cc9..793113b 100644
--- a/tuple/include/theta_update_sketch_base_impl.hpp
+++ b/tuple/include/theta_update_sketch_base_impl.hpp
@@ -29,7 +29,6 @@ is_empty_(true),
 lg_cur_size_(lg_cur_size),
 lg_nom_size_(lg_nom_size),
 rf_(rf),
-p_(p),
 num_entries_(0),
 theta_(theta_constants::MAX_THETA),
 seed_(seed),
diff --git a/tuple/include/tuple_sketch.hpp b/tuple/include/tuple_sketch.hpp
index 3409557..977bf10 100644
--- a/tuple/include/tuple_sketch.hpp
+++ b/tuple/include/tuple_sketch.hpp
@@ -101,10 +101,11 @@ public:
   virtual bool is_ordered() const = 0;
 
   /**
-   * Writes a human-readable summary of this sketch to a given stream
+   * Provides a human-readable summary of this sketch as a string
    * @param print_items if true include the list of items retained by the sketch
+   * @return sketch summary as a string
    */
-  virtual string<Allocator> to_string(bool print_items = false) const = 0;
+  string<Allocator> to_string(bool print_items = false) const;
 
   /**
    * Iterator over entries in this sketch.
@@ -135,6 +136,8 @@ public:
 protected:
   enum flags { IS_BIG_ENDIAN, IS_READ_ONLY, IS_EMPTY, IS_COMPACT, IS_ORDERED };
 
+  virtual void print_specifics(std::ostringstream& os) const = 0;
+
   static uint16_t get_seed_hash(uint64_t seed);
 
   static void check_sketch_type(uint8_t actual, uint8_t expected);
@@ -184,7 +187,6 @@ public:
   virtual uint64_t get_theta64() const;
   virtual uint32_t get_num_retained() const;
   virtual uint16_t get_seed_hash() const;
-  virtual string<Allocator> to_string(bool print_items = false) const;
 
   /**
    * @return configured nominal number of entries in the sketch
@@ -320,6 +322,8 @@ private:
 
   // for builder
   update_tuple_sketch(uint8_t lg_cur_size, uint8_t lg_nom_size, resize_factor rf, float p, uint64_t seed, const Policy& policy);
+
+  virtual void print_specifics(std::ostringstream& os) const;
 };
 
 // compact sketch
@@ -357,7 +361,6 @@ public:
   virtual uint64_t get_theta64() const;
   virtual uint32_t get_num_retained() const;
   virtual uint16_t get_seed_hash() const;
-  virtual string<Allocator> to_string(bool print_items = false) const;
 
   template<typename SerDe = serde<Summary>>
   void serialize(std::ostream& os, const SerDe& sd = SerDe()) const;
@@ -434,6 +437,9 @@ private:
     uint32_t num;
     bool destroy;
   };
+
+  virtual void print_specifics(std::ostringstream& os) const;
+
 };
 
 // builder
diff --git a/tuple/include/tuple_sketch_impl.hpp b/tuple/include/tuple_sketch_impl.hpp
index ae09cfe..23a5a3b 100644
--- a/tuple/include/tuple_sketch_impl.hpp
+++ b/tuple/include/tuple_sketch_impl.hpp
@@ -51,6 +51,34 @@ double tuple_sketch<S, A>::get_upper_bound(uint8_t num_std_devs) const {
   return binomial_bounds::get_upper_bound(get_num_retained(), get_theta(), num_std_devs);
 }
 
+template<typename S, typename A>
+string<A> tuple_sketch<S, A>::to_string(bool detail) const {
+  std::basic_ostringstream<char, std::char_traits<char>, AllocChar<A>> 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;
+  if (detail) {
+    os << "### Retained entries" << std::endl;
+    for (const auto& it: *this) {
+      if (it.first != 0) {
+        os << it.first << ": " << it.second << std::endl;
+      }
+    }
+    os << "### End retained entries" << std::endl;
+  }
+  return os.str();
+}
+
 // update sketch
 
 template<typename S, typename U, typename P, typename A>
@@ -182,23 +210,6 @@ void update_tuple_sketch<S, U, P, A>::trim() {
 }
 
 template<typename S, typename U, typename P, typename A>
-string<A> update_tuple_sketch<S, U, P, A>::to_string(bool detail) const {
-  std::basic_ostringstream<char, std::char_traits<char>, AllocChar<A>> os;
-  auto type = typeid(*this).name();
-  os << "sizeof(" << type << ")=" << sizeof(*this) << std::endl;
-  os << "sizeof(entry)=" << sizeof(Entry) << std::endl;
-  os << map_.to_string();
-  if (detail) {
-    for (const auto& it: map_) {
-      if (it.first != 0) {
-        os << it.first << ": " << it.second << std::endl;
-      }
-    }
-  }
-  return os.str();
-}
-
-template<typename S, typename U, typename P, typename A>
 auto update_tuple_sketch<S, U, P, A>::begin() -> iterator {
   return iterator(map_.entries_, 1 << map_.lg_cur_size_, 0);
 }
@@ -223,6 +234,13 @@ compact_tuple_sketch<S, A> update_tuple_sketch<S, U, P, A>::compact(bool ordered
   return compact_tuple_sketch<S, A>(*this, ordered);
 }
 
+template<typename S, typename U, typename P, typename A>
+void update_tuple_sketch<S, U, P, A>::print_specifics(std::ostringstream& 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;
+}
+
 // compact sketch
 
 template<typename S, typename A>
@@ -272,37 +290,6 @@ uint16_t compact_tuple_sketch<S, A>::get_seed_hash() const {
   return seed_hash_;
 }
 
-template<typename S, typename A>
-string<A> compact_tuple_sketch<S, A>::to_string(bool detail) const {
-  std::basic_ostringstream<char, std::char_traits<char>, AllocChar<A>> os;
-  os << "### Compact Tuple sketch summary:" << std::endl;
-  auto type = typeid(*this).name();
-  os << "   type                 : " << type << std::endl;
-  os << "   sizeof(type)         : " << sizeof(*this) << std::endl;
-  os << "   sizeof(entry)        : " << sizeof(Entry) << std::endl;
-  os << "   num retained entries : " << entries_.size() << std::endl;
-  os << "   seed hash            : " << this->get_seed_hash() << std::endl;
-  os << "   empty?               : " << (this->is_empty() ? "true" : "false") << std::endl;
-  os << "   ordered?             : " << (this->is_ordered() ? "true" : "false") << std::endl;
-  os << "   estimation mode?     : " << (this->is_estimation_mode() ? "true" : "false") << std::endl;
-  os << "   theta (fraction)     : " << this->get_theta() << std::endl;
-  os << "   theta (raw 64-bit)   : " << this->theta_ << 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;
-  os << "### End sketch summary" << std::endl;
-  if (detail) {
-    os << "### Retained entries" << std::endl;
-    for (const auto& it: entries_) {
-      if (it.first != 0) {
-        os << it.first << ": " << it.second << std::endl;
-      }
-    }
-    os << "### End retained entries" << std::endl;
-  }
-  return os.str();
-}
-
 // implementation for fixed-size arithmetic types (integral and floating point)
 template<typename S, typename A>
 template<typename SD, typename SS, typename std::enable_if<std::is_arithmetic<SS>::value, int>::type>
@@ -455,6 +442,9 @@ auto compact_tuple_sketch<S, A>::end() const -> const_iterator {
   return const_iterator(nullptr, 0, entries_.size());
 }
 
+template<typename S, typename A>
+void compact_tuple_sketch<S, A>::print_specifics(std::ostringstream&) const {}
+
 // builder
 
 template<typename S, typename U, typename P, typename A>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org