You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by jm...@apache.org on 2020/04/16 05:47:03 UTC

[incubator-datasketches-cpp] branch common_cleanup created (now 188d1cc)

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

jmalkin pushed a change to branch common_cleanup
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git.


      at 188d1cc  define single DEFAULT_SEED and zero-counting class, clean up python manifest

This branch includes the following new commits:

     new 188d1cc  define single DEFAULT_SEED and zero-counting class, clean up python manifest

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


[incubator-datasketches-cpp] 01/01: define single DEFAULT_SEED and zero-counting class, clean up python manifest

Posted by jm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 188d1cc7e99689c500d788bde005fdeaedabc051
Author: Jon Malkin <jm...@users.noreply.github.com>
AuthorDate: Wed Apr 15 22:46:37 2020 -0700

    define single DEFAULT_SEED and zero-counting class, clean up python manifest
---
 MANIFEST.in                                        | 21 ++++---
 common/CMakeLists.txt                              |  8 ++-
 common/include/CommonUtil.hpp                      | 71 ----------------------
 .../include/common_defs.hpp                        | 38 ++----------
 .../include/count_zeros.hpp                        | 15 ++++-
 cpc/CMakeLists.txt                                 |  2 -
 cpc/include/cpc_common.hpp                         |  1 -
 cpc/include/cpc_compressor_impl.hpp                |  3 +-
 cpc/include/cpc_sketch.hpp                         |  1 +
 cpc/include/cpc_sketch_impl.hpp                    |  1 +
 cpc/include/cpc_union.hpp                          |  1 +
 cpc/include/cpc_union_impl.hpp                     |  2 +
 hll/include/HllSketch-internal.hpp                 | 19 +++---
 hll/include/HllUtil.hpp                            | 54 +++-------------
 python/src/cpc_wrapper.cpp                         |  6 +-
 python/src/theta_wrapper.cpp                       | 37 ++++++-----
 sampling/include/var_opt_sketch.hpp                |  3 +-
 sampling/include/var_opt_sketch_impl.hpp           | 24 ++------
 theta/include/theta_a_not_b.hpp                    |  5 +-
 theta/include/theta_intersection.hpp               |  5 +-
 theta/include/theta_sketch.hpp                     | 15 ++---
 21 files changed, 103 insertions(+), 229 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index bacfbbf..8d598c3 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,14 +1,19 @@
 global-include CMakeLists.txt
-global-include .cmake
-global-include .cpp
-global-include .c
-global-include .hpp
-global-include .h
-global-include .bin
-global-include .cmake
+global-include *.cpp
+global-include *.c
+global-include *.hpp
+global-include *.h
+global-include *.bin
 
 global-exclude .git*
 
 recursive-include python/pybind11 *
 
-graft cmake common cpc fi hll kll theta python
+graft common
+graft cpc
+graft fi
+graft hll
+graft kll
+graft theta
+graft sampling
+graft python
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index 9f8484b..624c3d6 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -23,14 +23,18 @@ endif()
 
 target_include_directories(common
   INTERFACE
-    include
+    $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
+    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
 )
 
+target_compile_features(common INTERFACE cxx_std_11)
+
 target_sources(common
   INTERFACE
+    ${CMAKE_CURRENT_SOURCE_DIR}/include/common_defs.hpp
     ${CMAKE_CURRENT_SOURCE_DIR}/include/MurmurHash3.h
     ${CMAKE_CURRENT_SOURCE_DIR}/include/serde.hpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/include/CommonUtil.hpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/include/count_zeros.hpp
     ${CMAKE_CURRENT_SOURCE_DIR}/include/inv_pow2_table.hpp
 )
 
diff --git a/common/include/CommonUtil.hpp b/common/include/CommonUtil.hpp
deleted file mode 100644
index 55e7dfc..0000000
--- a/common/include/CommonUtil.hpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// author Kevin Lang, Yahoo Research
-// author Jon Malkin, Yahoo Research
-
-#ifndef _COMMONUTIL_HPP_
-#define _COMMONUTIL_HPP_
-
-#include <cstdint>
-
-namespace datasketches {
-
-class CommonUtil final {
-  public:
-    static unsigned int getNumberOfLeadingZeros(uint64_t x);
-};
-
-#define FCLZ_MASK_56 ((uint64_t) 0x00ffffffffffffff)
-#define FCLZ_MASK_48 ((uint64_t) 0x0000ffffffffffff)
-#define FCLZ_MASK_40 ((uint64_t) 0x000000ffffffffff)
-#define FCLZ_MASK_32 ((uint64_t) 0x00000000ffffffff)
-#define FCLZ_MASK_24 ((uint64_t) 0x0000000000ffffff)
-#define FCLZ_MASK_16 ((uint64_t) 0x000000000000ffff)
-#define FCLZ_MASK_08 ((uint64_t) 0x00000000000000ff)
-
-inline unsigned int CommonUtil::getNumberOfLeadingZeros(const uint64_t x) {
-  if (x == 0)
-    return 64;
-
-  static const uint8_t clzByteCount[256] = {8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, [...]
-
-  if (x > FCLZ_MASK_56)
-    return ((unsigned int) ( 0 + clzByteCount[(x >> 56) & FCLZ_MASK_08]));
-  if (x > FCLZ_MASK_48)
-    return ((unsigned int) ( 8 + clzByteCount[(x >> 48) & FCLZ_MASK_08]));
-  if (x > FCLZ_MASK_40)
-    return ((unsigned int) (16 + clzByteCount[(x >> 40) & FCLZ_MASK_08]));
-  if (x > FCLZ_MASK_32)
-    return ((unsigned int) (24 + clzByteCount[(x >> 32) & FCLZ_MASK_08]));
-  if (x > FCLZ_MASK_24)
-    return ((unsigned int) (32 + clzByteCount[(x >> 24) & FCLZ_MASK_08]));
-  if (x > FCLZ_MASK_16)
-    return ((unsigned int) (40 + clzByteCount[(x >> 16) & FCLZ_MASK_08]));
-  if (x > FCLZ_MASK_08)
-    return ((unsigned int) (48 + clzByteCount[(x >>  8) & FCLZ_MASK_08]));
-  if (1)
-    return ((unsigned int) (56 + clzByteCount[(x >>  0) & FCLZ_MASK_08]));
-
-}
-
-
-}
-
-#endif // _COMMONUTIL_HPP_
\ No newline at end of file
diff --git a/theta/include/theta_a_not_b.hpp b/common/include/common_defs.hpp
similarity index 50%
copy from theta/include/theta_a_not_b.hpp
copy to common/include/common_defs.hpp
index a45c82f..0117ce4 100644
--- a/theta/include/theta_a_not_b.hpp
+++ b/common/include/common_defs.hpp
@@ -17,41 +17,15 @@
  * under the License.
  */
 
-#ifndef THETA_A_NOT_B_HPP_
-#define THETA_A_NOT_B_HPP_
+#ifndef _COMMON_DEFS_HPP_
+#define _COMMON_DEFS_HPP_
 
-#include <memory>
-#include <functional>
-#include <climits>
-
-#include <theta_sketch.hpp>
+#include <cstdint>
 
 namespace datasketches {
 
-/*
- * author Alexander Saydakov
- * author Lee Rhodes
- * author Kevin Lang
- */
-
-template<typename A>
-class theta_a_not_b_alloc {
-public:
-  explicit theta_a_not_b_alloc(uint64_t seed = update_theta_sketch_alloc<A>::builder::DEFAULT_SEED);
-
-  compact_theta_sketch_alloc<A> compute(const theta_sketch_alloc<A>& a, const theta_sketch_alloc<A>& b, bool ordered = true) const;
-
-private:
-  typedef typename std::allocator_traits<A>::template rebind_alloc<uint64_t> AllocU64;
-  uint16_t seed_hash_;
-
-};
-
-// alias with default allocator for convenience
-typedef theta_a_not_b_alloc<std::allocator<void>> theta_a_not_b;
-
-} /* namespace datasketches */
+static const uint64_t DEFAULT_SEED = 9001;
 
-#include "theta_a_not_b_impl.hpp"
+} // namespace
 
-# endif
+#endif // _COMMON_DEFS_HPP_
\ No newline at end of file
diff --git a/cpc/include/counter_of_zeros.hpp b/common/include/count_zeros.hpp
similarity index 92%
rename from cpc/include/counter_of_zeros.hpp
rename to common/include/count_zeros.hpp
index eb2036e..0c9f6b4 100644
--- a/cpc/include/counter_of_zeros.hpp
+++ b/common/include/count_zeros.hpp
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-#ifndef COUNT_ZEROS_HPP_
-#define COUNT_ZEROS_HPP_
+#ifndef _COUNT_ZEROS_HPP_
+#define _COUNT_ZEROS_HPP_
 
 #include <cstdint>
 
@@ -91,6 +91,15 @@ static inline uint8_t count_leading_zeros_in_u64(uint64_t input) {
     return 56 + byte_leading_zeros_table[(input      ) & FCLZ_MASK_08];
 }
 
+static inline uint8_t count_trailing_zeros_in_u32(uint32_t input) {
+  for (int i = 0; i < 4; i++) {
+    const int byte = input & 0xff;
+    if (byte != 0) return (i << 3) + byte_trailing_zeros_table[byte];
+    input >>= 8;
+  }
+  return 32;
+}
+
 static inline uint8_t count_trailing_zeros_in_u64(uint64_t input) {
   for (int i = 0; i < 8; i++) {
     const int byte = input & 0xff;
@@ -102,4 +111,4 @@ static inline uint8_t count_trailing_zeros_in_u64(uint64_t input) {
 
 } /* namespace datasketches */
 
-#endif
+#endif // _COUNT_ZEROS_HPP_
diff --git a/cpc/CMakeLists.txt b/cpc/CMakeLists.txt
index 8a97d87..7f4faf3 100644
--- a/cpc/CMakeLists.txt
+++ b/cpc/CMakeLists.txt
@@ -34,7 +34,6 @@ target_compile_features(cpc INTERFACE cxx_std_11)
 
 set(cpc_HEADERS "")
 list(APPEND cpc_HEADERS "include/compression_data.hpp")
-list(APPEND cpc_HEADERS "include/counter_of_zeros.hpp")
 list(APPEND cpc_HEADERS "include/cpc_common.hpp")
 list(APPEND cpc_HEADERS "include/cpc_compressor.hpp")
 list(APPEND cpc_HEADERS "include/cpc_compressor_impl.hpp")
@@ -59,7 +58,6 @@ install(FILES ${cpc_HEADERS}
 target_sources(cpc
   INTERFACE
     ${CMAKE_CURRENT_SOURCE_DIR}/include/compression_data.hpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/include/counter_of_zeros.hpp
     ${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_common.hpp
     ${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_compressor.hpp
     ${CMAKE_CURRENT_SOURCE_DIR}/include/cpc_compressor_impl.hpp
diff --git a/cpc/include/cpc_common.hpp b/cpc/include/cpc_common.hpp
index c6254df..9a766b8 100644
--- a/cpc/include/cpc_common.hpp
+++ b/cpc/include/cpc_common.hpp
@@ -29,7 +29,6 @@ namespace datasketches {
 static const uint8_t CPC_MIN_LG_K = 4;
 static const uint8_t CPC_MAX_LG_K = 26;
 static const uint8_t CPC_DEFAULT_LG_K = 11;
-static const uint64_t DEFAULT_SEED = 9001;
 
 template<typename A> using AllocU8 = typename std::allocator_traits<A>::template rebind_alloc<uint8_t>;
 template<typename A> using AllocU16 = typename std::allocator_traits<A>::template rebind_alloc<uint16_t>;
diff --git a/cpc/include/cpc_compressor_impl.hpp b/cpc/include/cpc_compressor_impl.hpp
index fdafd3f..b951b05 100644
--- a/cpc/include/cpc_compressor_impl.hpp
+++ b/cpc/include/cpc_compressor_impl.hpp
@@ -25,10 +25,9 @@
 #include <memory>
 
 #include "compression_data.hpp"
-#include "counter_of_zeros.hpp"
 #include "cpc_util.hpp"
-
 #include "cpc_common.hpp"
+#include "count_zeros.hpp"
 
 namespace datasketches {
 
diff --git a/cpc/include/cpc_sketch.hpp b/cpc/include/cpc_sketch.hpp
index f6df2c2..5b687ab 100644
--- a/cpc/include/cpc_sketch.hpp
+++ b/cpc/include/cpc_sketch.hpp
@@ -29,6 +29,7 @@
 #include "cpc_common.hpp"
 #include "cpc_compressor.hpp"
 #include "cpc_confidence.hpp"
+#include "common_defs.hpp"
 
 namespace datasketches {
 
diff --git a/cpc/include/cpc_sketch_impl.hpp b/cpc/include/cpc_sketch_impl.hpp
index 449d9c9..82df380 100644
--- a/cpc/include/cpc_sketch_impl.hpp
+++ b/cpc/include/cpc_sketch_impl.hpp
@@ -30,6 +30,7 @@
 #include "cpc_util.hpp"
 #include "icon_estimator.hpp"
 #include "serde.hpp"
+#include "count_zeros.hpp"
 
 namespace datasketches {
 
diff --git a/cpc/include/cpc_union.hpp b/cpc/include/cpc_union.hpp
index bc06975..a226ec2 100644
--- a/cpc/include/cpc_union.hpp
+++ b/cpc/include/cpc_union.hpp
@@ -23,6 +23,7 @@
 #include <string>
 
 #include "cpc_sketch.hpp"
+#include "common_defs.hpp"
 
 namespace datasketches {
 
diff --git a/cpc/include/cpc_union_impl.hpp b/cpc/include/cpc_union_impl.hpp
index 7676919..a63da9c 100644
--- a/cpc/include/cpc_union_impl.hpp
+++ b/cpc/include/cpc_union_impl.hpp
@@ -20,6 +20,8 @@
 #ifndef CPC_UNION_IMPL_HPP_
 #define CPC_UNION_IMPL_HPP_
 
+#include "count_zeros.hpp"
+
 namespace datasketches {
 
 template<typename A>
diff --git a/hll/include/HllSketch-internal.hpp b/hll/include/HllSketch-internal.hpp
index 6587fe8..f05852e 100644
--- a/hll/include/HllSketch-internal.hpp
+++ b/hll/include/HllSketch-internal.hpp
@@ -25,6 +25,7 @@
 #include "HllSketchImplFactory.hpp"
 #include "CouponList.hpp"
 #include "HllArray.hpp"
+#include "common_defs.hpp"
 
 #include <cstdio>
 #include <cstdlib>
@@ -123,7 +124,7 @@ template<typename A>
 void hll_sketch_alloc<A>::update(const std::string& datum) {
   if (datum.empty()) { return; }
   HashState hashResult;
-  HllUtil<A>::hash(datum.c_str(), datum.length(), HllUtil<A>::DEFAULT_UPDATE_SEED, hashResult);
+  HllUtil<A>::hash(datum.c_str(), datum.length(), DEFAULT_SEED, hashResult);
   coupon_update(HllUtil<A>::coupon(hashResult));
 }
 
@@ -131,7 +132,7 @@ template<typename A>
 void hll_sketch_alloc<A>::update(const uint64_t datum) {
   // no sign extension with 64 bits so no need to cast to signed value
   HashState hashResult;
-  HllUtil<A>::hash(&datum, sizeof(uint64_t), HllUtil<A>::DEFAULT_UPDATE_SEED, hashResult);
+  HllUtil<A>::hash(&datum, sizeof(uint64_t), DEFAULT_SEED, hashResult);
   coupon_update(HllUtil<A>::coupon(hashResult));
 }
 
@@ -153,7 +154,7 @@ void hll_sketch_alloc<A>::update(const uint8_t datum) {
 template<typename A>
 void hll_sketch_alloc<A>::update(const int64_t datum) {
   HashState hashResult;
-  HllUtil<A>::hash(&datum, sizeof(int64_t), HllUtil<A>::DEFAULT_UPDATE_SEED, hashResult);
+  HllUtil<A>::hash(&datum, sizeof(int64_t), DEFAULT_SEED, hashResult);
   coupon_update(HllUtil<A>::coupon(hashResult));
 }
 
@@ -161,7 +162,7 @@ template<typename A>
 void hll_sketch_alloc<A>::update(const int32_t datum) {
   int64_t val = static_cast<int64_t>(datum);
   HashState hashResult;
-  HllUtil<A>::hash(&val, sizeof(int64_t), HllUtil<A>::DEFAULT_UPDATE_SEED, hashResult);
+  HllUtil<A>::hash(&val, sizeof(int64_t), DEFAULT_SEED, hashResult);
   coupon_update(HllUtil<A>::coupon(hashResult));
 }
 
@@ -169,7 +170,7 @@ template<typename A>
 void hll_sketch_alloc<A>::update(const int16_t datum) {
   int64_t val = static_cast<int64_t>(datum);
   HashState hashResult;
-  HllUtil<A>::hash(&val, sizeof(int64_t), HllUtil<A>::DEFAULT_UPDATE_SEED, hashResult);
+  HllUtil<A>::hash(&val, sizeof(int64_t), DEFAULT_SEED, hashResult);
   coupon_update(HllUtil<A>::coupon(hashResult));
 }
 
@@ -177,7 +178,7 @@ template<typename A>
 void hll_sketch_alloc<A>::update(const int8_t datum) {
   int64_t val = static_cast<int64_t>(datum);
   HashState hashResult;
-  HllUtil<A>::hash(&val, sizeof(int64_t), HllUtil<A>::DEFAULT_UPDATE_SEED, hashResult);
+  HllUtil<A>::hash(&val, sizeof(int64_t), DEFAULT_SEED, hashResult);
   coupon_update(HllUtil<A>::coupon(hashResult));
 }
 
@@ -191,7 +192,7 @@ void hll_sketch_alloc<A>::update(const double datum) {
     d.longBytes = 0x7ff8000000000000L; // canonicalize NaN using value from Java's Double.doubleToLongBits()
   }
   HashState hashResult;
-  HllUtil<A>::hash(&d, sizeof(double), HllUtil<A>::DEFAULT_UPDATE_SEED, hashResult);
+  HllUtil<A>::hash(&d, sizeof(double), DEFAULT_SEED, hashResult);
   coupon_update(HllUtil<A>::coupon(hashResult));
 }
 
@@ -205,7 +206,7 @@ void hll_sketch_alloc<A>::update(const float datum) {
     d.longBytes = 0x7ff8000000000000L; // canonicalize NaN using value from Java's Double.doubleToLongBits()
   }
   HashState hashResult;
-  HllUtil<A>::hash(&d, sizeof(double), HllUtil<A>::DEFAULT_UPDATE_SEED, hashResult);
+  HllUtil<A>::hash(&d, sizeof(double), DEFAULT_SEED, hashResult);
   coupon_update(HllUtil<A>::coupon(hashResult));
 }
 
@@ -213,7 +214,7 @@ template<typename A>
 void hll_sketch_alloc<A>::update(const void* data, const size_t lengthBytes) {
   if (data == nullptr) { return; }
   HashState hashResult;
-  HllUtil<A>::hash(data, lengthBytes, HllUtil<A>::DEFAULT_UPDATE_SEED, hashResult);
+  HllUtil<A>::hash(data, lengthBytes, DEFAULT_SEED, hashResult);
   coupon_update(HllUtil<A>::coupon(hashResult));
 }
 
diff --git a/hll/include/HllUtil.hpp b/hll/include/HllUtil.hpp
index eb956bc..8408d37 100644
--- a/hll/include/HllUtil.hpp
+++ b/hll/include/HllUtil.hpp
@@ -22,7 +22,8 @@
 
 #include "MurmurHash3.h"
 #include "RelativeErrorTables.hpp"
-#include "CommonUtil.hpp"
+#include "count_zeros.hpp"
+#include "common_defs.hpp"
 
 #include <cmath>
 #include <stdexcept>
@@ -83,8 +84,6 @@ public:
   static const int MIN_LOG_K = 4;
   static const int MAX_LOG_K = 21;
 
-  static const uint64_t DEFAULT_UPDATE_SEED = 9001L;
-
   static const double HLL_HIP_RSE_FACTOR; // sqrt(log(2.0)) = 0.8325546
   static const double HLL_NON_HIP_RSE_FACTOR; // sqrt((3.0 * log(2.0)) - 1.0) = 1.03896
   static const double COUPON_RSE_FACTOR; // 0.409 at transition point not the asymptote
@@ -108,7 +107,6 @@ public:
   static int coupon(const uint64_t hash[]);
   static int coupon(const HashState& hashState);
   static void hash(const void* key, int keyLen, uint64_t seed, HashState& result);
-
   static int checkLgK(int lgK);
   static void checkMemSize(uint64_t minBytes, uint64_t capBytes);
   static inline void checkNumStdDev(int numStdDev);
@@ -118,8 +116,6 @@ public:
   static double invPow2(int e);
   static unsigned int ceilingPowerOf2(unsigned int n);
   static unsigned int simpleIntLog2(unsigned int n); // n must be power of 2
-  static unsigned int getNumberOfLeadingZeros(uint64_t x);
-  static unsigned int numberOfTrailingZeros(uint32_t n);
   static int computeLgArrInts(hll_mode mode, int count, int lgConfigK);
   static double getRelErr(bool upperBound, bool unioned,
                           int lgConfigK, int numStdDev);
@@ -144,7 +140,7 @@ const int HllUtil<A>::LG_AUX_ARR_INTS[] = {
 template<typename A>
 inline int HllUtil<A>::coupon(const uint64_t hash[]) {
   int addr26 = (int) (hash[0] & KEY_MASK_26);
-  int lz = CommonUtil::getNumberOfLeadingZeros(hash[1]);
+  int lz = count_leading_zeros_in_u64(hash[1]);
   int value = ((lz > 62 ? 62 : lz) + 1); 
   return (value << KEY_BITS_26) | addr26;
 }
@@ -152,14 +148,14 @@ inline int HllUtil<A>::coupon(const uint64_t hash[]) {
 template<typename A>
 inline int HllUtil<A>::coupon(const HashState& hashState) {
   int addr26 = (int) (hashState.h1 & KEY_MASK_26);
-  int lz = CommonUtil::getNumberOfLeadingZeros(hashState.h2);  
+  int lz = count_leading_zeros_in_u64(hashState.h2);  
   int value = ((lz > 62 ? 62 : lz) + 1); 
   return (value << KEY_BITS_26) | addr26;
 }
 
 template<typename A>
 inline void HllUtil<A>::hash(const void* key, const int keyLen, const uint64_t seed, HashState& result) {
-  MurmurHash3_x64_128(key, keyLen, DEFAULT_UPDATE_SEED, result);
+  MurmurHash3_x64_128(key, keyLen, DEFAULT_SEED, result);
 }
 
 template<typename A>
@@ -219,7 +215,7 @@ inline double HllUtil<A>::invPow2(const int e) {
 // compute the next highest power of 2 of 32-bit n
 // taken from https://graphics.stanford.edu/~seander/bithacks.html
 template<typename A>
-inline unsigned int HllUtil<A>::ceilingPowerOf2(unsigned int n) {
+inline uint32_t HllUtil<A>::ceilingPowerOf2(uint32_t n) {
   --n;
   n |= n >> 1;
   n |= n >> 2;
@@ -230,45 +226,11 @@ inline unsigned int HllUtil<A>::ceilingPowerOf2(unsigned int n) {
 }
 
 template<typename A>
-inline unsigned int HllUtil<A>::simpleIntLog2(unsigned int n) {
+inline uint32_t HllUtil<A>::simpleIntLog2(uint32_t n) {
   if (n == 0) {
     throw std::logic_error("cannot take log of 0");
   }
-  const unsigned int e = numberOfTrailingZeros(n);
-  return e;
-}
-
-// taken from https://graphics.stanford.edu/~seander/bithacks.html
-// input is 32-bit word to count zero bits on right
-template<typename A>
-inline unsigned int HllUtil<A>::numberOfTrailingZeros(uint32_t v) {
-  unsigned int c;     // c will be the number of zero bits on the right,
-                      // so if v is 1101000 (base 2), then c will be 3
-  // NOTE: if 0 == v, then c = 31.
-  if (v & 0x1) {
-    // special case for odd v (assumed to happen half of the time)
-    c = 0;
-  } else {
-    c = 1;
-    if ((v & 0xffff) == 0) {  
-      v >>= 16;  
-      c += 16;
-    }
-    if ((v & 0xff) == 0) {  
-      v >>= 8;  
-      c += 8;
-    }
-    if ((v & 0xf) == 0) {  
-      v >>= 4;
-      c += 4;
-    }
-    if ((v & 0x3) == 0) {  
-      v >>= 2;
-      c += 2;
-    }
-    c -= v & 0x1;
-  }
-  return c;	
+  return count_trailing_zeros_in_u32(n);
 }
 
 template<typename A>
diff --git a/python/src/cpc_wrapper.cpp b/python/src/cpc_wrapper.cpp
index 9017010..0ccfe56 100644
--- a/python/src/cpc_wrapper.cpp
+++ b/python/src/cpc_wrapper.cpp
@@ -17,13 +17,13 @@
  * under the License.
  */
 
+#include <sstream>
+#include <pybind11/pybind11.h>
 
 #include "cpc_sketch.hpp"
 #include "cpc_union.hpp"
 #include "cpc_common.hpp"
-
-#include <pybind11/pybind11.h>
-#include <sstream>
+#include "common_defs.hpp"
 
 namespace py = pybind11;
 
diff --git a/python/src/theta_wrapper.cpp b/python/src/theta_wrapper.cpp
index 5eb27e8..25b916a 100644
--- a/python/src/theta_wrapper.cpp
+++ b/python/src/theta_wrapper.cpp
@@ -17,13 +17,15 @@
  * under the License.
  */
 
-#include <theta_sketch.hpp>
-#include <theta_union.hpp>
-#include <theta_intersection.hpp>
-#include <theta_a_not_b.hpp>
-
-#include <pybind11/pybind11.h>
 #include <sstream>
+#include <pybind11/pybind11.h>
+
+#include "theta_sketch.hpp"
+#include "theta_union.hpp"
+#include "theta_intersection.hpp"
+#include "theta_a_not_b.hpp"
+#include "common_defs.hpp"
+
 
 namespace py = pybind11;
 
@@ -46,8 +48,7 @@ theta_union theta_union_factory(uint8_t lg_k, double p, uint64_t seed) {
   return builder.build();
 }
 
-theta_sketch* theta_sketch_deserialize(py::bytes skBytes,
-                                       uint64_t seed = update_theta_sketch::builder::DEFAULT_SEED) {
+theta_sketch* theta_sketch_deserialize(py::bytes skBytes, uint64_t seed) {
   std::string skStr = skBytes; // implicit cast  
   return theta_sketch::deserialize(skStr.c_str(), skStr.length(), seed).release();
 }
@@ -68,14 +69,12 @@ uint16_t theta_sketch_get_seed_hash(const theta_sketch& sk) {
   return sk.get_seed_hash();
 }
 
-update_theta_sketch update_theta_sketch_deserialize(py::bytes skBytes,
-                                                     uint64_t seed = update_theta_sketch::builder::DEFAULT_SEED) {
+update_theta_sketch update_theta_sketch_deserialize(py::bytes skBytes, uint64_t seed) {
   std::string skStr = skBytes; // implicit cast  
   return update_theta_sketch::deserialize(skStr.c_str(), skStr.length(), seed);
 }
 
-compact_theta_sketch compact_theta_sketch_deserialize(py::bytes skBytes,
-                                                      uint64_t seed = update_theta_sketch::builder::DEFAULT_SEED) {
+compact_theta_sketch compact_theta_sketch_deserialize(py::bytes skBytes, uint64_t seed) {
   std::string skStr = skBytes; // implicit cast  
   return compact_theta_sketch::deserialize(skStr.c_str(), skStr.length(), seed);
 }
@@ -90,7 +89,7 @@ void init_theta(py::module &m) {
 
   py::class_<theta_sketch>(m, "theta_sketch")
     .def("serialize", &dspy::theta_sketch_serialize)
-    .def_static("deserialize", &dspy::theta_sketch_deserialize, py::arg("bytes"), py::arg("seed")=update_theta_sketch::builder::DEFAULT_SEED)
+    .def_static("deserialize", &dspy::theta_sketch_deserialize, py::arg("bytes"), py::arg("seed")=DEFAULT_SEED)
     .def("__str__", &dspy::theta_sketch_to_string, py::arg("print_items")=false)
     .def("to_string", &dspy::theta_sketch_to_string, py::arg("print_items")=false)
     .def("is_empty", &theta_sketch::is_empty)
@@ -106,32 +105,32 @@ void init_theta(py::module &m) {
 
   py::class_<update_theta_sketch, theta_sketch>(m, "update_theta_sketch")
     .def(py::init(&dspy::update_theta_sketch_factory),
-         py::arg("lg_k")=update_theta_sketch::builder::DEFAULT_LG_K, py::arg("p")=1.0, py::arg("seed")=update_theta_sketch::builder::DEFAULT_SEED)
+         py::arg("lg_k")=update_theta_sketch::builder::DEFAULT_LG_K, py::arg("p")=1.0, py::arg("seed")=DEFAULT_SEED)
     .def(py::init<const update_theta_sketch&>())
     .def("update", (void (update_theta_sketch::*)(int64_t)) &update_theta_sketch::update, py::arg("datum"))
     .def("update", (void (update_theta_sketch::*)(double)) &update_theta_sketch::update, py::arg("datum"))
     .def("update", (void (update_theta_sketch::*)(const std::string&)) &update_theta_sketch::update, py::arg("datum"))
     .def("compact", &update_theta_sketch::compact, py::arg("ordered")=true)
     .def_static("deserialize", &dspy::update_theta_sketch_deserialize,
-        py::arg("bytes"), py::arg("seed")=update_theta_sketch::builder::DEFAULT_SEED)
+        py::arg("bytes"), py::arg("seed")=DEFAULT_SEED)
   ;
 
   py::class_<compact_theta_sketch, theta_sketch>(m, "compact_theta_sketch")
     .def(py::init<const compact_theta_sketch&>())
     .def(py::init<const theta_sketch&, bool>())
     .def_static("deserialize", &dspy::compact_theta_sketch_deserialize,
-        py::arg("bytes"), py::arg("seed")=update_theta_sketch::builder::DEFAULT_SEED)
+        py::arg("bytes"), py::arg("seed")=DEFAULT_SEED)
   ;
 
   py::class_<theta_union>(m, "theta_union")
     .def(py::init(&dspy::theta_union_factory),
-         py::arg("lg_k")=update_theta_sketch::builder::DEFAULT_LG_K, py::arg("p")=1.0, py::arg("seed")=update_theta_sketch::builder::DEFAULT_SEED)
+         py::arg("lg_k")=update_theta_sketch::builder::DEFAULT_LG_K, py::arg("p")=1.0, py::arg("seed")=DEFAULT_SEED)
     .def("update", &theta_union::update, py::arg("sketch"))
     .def("get_result", &theta_union::get_result, py::arg("ordered")=true)
   ;
 
   py::class_<theta_intersection>(m, "theta_intersection")
-    .def(py::init<uint64_t>(), py::arg("seed")=update_theta_sketch::builder::DEFAULT_SEED)
+    .def(py::init<uint64_t>(), py::arg("seed")=DEFAULT_SEED)
     .def(py::init<const theta_intersection&>())
     .def("update", &theta_intersection::update, py::arg("sketch"))
     .def("get_result", &theta_intersection::get_result, py::arg("ordered")=true)
@@ -139,7 +138,7 @@ void init_theta(py::module &m) {
   ;
 
   py::class_<theta_a_not_b>(m, "theta_a_not_b")
-    .def(py::init<uint64_t>(), py::arg("seed")=update_theta_sketch::builder::DEFAULT_SEED)
+    .def(py::init<uint64_t>(), py::arg("seed")=DEFAULT_SEED)
     .def("compute", &theta_a_not_b::compute, py::arg("a"), py::arg("b"), py::arg("ordered")=true)
   ;
 }
diff --git a/sampling/include/var_opt_sketch.hpp b/sampling/include/var_opt_sketch.hpp
index d45b0aa..c669792 100644
--- a/sampling/include/var_opt_sketch.hpp
+++ b/sampling/include/var_opt_sketch.hpp
@@ -199,14 +199,13 @@ class var_opt_sketch {
     // next method sets current_items_alloc_
     void validate_and_set_current_size(int preamble_longs);
 
-    // things to move to common utils and share among sketches
+    // things to move to common and be shared among sketches
     static uint32_t get_adjusted_size(int max_size, int resize_target);
     static uint32_t starting_sub_multiple(int lg_target, int lg_rf, int lg_min);
     static inline double pseudo_hypergeometric_ub_on_p(uint64_t n, uint32_t k, double sampling_rate);
     static inline double pseudo_hypergeometric_lb_on_p(uint64_t n, uint32_t k, double sampling_rate);
     static bool is_power_of_2(uint32_t v);
     static uint32_t to_log_2(uint32_t v);
-    static uint32_t count_trailing_zeros(uint32_t v);
     static uint32_t ceiling_power_of_2(uint32_t n);
     static inline uint32_t next_int(uint32_t max_value);
     static inline double next_double_exclude_zero();
diff --git a/sampling/include/var_opt_sketch_impl.hpp b/sampling/include/var_opt_sketch_impl.hpp
index c5b9909..bc10a80 100644
--- a/sampling/include/var_opt_sketch_impl.hpp
+++ b/sampling/include/var_opt_sketch_impl.hpp
@@ -20,10 +20,6 @@
 #ifndef _VAR_OPT_SKETCH_IMPL_HPP_
 #define _VAR_OPT_SKETCH_IMPL_HPP_
 
-#include "var_opt_sketch.hpp"
-#include "serde.hpp"
-#include "bounds_binomial_proportions.hpp"
-
 #include <memory>
 #include <sstream>
 #include <cmath>
@@ -31,6 +27,11 @@
 #include <algorithm>
 #include <cassert>
 
+#include "var_opt_sketch.hpp"
+#include "serde.hpp"
+#include "bounds_binomial_proportions.hpp"
+#include "count_zeros.hpp"
+
 namespace datasketches {
 
 /**
@@ -1534,7 +1535,7 @@ bool var_opt_sketch<T,S,A>::is_power_of_2(uint32_t v) {
 template<typename T, typename S, typename A>
 uint32_t var_opt_sketch<T,S,A>::to_log_2(uint32_t v) {
   if (is_power_of_2(v)) {
-    return count_trailing_zeros(v);
+    return count_trailing_zeros_in_u32(v);
   } else {
     throw std::invalid_argument("Attempt to compute integer log2 of non-positive or non-power of 2");
   }
@@ -1557,19 +1558,6 @@ double var_opt_sketch<T,S,A>::next_double_exclude_zero() {
 }
 
 template<typename T, typename S, typename A>
-uint32_t var_opt_sketch<T,S,A>::count_trailing_zeros(uint32_t v) {
-  static const uint8_t ctz_byte_count[256] = {8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1, [...]
-
-  uint32_t tmp = v;
-  for (int j = 0; j < 4; ++j) {
-    const int byte = (tmp & 0xFFUL);
-    if (byte != 0) return (j << 3) + ctz_byte_count[byte];
-    tmp >>= 8;
-  }
-  return 64;
-}
-
-template<typename T, typename S, typename A>
 uint32_t var_opt_sketch<T,S,A>::ceiling_power_of_2(uint32_t n) {
   --n;
   n |= n >> 1;
diff --git a/theta/include/theta_a_not_b.hpp b/theta/include/theta_a_not_b.hpp
index a45c82f..d4c413c 100644
--- a/theta/include/theta_a_not_b.hpp
+++ b/theta/include/theta_a_not_b.hpp
@@ -24,7 +24,8 @@
 #include <functional>
 #include <climits>
 
-#include <theta_sketch.hpp>
+#include "theta_sketch.hpp"
+#include "common_defs.hpp"
 
 namespace datasketches {
 
@@ -37,7 +38,7 @@ namespace datasketches {
 template<typename A>
 class theta_a_not_b_alloc {
 public:
-  explicit theta_a_not_b_alloc(uint64_t seed = update_theta_sketch_alloc<A>::builder::DEFAULT_SEED);
+  explicit theta_a_not_b_alloc(uint64_t seed = DEFAULT_SEED);
 
   compact_theta_sketch_alloc<A> compute(const theta_sketch_alloc<A>& a, const theta_sketch_alloc<A>& b, bool ordered = true) const;
 
diff --git a/theta/include/theta_intersection.hpp b/theta/include/theta_intersection.hpp
index 8ac7b18..18b3cf9 100644
--- a/theta/include/theta_intersection.hpp
+++ b/theta/include/theta_intersection.hpp
@@ -24,7 +24,8 @@
 #include <functional>
 #include <climits>
 
-#include <theta_sketch.hpp>
+#include "theta_sketch.hpp"
+#include "common_defs.hpp"
 
 namespace datasketches {
 
@@ -37,7 +38,7 @@ namespace datasketches {
 template<typename A>
 class theta_intersection_alloc {
 public:
-  explicit theta_intersection_alloc(uint64_t seed = update_theta_sketch_alloc<A>::builder::DEFAULT_SEED);
+  explicit theta_intersection_alloc(uint64_t seed = DEFAULT_SEED);
   theta_intersection_alloc(const theta_intersection_alloc<A>& other);
   theta_intersection_alloc(theta_intersection_alloc<A>&& other) noexcept;
   ~theta_intersection_alloc();
diff --git a/theta/include/theta_sketch.hpp b/theta/include/theta_sketch.hpp
index 6ab5cb1..fc489b5 100644
--- a/theta/include/theta_sketch.hpp
+++ b/theta/include/theta_sketch.hpp
@@ -25,6 +25,8 @@
 #include <climits>
 #include <vector>
 
+#include "common_defs.hpp"
+
 namespace datasketches {
 
 /*
@@ -76,8 +78,8 @@ public:
   virtual vector_bytes serialize(unsigned header_size_bytes = 0) const = 0;
 
   typedef std::unique_ptr<theta_sketch_alloc<A>, std::function<void(theta_sketch_alloc<A>*)>> unique_ptr;
-  static unique_ptr deserialize(std::istream& is, uint64_t seed = update_theta_sketch_alloc<A>::builder::DEFAULT_SEED);
-  static unique_ptr deserialize(const void* bytes, size_t size, uint64_t seed = update_theta_sketch_alloc<A>::builder::DEFAULT_SEED);
+  static unique_ptr deserialize(std::istream& is, uint64_t seed = DEFAULT_SEED);
+  static unique_ptr deserialize(const void* bytes, size_t size, uint64_t seed = DEFAULT_SEED);
 
   class const_iterator;
   virtual const_iterator begin() const = 0;
@@ -155,8 +157,8 @@ public:
   virtual typename theta_sketch_alloc<A>::const_iterator begin() const;
   virtual typename theta_sketch_alloc<A>::const_iterator end() const;
 
-  static update_theta_sketch_alloc<A> deserialize(std::istream& is, uint64_t seed = builder::DEFAULT_SEED);
-  static update_theta_sketch_alloc<A> deserialize(const void* bytes, size_t size, uint64_t seed = update_theta_sketch_alloc<A>::builder::DEFAULT_SEED);
+  static update_theta_sketch_alloc<A> deserialize(std::istream& is, uint64_t seed = DEFAULT_SEED);
+  static update_theta_sketch_alloc<A> deserialize(const void* bytes, size_t size, uint64_t seed = DEFAULT_SEED);
 
 private:
   // resize threshold = 0.5 tuned for speed
@@ -228,8 +230,8 @@ public:
   virtual typename theta_sketch_alloc<A>::const_iterator begin() const;
   virtual typename theta_sketch_alloc<A>::const_iterator end() const;
 
-  static compact_theta_sketch_alloc<A> deserialize(std::istream& is, uint64_t seed = update_theta_sketch_alloc<A>::builder::DEFAULT_SEED);
-  static compact_theta_sketch_alloc<A> deserialize(const void* bytes, size_t size, uint64_t seed = update_theta_sketch_alloc<A>::builder::DEFAULT_SEED);
+  static compact_theta_sketch_alloc<A> deserialize(std::istream& is, uint64_t seed = DEFAULT_SEED);
+  static compact_theta_sketch_alloc<A> deserialize(const void* bytes, size_t size, uint64_t seed = DEFAULT_SEED);
 
 private:
   typedef typename std::allocator_traits<A>::template rebind_alloc<uint64_t> AllocU64;
@@ -257,7 +259,6 @@ public:
   static const uint8_t MIN_LG_K = 5;
   static const uint8_t DEFAULT_LG_K = 12;
   static const resize_factor DEFAULT_RESIZE_FACTOR = X8;
-  static const uint64_t DEFAULT_SEED = 9001;
 
   builder();
   builder& set_lg_k(uint8_t lg_k);


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