datasketches 0.1.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/LICENSE +40 -3
  4. data/NOTICE +1 -1
  5. data/ext/datasketches/cpc_wrapper.cpp +12 -13
  6. data/ext/datasketches/ext.cpp +1 -1
  7. data/ext/datasketches/ext.h +4 -0
  8. data/ext/datasketches/extconf.rb +1 -1
  9. data/ext/datasketches/fi_wrapper.cpp +6 -8
  10. data/ext/datasketches/hll_wrapper.cpp +13 -14
  11. data/ext/datasketches/kll_wrapper.cpp +28 -76
  12. data/ext/datasketches/theta_wrapper.cpp +27 -41
  13. data/ext/datasketches/vo_wrapper.cpp +4 -6
  14. data/lib/datasketches/version.rb +1 -1
  15. data/vendor/datasketches-cpp/CMakeLists.txt +10 -0
  16. data/vendor/datasketches-cpp/LICENSE +40 -3
  17. data/vendor/datasketches-cpp/NOTICE +1 -1
  18. data/vendor/datasketches-cpp/README.md +4 -4
  19. data/vendor/datasketches-cpp/common/include/MurmurHash3.h +18 -7
  20. data/vendor/datasketches-cpp/common/include/binomial_bounds.hpp +8 -8
  21. data/vendor/datasketches-cpp/common/include/bounds_binomial_proportions.hpp +12 -15
  22. data/vendor/datasketches-cpp/common/include/common_defs.hpp +26 -0
  23. data/vendor/datasketches-cpp/common/include/conditional_forward.hpp +20 -8
  24. data/vendor/datasketches-cpp/common/include/count_zeros.hpp +2 -2
  25. data/vendor/datasketches-cpp/common/include/memory_operations.hpp +12 -0
  26. data/vendor/datasketches-cpp/common/include/serde.hpp +7 -7
  27. data/vendor/datasketches-cpp/common/test/CMakeLists.txt +24 -0
  28. data/vendor/datasketches-cpp/common/test/integration_test.cpp +77 -0
  29. data/vendor/datasketches-cpp/common/test/test_allocator.hpp +9 -1
  30. data/vendor/datasketches-cpp/cpc/include/cpc_common.hpp +13 -3
  31. data/vendor/datasketches-cpp/cpc/include/cpc_compressor.hpp +20 -20
  32. data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +116 -105
  33. data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +22 -6
  34. data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +140 -101
  35. data/vendor/datasketches-cpp/cpc/include/cpc_union.hpp +2 -2
  36. data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +20 -20
  37. data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +10 -16
  38. data/vendor/datasketches-cpp/cpc/include/icon_estimator.hpp +6 -6
  39. data/vendor/datasketches-cpp/cpc/include/u32_table.hpp +10 -10
  40. data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +21 -21
  41. data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +1 -0
  42. data/vendor/datasketches-cpp/cpc/test/compression_test.cpp +10 -10
  43. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_allocation_test.cpp +237 -0
  44. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +25 -0
  45. data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +1 -1
  46. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +15 -10
  47. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +102 -105
  48. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +19 -13
  49. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map_impl.hpp +141 -125
  50. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_custom_type_test.cpp +15 -12
  51. data/vendor/datasketches-cpp/fi/test/reverse_purge_hash_map_test.cpp +5 -5
  52. data/vendor/datasketches-cpp/hll/CMakeLists.txt +3 -0
  53. data/vendor/datasketches-cpp/hll/include/AuxHashMap-internal.hpp +81 -109
  54. data/vendor/datasketches-cpp/hll/include/AuxHashMap.hpp +25 -24
  55. data/vendor/datasketches-cpp/hll/include/CompositeInterpolationXTable-internal.hpp +15 -15
  56. data/vendor/datasketches-cpp/hll/include/CompositeInterpolationXTable.hpp +5 -5
  57. data/vendor/datasketches-cpp/hll/include/CouponHashSet-internal.hpp +89 -105
  58. data/vendor/datasketches-cpp/hll/include/CouponHashSet.hpp +13 -13
  59. data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +130 -165
  60. data/vendor/datasketches-cpp/hll/include/CouponList.hpp +21 -22
  61. data/vendor/datasketches-cpp/hll/include/CubicInterpolation-internal.hpp +2 -4
  62. data/vendor/datasketches-cpp/hll/include/CubicInterpolation.hpp +2 -2
  63. data/vendor/datasketches-cpp/hll/include/HarmonicNumbers-internal.hpp +1 -1
  64. data/vendor/datasketches-cpp/hll/include/HarmonicNumbers.hpp +2 -2
  65. data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +88 -83
  66. data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +9 -9
  67. data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +34 -45
  68. data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +7 -8
  69. data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +41 -52
  70. data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +7 -8
  71. data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +220 -251
  72. data/vendor/datasketches-cpp/hll/include/HllArray.hpp +42 -42
  73. data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +36 -38
  74. data/vendor/datasketches-cpp/hll/include/HllSketchImpl-internal.hpp +22 -22
  75. data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +15 -14
  76. data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +47 -44
  77. data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +62 -87
  78. data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +121 -128
  79. data/vendor/datasketches-cpp/hll/include/RelativeErrorTables.hpp +1 -1
  80. data/vendor/datasketches-cpp/hll/include/coupon_iterator-internal.hpp +9 -9
  81. data/vendor/datasketches-cpp/hll/include/coupon_iterator.hpp +5 -5
  82. data/vendor/datasketches-cpp/hll/include/hll.hpp +25 -53
  83. data/vendor/datasketches-cpp/hll/test/AuxHashMapTest.cpp +8 -8
  84. data/vendor/datasketches-cpp/hll/test/CouponHashSetTest.cpp +36 -36
  85. data/vendor/datasketches-cpp/hll/test/CouponListTest.cpp +28 -28
  86. data/vendor/datasketches-cpp/hll/test/CrossCountingTest.cpp +2 -2
  87. data/vendor/datasketches-cpp/hll/test/HllArrayTest.cpp +37 -37
  88. data/vendor/datasketches-cpp/hll/test/HllSketchTest.cpp +57 -61
  89. data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +10 -14
  90. data/vendor/datasketches-cpp/hll/test/IsomorphicTest.cpp +3 -3
  91. data/vendor/datasketches-cpp/hll/test/ToFromByteArrayTest.cpp +4 -4
  92. data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +5 -4
  93. data/vendor/datasketches-cpp/kll/include/kll_helper_impl.hpp +6 -6
  94. data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator.hpp +14 -6
  95. data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator_impl.hpp +40 -25
  96. data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +50 -6
  97. data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +164 -136
  98. data/vendor/datasketches-cpp/kll/include/kolmogorov_smirnov.hpp +67 -0
  99. data/vendor/datasketches-cpp/kll/include/kolmogorov_smirnov_impl.hpp +78 -0
  100. data/vendor/datasketches-cpp/kll/test/CMakeLists.txt +1 -0
  101. data/vendor/datasketches-cpp/kll/test/kll_sketch_custom_type_test.cpp +11 -10
  102. data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +178 -88
  103. data/vendor/datasketches-cpp/kll/test/kolmogorov_smirnov_test.cpp +111 -0
  104. data/vendor/datasketches-cpp/pyproject.toml +4 -2
  105. data/vendor/datasketches-cpp/python/CMakeLists.txt +12 -6
  106. data/vendor/datasketches-cpp/python/README.md +52 -49
  107. data/vendor/datasketches-cpp/python/pybind11Path.cmd +3 -0
  108. data/vendor/datasketches-cpp/python/src/cpc_wrapper.cpp +1 -1
  109. data/vendor/datasketches-cpp/python/src/datasketches.cpp +2 -0
  110. data/vendor/datasketches-cpp/python/src/hll_wrapper.cpp +4 -6
  111. data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +4 -2
  112. data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +246 -0
  113. data/vendor/datasketches-cpp/python/src/theta_wrapper.cpp +38 -28
  114. data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +11 -5
  115. data/vendor/datasketches-cpp/python/src/vo_wrapper.cpp +2 -2
  116. data/vendor/datasketches-cpp/python/tests/hll_test.py +1 -2
  117. data/vendor/datasketches-cpp/python/tests/kll_test.py +5 -5
  118. data/vendor/datasketches-cpp/python/tests/req_test.py +126 -0
  119. data/vendor/datasketches-cpp/python/tests/theta_test.py +28 -3
  120. data/vendor/datasketches-cpp/python/tests/vector_of_kll_test.py +4 -4
  121. data/vendor/datasketches-cpp/python/tests/vo_test.py +3 -3
  122. data/vendor/datasketches-cpp/req/CMakeLists.txt +60 -0
  123. data/vendor/datasketches-cpp/{tuple/include/theta_a_not_b_experimental_impl.hpp → req/include/req_common.hpp} +18 -8
  124. data/vendor/datasketches-cpp/req/include/req_compactor.hpp +137 -0
  125. data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +488 -0
  126. data/vendor/datasketches-cpp/req/include/req_quantile_calculator.hpp +69 -0
  127. data/vendor/datasketches-cpp/req/include/req_quantile_calculator_impl.hpp +60 -0
  128. data/vendor/datasketches-cpp/req/include/req_sketch.hpp +395 -0
  129. data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +810 -0
  130. data/vendor/datasketches-cpp/req/test/CMakeLists.txt +43 -0
  131. data/vendor/datasketches-cpp/req/test/req_float_empty_from_java.sk +0 -0
  132. data/vendor/datasketches-cpp/req/test/req_float_estimation_from_java.sk +0 -0
  133. data/vendor/datasketches-cpp/req/test/req_float_exact_from_java.sk +0 -0
  134. data/vendor/datasketches-cpp/req/test/req_float_raw_items_from_java.sk +0 -0
  135. data/vendor/datasketches-cpp/req/test/req_float_single_item_from_java.sk +0 -0
  136. data/vendor/datasketches-cpp/req/test/req_sketch_custom_type_test.cpp +128 -0
  137. data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +494 -0
  138. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +19 -13
  139. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +130 -127
  140. data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +5 -5
  141. data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +41 -49
  142. data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +1 -0
  143. data/vendor/datasketches-cpp/sampling/test/var_opt_allocation_test.cpp +96 -0
  144. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +6 -6
  145. data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +13 -44
  146. data/vendor/datasketches-cpp/setup.py +11 -6
  147. data/vendor/datasketches-cpp/theta/CMakeLists.txt +30 -3
  148. data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_sampled_sets.hpp +3 -2
  149. data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_theta_sketched_sets.hpp +1 -1
  150. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser.hpp +67 -0
  151. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser_impl.hpp +70 -0
  152. data/vendor/datasketches-cpp/theta/include/theta_a_not_b.hpp +12 -29
  153. data/vendor/datasketches-cpp/theta/include/theta_a_not_b_impl.hpp +5 -46
  154. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_comparators.hpp +0 -0
  155. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_constants.hpp +11 -4
  156. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_helpers.hpp +0 -0
  157. data/vendor/datasketches-cpp/theta/include/theta_intersection.hpp +26 -28
  158. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_intersection_base.hpp +0 -0
  159. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_intersection_base_impl.hpp +0 -0
  160. data/vendor/datasketches-cpp/theta/include/theta_intersection_impl.hpp +8 -90
  161. data/vendor/datasketches-cpp/{tuple/test/theta_union_experimental_test.cpp → theta/include/theta_jaccard_similarity.hpp} +11 -18
  162. data/vendor/datasketches-cpp/{tuple/include/jaccard_similarity.hpp → theta/include/theta_jaccard_similarity_base.hpp} +24 -36
  163. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_set_difference_base.hpp +0 -0
  164. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_set_difference_base_impl.hpp +5 -0
  165. data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +163 -256
  166. data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +250 -651
  167. data/vendor/datasketches-cpp/theta/include/theta_union.hpp +27 -60
  168. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_union_base.hpp +1 -1
  169. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_union_base_impl.hpp +6 -1
  170. data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +13 -69
  171. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base.hpp +10 -21
  172. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base_impl.hpp +44 -30
  173. data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +1 -0
  174. data/vendor/datasketches-cpp/theta/test/theta_a_not_b_test.cpp +23 -1
  175. data/vendor/datasketches-cpp/theta/test/theta_intersection_test.cpp +21 -1
  176. data/vendor/datasketches-cpp/{tuple → theta}/test/theta_jaccard_similarity_test.cpp +60 -5
  177. data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +74 -235
  178. data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +22 -2
  179. data/vendor/datasketches-cpp/tuple/CMakeLists.txt +3 -35
  180. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_sketch_impl.hpp +47 -60
  181. data/vendor/datasketches-cpp/tuple/include/tuple_jaccard_similarity.hpp +38 -0
  182. data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +28 -13
  183. data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +57 -70
  184. data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +1 -6
  185. data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +1 -1
  186. data/vendor/datasketches-cpp/tuple/test/tuple_a_not_b_test.cpp +18 -21
  187. data/vendor/datasketches-cpp/tuple/test/tuple_intersection_test.cpp +13 -16
  188. data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +7 -6
  189. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_allocation_test.cpp +3 -3
  190. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +20 -20
  191. data/vendor/datasketches-cpp/tuple/test/tuple_union_test.cpp +13 -16
  192. metadata +51 -36
  193. data/vendor/datasketches-cpp/tuple/include/theta_a_not_b_experimental.hpp +0 -53
  194. data/vendor/datasketches-cpp/tuple/include/theta_intersection_experimental.hpp +0 -78
  195. data/vendor/datasketches-cpp/tuple/include/theta_intersection_experimental_impl.hpp +0 -43
  196. data/vendor/datasketches-cpp/tuple/include/theta_sketch_experimental.hpp +0 -393
  197. data/vendor/datasketches-cpp/tuple/include/theta_sketch_experimental_impl.hpp +0 -481
  198. data/vendor/datasketches-cpp/tuple/include/theta_union_experimental.hpp +0 -88
  199. data/vendor/datasketches-cpp/tuple/include/theta_union_experimental_impl.hpp +0 -47
  200. data/vendor/datasketches-cpp/tuple/test/theta_a_not_b_experimental_test.cpp +0 -250
  201. data/vendor/datasketches-cpp/tuple/test/theta_compact_empty_from_java.sk +0 -0
  202. data/vendor/datasketches-cpp/tuple/test/theta_compact_estimation_from_java.sk +0 -0
  203. data/vendor/datasketches-cpp/tuple/test/theta_compact_single_item_from_java.sk +0 -0
  204. data/vendor/datasketches-cpp/tuple/test/theta_intersection_experimental_test.cpp +0 -224
  205. data/vendor/datasketches-cpp/tuple/test/theta_sketch_experimental_test.cpp +0 -247
@@ -23,6 +23,7 @@
23
23
  #include "CouponList.hpp"
24
24
  #include "CubicInterpolation.hpp"
25
25
  #include "HllUtil.hpp"
26
+ #include "count_zeros.hpp"
26
27
 
27
28
  #include <algorithm>
28
29
  #include <cmath>
@@ -30,161 +31,134 @@
30
31
  namespace datasketches {
31
32
 
32
33
  template<typename A>
33
- CouponList<A>::CouponList(const int lgConfigK, const target_hll_type tgtHllType, const hll_mode mode)
34
- : HllSketchImpl<A>(lgConfigK, tgtHllType, mode, false) {
35
- if (mode == hll_mode::LIST) {
36
- lgCouponArrInts = HllUtil<A>::LG_INIT_LIST_SIZE;
37
- } else { // mode == SET
38
- lgCouponArrInts = HllUtil<A>::LG_INIT_SET_SIZE;
39
- }
40
- oooFlag = false;
41
- const int arrayLen = 1 << lgCouponArrInts;
42
- typedef typename std::allocator_traits<A>::template rebind_alloc<int> intAlloc;
43
- couponIntArr = intAlloc().allocate(arrayLen);
44
- std::fill(couponIntArr, couponIntArr + arrayLen, 0);
45
- couponCount = 0;
46
- }
47
-
48
- template<typename A>
49
- CouponList<A>::CouponList(const CouponList& that)
50
- : HllSketchImpl<A>(that.lgConfigK, that.tgtHllType, that.mode, false),
51
- lgCouponArrInts(that.lgCouponArrInts),
52
- couponCount(that.couponCount),
53
- oooFlag(that.oooFlag) {
54
-
55
- const int numItems = 1 << lgCouponArrInts;
56
- typedef typename std::allocator_traits<A>::template rebind_alloc<int> intAlloc;
57
- couponIntArr = intAlloc().allocate(numItems);
58
- std::copy(that.couponIntArr, that.couponIntArr + numItems, couponIntArr);
59
- }
60
-
61
- template<typename A>
62
- CouponList<A>::CouponList(const CouponList& that, const target_hll_type tgtHllType)
63
- : HllSketchImpl<A>(that.lgConfigK, tgtHllType, that.mode, false),
64
- lgCouponArrInts(that.lgCouponArrInts),
65
- couponCount(that.couponCount),
66
- oooFlag(that.oooFlag) {
67
-
68
- const int numItems = 1 << lgCouponArrInts;
69
- typedef typename std::allocator_traits<A>::template rebind_alloc<int> intAlloc;
70
- couponIntArr = intAlloc().allocate(numItems);
71
- std::copy(that.couponIntArr, that.couponIntArr + numItems, couponIntArr);
72
- }
34
+ CouponList<A>::CouponList(uint8_t lgConfigK, target_hll_type tgtHllType, hll_mode mode, const A& allocator):
35
+ HllSketchImpl<A>(lgConfigK, tgtHllType, mode, false),
36
+ couponCount_(0),
37
+ oooFlag_(false),
38
+ coupons_(1ULL << (mode == hll_mode::LIST ? hll_constants::LG_INIT_LIST_SIZE : hll_constants::LG_INIT_SET_SIZE), 0, allocator)
39
+ {}
73
40
 
74
41
  template<typename A>
75
- CouponList<A>::~CouponList() {
76
- typedef typename std::allocator_traits<A>::template rebind_alloc<int> intAlloc;
77
- intAlloc().deallocate(couponIntArr, 1 << lgCouponArrInts);
78
- }
42
+ CouponList<A>::CouponList(const CouponList& that, const target_hll_type tgtHllType):
43
+ HllSketchImpl<A>(that.lgConfigK_, tgtHllType, that.mode_, false),
44
+ couponCount_(that.couponCount_),
45
+ oooFlag_(that.oooFlag_),
46
+ coupons_(that.coupons_)
47
+ {}
79
48
 
80
49
  template<typename A>
81
50
  std::function<void(HllSketchImpl<A>*)> CouponList<A>::get_deleter() const {
82
51
  return [](HllSketchImpl<A>* ptr) {
83
52
  CouponList<A>* cl = static_cast<CouponList<A>*>(ptr);
53
+ ClAlloc cla(cl->getAllocator());
84
54
  cl->~CouponList();
85
- clAlloc().deallocate(cl, 1);
55
+ cla.deallocate(cl, 1);
86
56
  };
87
57
  }
88
58
 
89
59
  template<typename A>
90
60
  CouponList<A>* CouponList<A>::copy() const {
91
- return new (clAlloc().allocate(1)) CouponList<A>(*this);
61
+ ClAlloc cla(coupons_.get_allocator());
62
+ return new (cla.allocate(1)) CouponList<A>(*this);
92
63
  }
93
64
 
94
65
  template<typename A>
95
66
  CouponList<A>* CouponList<A>::copyAs(target_hll_type tgtHllType) const {
96
- return new (clAlloc().allocate(1)) CouponList<A>(*this, tgtHllType);
67
+ ClAlloc cla(coupons_.get_allocator());
68
+ return new (cla.allocate(1)) CouponList<A>(*this, tgtHllType);
97
69
  }
98
70
 
99
71
  template<typename A>
100
- CouponList<A>* CouponList<A>::newList(const void* bytes, size_t len) {
101
- if (len < HllUtil<A>::LIST_INT_ARR_START) {
72
+ CouponList<A>* CouponList<A>::newList(const void* bytes, size_t len, const A& allocator) {
73
+ if (len < hll_constants::LIST_INT_ARR_START) {
102
74
  throw std::out_of_range("Input data length insufficient to hold CouponHashSet");
103
75
  }
104
76
 
105
77
  const uint8_t* data = static_cast<const uint8_t*>(bytes);
106
- if (data[HllUtil<A>::PREAMBLE_INTS_BYTE] != HllUtil<A>::LIST_PREINTS) {
78
+ if (data[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::LIST_PREINTS) {
107
79
  throw std::invalid_argument("Incorrect number of preInts in input stream");
108
80
  }
109
- if (data[HllUtil<A>::SER_VER_BYTE] != HllUtil<A>::SER_VER) {
81
+ if (data[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
110
82
  throw std::invalid_argument("Wrong ser ver in input stream");
111
83
  }
112
- if (data[HllUtil<A>::FAMILY_BYTE] != HllUtil<A>::FAMILY_ID) {
84
+ if (data[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
113
85
  throw std::invalid_argument("Input stream is not an HLL sketch");
114
86
  }
115
87
 
116
- hll_mode mode = HllSketchImpl<A>::extractCurMode(data[HllUtil<A>::MODE_BYTE]);
88
+ hll_mode mode = HllSketchImpl<A>::extractCurMode(data[hll_constants::MODE_BYTE]);
117
89
  if (mode != LIST) {
118
- throw std::invalid_argument("Calling set construtor with non-list mode data");
90
+ throw std::invalid_argument("Calling list constructor with non-list mode data");
119
91
  }
120
92
 
121
- target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[HllUtil<A>::MODE_BYTE]);
93
+ target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[hll_constants::MODE_BYTE]);
122
94
 
123
- const int lgK = data[HllUtil<A>::LG_K_BYTE];
124
- const bool compact = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
125
- const bool oooFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
126
- const bool emptyFlag = ((data[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::EMPTY_FLAG_MASK) ? true : false);
95
+ const uint8_t lgK = data[hll_constants::LG_K_BYTE];
96
+ const bool compact = ((data[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
97
+ const bool oooFlag = ((data[hll_constants::FLAGS_BYTE] & hll_constants::OUT_OF_ORDER_FLAG_MASK) ? true : false);
98
+ const bool emptyFlag = ((data[hll_constants::FLAGS_BYTE] & hll_constants::EMPTY_FLAG_MASK) ? true : false);
127
99
 
128
- const int couponCount = data[HllUtil<A>::LIST_COUNT_BYTE];
129
- const int couponsInArray = (compact ? couponCount : (1 << HllUtil<A>::computeLgArrInts(LIST, couponCount, lgK)));
130
- const size_t expectedLength = HllUtil<A>::LIST_INT_ARR_START + (couponsInArray * sizeof(int));
100
+ const uint32_t couponCount = data[hll_constants::LIST_COUNT_BYTE];
101
+ const uint32_t couponsInArray = (compact ? couponCount : (1 << HllUtil<A>::computeLgArrInts(LIST, couponCount, lgK)));
102
+ const size_t expectedLength = hll_constants::LIST_INT_ARR_START + (couponsInArray * sizeof(uint32_t));
131
103
  if (len < expectedLength) {
132
104
  throw std::out_of_range("Byte array too short for sketch. Expected " + std::to_string(expectedLength)
133
105
  + ", found: " + std::to_string(len));
134
106
  }
135
107
 
136
- CouponList<A>* sketch = new (clAlloc().allocate(1)) CouponList<A>(lgK, tgtHllType, mode);
137
- sketch->couponCount = couponCount;
108
+ ClAlloc cla(allocator);
109
+ CouponList<A>* sketch = new (cla.allocate(1)) CouponList<A>(lgK, tgtHllType, mode, allocator);
110
+ sketch->couponCount_ = couponCount;
138
111
  sketch->putOutOfOrderFlag(oooFlag); // should always be false for LIST
139
112
 
140
113
  if (!emptyFlag) {
141
114
  // only need to read valid coupons, unlike in stream case
142
- std::memcpy(sketch->couponIntArr, data + HllUtil<A>::LIST_INT_ARR_START, couponCount * sizeof(int));
115
+ std::memcpy(sketch->coupons_.data(), data + hll_constants::LIST_INT_ARR_START, couponCount * sizeof(uint32_t));
143
116
  }
144
117
 
145
118
  return sketch;
146
119
  }
147
120
 
148
121
  template<typename A>
149
- CouponList<A>* CouponList<A>::newList(std::istream& is) {
122
+ CouponList<A>* CouponList<A>::newList(std::istream& is, const A& allocator) {
150
123
  uint8_t listHeader[8];
151
- is.read((char*)listHeader, 8 * sizeof(uint8_t));
124
+ read(is, listHeader, 8 * sizeof(uint8_t));
152
125
 
153
- if (listHeader[HllUtil<A>::PREAMBLE_INTS_BYTE] != HllUtil<A>::LIST_PREINTS) {
126
+ if (listHeader[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::LIST_PREINTS) {
154
127
  throw std::invalid_argument("Incorrect number of preInts in input stream");
155
128
  }
156
- if (listHeader[HllUtil<A>::SER_VER_BYTE] != HllUtil<A>::SER_VER) {
129
+ if (listHeader[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
157
130
  throw std::invalid_argument("Wrong ser ver in input stream");
158
131
  }
159
- if (listHeader[HllUtil<A>::FAMILY_BYTE] != HllUtil<A>::FAMILY_ID) {
132
+ if (listHeader[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
160
133
  throw std::invalid_argument("Input stream is not an HLL sketch");
161
134
  }
162
135
 
163
- hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[HllUtil<A>::MODE_BYTE]);
136
+ hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[hll_constants::MODE_BYTE]);
164
137
  if (mode != LIST) {
165
- throw std::invalid_argument("Calling list construtor with non-list mode data");
138
+ throw std::invalid_argument("Calling list constructor with non-list mode data");
166
139
  }
167
140
 
168
- const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[HllUtil<A>::MODE_BYTE]);
141
+ const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[hll_constants::MODE_BYTE]);
169
142
 
170
- const int lgK = (int) listHeader[HllUtil<A>::LG_K_BYTE];
171
- const bool compact = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::COMPACT_FLAG_MASK) ? true : false);
172
- const bool oooFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::OUT_OF_ORDER_FLAG_MASK) ? true : false);
173
- const bool emptyFlag = ((listHeader[HllUtil<A>::FLAGS_BYTE] & HllUtil<A>::EMPTY_FLAG_MASK) ? true : false);
143
+ const uint8_t lgK = listHeader[hll_constants::LG_K_BYTE];
144
+ const bool compact = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
145
+ const bool oooFlag = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::OUT_OF_ORDER_FLAG_MASK) ? true : false);
146
+ const bool emptyFlag = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::EMPTY_FLAG_MASK) ? true : false);
174
147
 
175
- CouponList<A>* sketch = new (clAlloc().allocate(1)) CouponList<A>(lgK, tgtHllType, mode);
176
- typedef std::unique_ptr<CouponList<A>, std::function<void(HllSketchImpl<A>*)>> coupon_list_ptr;
148
+ ClAlloc cla(allocator);
149
+ CouponList<A>* sketch = new (cla.allocate(1)) CouponList<A>(lgK, tgtHllType, mode, allocator);
150
+ using coupon_list_ptr = std::unique_ptr<CouponList<A>, std::function<void(HllSketchImpl<A>*)>>;
177
151
  coupon_list_ptr ptr(sketch, sketch->get_deleter());
178
- const int couponCount = listHeader[HllUtil<A>::LIST_COUNT_BYTE];
179
- sketch->couponCount = couponCount;
152
+ const uint32_t couponCount = listHeader[hll_constants::LIST_COUNT_BYTE];
153
+ sketch->couponCount_ = couponCount;
180
154
  sketch->putOutOfOrderFlag(oooFlag); // should always be false for LIST
181
155
 
182
156
  if (!emptyFlag) {
183
157
  // For stream processing, need to read entire number written to stream so read
184
158
  // pointer ends up set correctly.
185
159
  // If not compact, still need to read empty items even though in order.
186
- const int numToRead = (compact ? couponCount : (1 << sketch->lgCouponArrInts));
187
- is.read((char*)sketch->couponIntArr, numToRead * sizeof(int));
160
+ const uint32_t numToRead = (compact ? couponCount : static_cast<uint32_t>(sketch->coupons_.size()));
161
+ read(is, sketch->coupons_.data(), numToRead * sizeof(uint32_t));
188
162
  }
189
163
 
190
164
  if (!is.good())
@@ -196,20 +170,20 @@ CouponList<A>* CouponList<A>::newList(std::istream& is) {
196
170
  template<typename A>
197
171
  vector_u8<A> CouponList<A>::serialize(bool compact, unsigned header_size_bytes) const {
198
172
  const size_t sketchSizeBytes = (compact ? getCompactSerializationBytes() : getUpdatableSerializationBytes()) + header_size_bytes;
199
- vector_u8<A> byteArr(sketchSizeBytes);
173
+ vector_u8<A> byteArr(sketchSizeBytes, 0, getAllocator());
200
174
  uint8_t* bytes = byteArr.data() + header_size_bytes;
201
175
 
202
- bytes[HllUtil<A>::PREAMBLE_INTS_BYTE] = static_cast<uint8_t>(getPreInts());
203
- bytes[HllUtil<A>::SER_VER_BYTE] = static_cast<uint8_t>(HllUtil<A>::SER_VER);
204
- bytes[HllUtil<A>::FAMILY_BYTE] = static_cast<uint8_t>(HllUtil<A>::FAMILY_ID);
205
- bytes[HllUtil<A>::LG_K_BYTE] = static_cast<uint8_t>(this->lgConfigK);
206
- bytes[HllUtil<A>::LG_ARR_BYTE] = static_cast<uint8_t>(lgCouponArrInts);
207
- bytes[HllUtil<A>::FLAGS_BYTE] = this->makeFlagsByte(compact);
208
- bytes[HllUtil<A>::LIST_COUNT_BYTE] = static_cast<uint8_t>(this->mode == LIST ? couponCount : 0);
209
- bytes[HllUtil<A>::MODE_BYTE] = this->makeModeByte();
210
-
211
- if (this->mode == SET) {
212
- std::memcpy(bytes + HllUtil<A>::HASH_SET_COUNT_INT, &couponCount, sizeof(couponCount));
176
+ bytes[hll_constants::PREAMBLE_INTS_BYTE] = static_cast<uint8_t>(getPreInts());
177
+ bytes[hll_constants::SER_VER_BYTE] = static_cast<uint8_t>(hll_constants::SER_VER);
178
+ bytes[hll_constants::FAMILY_BYTE] = static_cast<uint8_t>(hll_constants::FAMILY_ID);
179
+ bytes[hll_constants::LG_K_BYTE] = static_cast<uint8_t>(this->lgConfigK_);
180
+ bytes[hll_constants::LG_ARR_BYTE] = count_trailing_zeros_in_u32(static_cast<uint32_t>(coupons_.size()));
181
+ bytes[hll_constants::FLAGS_BYTE] = this->makeFlagsByte(compact);
182
+ bytes[hll_constants::LIST_COUNT_BYTE] = static_cast<uint8_t>(this->mode_ == LIST ? couponCount_ : 0);
183
+ bytes[hll_constants::MODE_BYTE] = this->makeModeByte();
184
+
185
+ if (this->mode_ == SET) {
186
+ std::memcpy(bytes + hll_constants::HASH_SET_COUNT_INT, &couponCount_, sizeof(couponCount_));
213
187
  }
214
188
 
215
189
  // coupons
@@ -217,12 +191,12 @@ vector_u8<A> CouponList<A>::serialize(bool compact, unsigned header_size_bytes)
217
191
  const int sw = (isCompact() ? 2 : 0) | (compact ? 1 : 0);
218
192
  switch (sw) {
219
193
  case 0: { // src updatable, dst updatable
220
- std::memcpy(bytes + getMemDataStart(), getCouponIntArr(), (1 << lgCouponArrInts) * sizeof(int));
194
+ std::memcpy(bytes + getMemDataStart(), coupons_.data(), coupons_.size() * sizeof(uint32_t));
221
195
  break;
222
196
  }
223
197
  case 1: { // src updatable, dst compact
224
198
  bytes += getMemDataStart(); // reusing pointer for incremental writes
225
- for (uint32_t coupon: *this) {
199
+ for (const uint32_t coupon: *this) {
226
200
  std::memcpy(bytes, &coupon, sizeof(coupon));
227
201
  bytes += sizeof(coupon);
228
202
  }
@@ -239,33 +213,33 @@ vector_u8<A> CouponList<A>::serialize(bool compact, unsigned header_size_bytes)
239
213
  template<typename A>
240
214
  void CouponList<A>::serialize(std::ostream& os, const bool compact) const {
241
215
  // header
242
- const uint8_t preInts(getPreInts());
243
- os.write((char*)&preInts, sizeof(preInts));
244
- const uint8_t serialVersion(HllUtil<A>::SER_VER);
245
- os.write((char*)&serialVersion, sizeof(serialVersion));
246
- const uint8_t familyId(HllUtil<A>::FAMILY_ID);
247
- os.write((char*)&familyId, sizeof(familyId));
248
- const uint8_t lgKByte((uint8_t) this->lgConfigK);
249
- os.write((char*)&lgKByte, sizeof(lgKByte));
250
- const uint8_t lgArrIntsByte((uint8_t) lgCouponArrInts);
251
- os.write((char*)&lgArrIntsByte, sizeof(lgArrIntsByte));
252
- const uint8_t flagsByte(this->makeFlagsByte(compact));
253
- os.write((char*)&flagsByte, sizeof(flagsByte));
254
-
255
- if (this->mode == LIST) {
256
- const uint8_t listCount((uint8_t) couponCount);
257
- os.write((char*)&listCount, sizeof(listCount));
216
+ const uint8_t preInts = getPreInts();
217
+ write(os, preInts);
218
+ const uint8_t serialVersion(hll_constants::SER_VER);
219
+ write(os, serialVersion);
220
+ const uint8_t familyId(hll_constants::FAMILY_ID);
221
+ write(os, familyId);
222
+ const uint8_t lgKByte = this->lgConfigK_;
223
+ write(os, lgKByte);
224
+ const uint8_t lgArrIntsByte = count_trailing_zeros_in_u32(static_cast<uint32_t>(coupons_.size()));
225
+ write(os, lgArrIntsByte);
226
+ const uint8_t flagsByte = this->makeFlagsByte(compact);
227
+ write(os, flagsByte);
228
+
229
+ if (this->mode_ == LIST) {
230
+ const uint8_t listCount = static_cast<uint8_t>(couponCount_);
231
+ write(os, listCount);
258
232
  } else { // mode == SET
259
- const uint8_t unused(0);
260
- os.write((char*)&unused, sizeof(unused));
233
+ const uint8_t unused = 0;
234
+ write(os, unused);
261
235
  }
262
236
 
263
- const uint8_t modeByte(this->makeModeByte());
264
- os.write((char*)&modeByte, sizeof(modeByte));
237
+ const uint8_t modeByte = this->makeModeByte();
238
+ write(os, modeByte);
265
239
 
266
- if (this->mode == SET) {
240
+ if (this->mode_ == SET) {
267
241
  // writing as int, already stored as int
268
- os.write((char*)&couponCount, sizeof(couponCount));
242
+ write(os, couponCount_);
269
243
  }
270
244
 
271
245
  // coupons
@@ -273,12 +247,12 @@ void CouponList<A>::serialize(std::ostream& os, const bool compact) const {
273
247
  const int sw = (isCompact() ? 2 : 0) | (compact ? 1 : 0);
274
248
  switch (sw) {
275
249
  case 0: { // src updatable, dst updatable
276
- os.write((char*)getCouponIntArr(), (1 << lgCouponArrInts) * sizeof(int));
250
+ write(os, coupons_.data(), coupons_.size() * sizeof(uint32_t));
277
251
  break;
278
252
  }
279
253
  case 1: { // src updatable, dst compact
280
- for (uint32_t coupon: *this) {
281
- os.write((char*)&coupon, sizeof(coupon));
254
+ for (const uint32_t coupon: *this) {
255
+ write(os, coupon);
282
256
  }
283
257
  break;
284
258
  }
@@ -291,15 +265,14 @@ void CouponList<A>::serialize(std::ostream& os, const bool compact) const {
291
265
  }
292
266
 
293
267
  template<typename A>
294
- HllSketchImpl<A>* CouponList<A>::couponUpdate(int coupon) {
295
- const int len = 1 << lgCouponArrInts;
296
- for (int i = 0; i < len; ++i) { // search for empty slot
297
- const int couponAtIdx = couponIntArr[i];
298
- if (couponAtIdx == HllUtil<A>::EMPTY) {
299
- couponIntArr[i] = coupon; // the actual update
300
- ++couponCount;
301
- if (couponCount >= len) { // array full
302
- if (this->lgConfigK < 8) {
268
+ HllSketchImpl<A>* CouponList<A>::couponUpdate(uint32_t coupon) {
269
+ for (size_t i = 0; i < coupons_.size(); ++i) { // search for empty slot
270
+ const uint32_t couponAtIdx = coupons_[i];
271
+ if (couponAtIdx == hll_constants::EMPTY) {
272
+ coupons_[i] = coupon; // the actual update
273
+ ++couponCount_;
274
+ if (couponCount_ == static_cast<uint32_t>(coupons_.size())) { // array full
275
+ if (this->lgConfigK_ < 8) {
303
276
  return promoteHeapListOrSetToHll(*this);
304
277
  }
305
278
  return promoteHeapListToSet(*this);
@@ -320,76 +293,68 @@ double CouponList<A>::getCompositeEstimate() const { return getEstimate(); }
320
293
 
321
294
  template<typename A>
322
295
  double CouponList<A>::getEstimate() const {
323
- const int couponCount = getCouponCount();
324
- const double est = CubicInterpolation<A>::usingXAndYTables(couponCount);
325
- return fmax(est, couponCount);
296
+ const double est = CubicInterpolation<A>::usingXAndYTables(couponCount_);
297
+ return fmax(est, couponCount_);
326
298
  }
327
299
 
328
300
  template<typename A>
329
- double CouponList<A>::getLowerBound(const int numStdDev) const {
301
+ double CouponList<A>::getLowerBound(uint8_t numStdDev) const {
330
302
  HllUtil<A>::checkNumStdDev(numStdDev);
331
- const int couponCount = getCouponCount();
332
- const double est = CubicInterpolation<A>::usingXAndYTables(couponCount);
333
- const double tmp = est / (1.0 + (numStdDev * HllUtil<A>::COUPON_RSE));
334
- return fmax(tmp, couponCount);
303
+ const double est = CubicInterpolation<A>::usingXAndYTables(couponCount_);
304
+ const double tmp = est / (1.0 + (numStdDev * hll_constants::COUPON_RSE));
305
+ return fmax(tmp, couponCount_);
335
306
  }
336
307
 
337
308
  template<typename A>
338
- double CouponList<A>::getUpperBound(const int numStdDev) const {
309
+ double CouponList<A>::getUpperBound(uint8_t numStdDev) const {
339
310
  HllUtil<A>::checkNumStdDev(numStdDev);
340
- const int couponCount = getCouponCount();
341
- const double est = CubicInterpolation<A>::usingXAndYTables(couponCount);
342
- const double tmp = est / (1.0 - (numStdDev * HllUtil<A>::COUPON_RSE));
343
- return fmax(tmp, couponCount);
311
+ const double est = CubicInterpolation<A>::usingXAndYTables(couponCount_);
312
+ const double tmp = est / (1.0 - (numStdDev * hll_constants::COUPON_RSE));
313
+ return fmax(tmp, couponCount_);
344
314
  }
345
315
 
346
316
  template<typename A>
347
317
  bool CouponList<A>::isEmpty() const { return getCouponCount() == 0; }
348
318
 
349
319
  template<typename A>
350
- int CouponList<A>::getUpdatableSerializationBytes() const {
351
- return getMemDataStart() + (4 << getLgCouponArrInts());
320
+ uint32_t CouponList<A>::getUpdatableSerializationBytes() const {
321
+ return getMemDataStart() + static_cast<uint32_t>(coupons_.size()) * sizeof(uint32_t);
352
322
  }
353
323
 
354
324
  template<typename A>
355
- int CouponList<A>::getCouponCount() const {
356
- return couponCount;
325
+ uint32_t CouponList<A>::getCouponCount() const {
326
+ return couponCount_;
357
327
  }
358
328
 
359
329
  template<typename A>
360
- int CouponList<A>::getCompactSerializationBytes() const {
361
- return getMemDataStart() + (couponCount << 2);
330
+ uint32_t CouponList<A>::getCompactSerializationBytes() const {
331
+ return getMemDataStart() + (couponCount_ << 2);
362
332
  }
363
333
 
364
334
  template<typename A>
365
- int CouponList<A>::getMemDataStart() const {
366
- return HllUtil<A>::LIST_INT_ARR_START;
335
+ uint32_t CouponList<A>::getMemDataStart() const {
336
+ return hll_constants::LIST_INT_ARR_START;
367
337
  }
368
338
 
369
339
  template<typename A>
370
- int CouponList<A>::getPreInts() const {
371
- return HllUtil<A>::LIST_PREINTS;
340
+ uint8_t CouponList<A>::getPreInts() const {
341
+ return hll_constants::LIST_PREINTS;
372
342
  }
373
343
 
374
344
  template<typename A>
375
345
  bool CouponList<A>::isCompact() const { return false; }
376
346
 
377
347
  template<typename A>
378
- bool CouponList<A>::isOutOfOrderFlag() const { return oooFlag; }
348
+ bool CouponList<A>::isOutOfOrderFlag() const { return oooFlag_; }
379
349
 
380
350
  template<typename A>
381
351
  void CouponList<A>::putOutOfOrderFlag(bool oooFlag) {
382
- this->oooFlag = oooFlag;
383
- }
384
-
385
- template<typename A>
386
- int CouponList<A>::getLgCouponArrInts() const {
387
- return lgCouponArrInts;
352
+ oooFlag_ = oooFlag;
388
353
  }
389
354
 
390
355
  template<typename A>
391
- int* CouponList<A>::getCouponIntArr() const {
392
- return couponIntArr;
356
+ A CouponList<A>::getAllocator() const {
357
+ return coupons_.get_allocator();
393
358
  }
394
359
 
395
360
  template<typename A>
@@ -404,12 +369,12 @@ HllSketchImpl<A>* CouponList<A>::promoteHeapListOrSetToHll(CouponList& src) {
404
369
 
405
370
  template<typename A>
406
371
  coupon_iterator<A> CouponList<A>::begin(bool all) const {
407
- return coupon_iterator<A>(couponIntArr, 1 << lgCouponArrInts, 0, all);
372
+ return coupon_iterator<A>(coupons_.data(), coupons_.size(), 0, all);
408
373
  }
409
374
 
410
375
  template<typename A>
411
376
  coupon_iterator<A> CouponList<A>::end() const {
412
- return coupon_iterator<A>(couponIntArr, 1 << lgCouponArrInts, 1 << lgCouponArrInts, false);
377
+ return coupon_iterator<A>(coupons_.data(), coupons_.size(), coupons_.size(), false);
413
378
  }
414
379
 
415
380
  }
@@ -30,58 +30,57 @@ namespace datasketches {
30
30
  template<typename A>
31
31
  class HllSketchImplFactory;
32
32
 
33
- template<typename A = std::allocator<char>>
33
+ template<typename A>
34
34
  class CouponList : public HllSketchImpl<A> {
35
35
  public:
36
- explicit CouponList(int lgConfigK, target_hll_type tgtHllType, hll_mode mode);
37
- explicit CouponList(const CouponList& that);
38
- explicit CouponList(const CouponList& that, target_hll_type tgtHllType);
36
+ CouponList(uint8_t lgConfigK, target_hll_type tgtHllType, hll_mode mode, const A& allocator);
37
+ CouponList(const CouponList& that, target_hll_type tgtHllType);
39
38
 
40
- static CouponList* newList(const void* bytes, size_t len);
41
- static CouponList* newList(std::istream& is);
39
+ static CouponList* newList(const void* bytes, size_t len, const A& allocator);
40
+ static CouponList* newList(std::istream& is, const A& allocator);
42
41
  virtual vector_u8<A> serialize(bool compact, unsigned header_size_bytes) const;
43
42
  virtual void serialize(std::ostream& os, bool compact) const;
44
43
 
45
- virtual ~CouponList();
44
+ virtual ~CouponList() = default;
46
45
  virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const;
47
46
 
48
47
  virtual CouponList* copy() const;
49
48
  virtual CouponList* copyAs(target_hll_type tgtHllType) const;
50
49
 
51
- virtual HllSketchImpl<A>* couponUpdate(int coupon);
50
+ virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon);
52
51
 
53
52
  virtual double getEstimate() const;
54
53
  virtual double getCompositeEstimate() const;
55
- virtual double getUpperBound(int numStdDev) const;
56
- virtual double getLowerBound(int numStdDev) const;
54
+ virtual double getUpperBound(uint8_t numStdDev) const;
55
+ virtual double getLowerBound(uint8_t numStdDev) const;
57
56
 
58
57
  virtual bool isEmpty() const;
59
- virtual int getCouponCount() const;
58
+ virtual uint32_t getCouponCount() const;
60
59
 
61
60
  coupon_iterator<A> begin(bool all = false) const;
62
61
  coupon_iterator<A> end() const;
63
62
 
64
63
  protected:
65
- typedef typename std::allocator_traits<A>::template rebind_alloc<CouponList<A>> clAlloc;
64
+ using ClAlloc = typename std::allocator_traits<A>::template rebind_alloc<CouponList<A>>;
65
+
66
+ using vector_int = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
66
67
 
67
68
  HllSketchImpl<A>* promoteHeapListToSet(CouponList& list);
68
69
  HllSketchImpl<A>* promoteHeapListOrSetToHll(CouponList& src);
69
70
 
70
- virtual int getUpdatableSerializationBytes() const;
71
- virtual int getCompactSerializationBytes() const;
72
- virtual int getMemDataStart() const;
73
- virtual int getPreInts() const;
71
+ virtual uint32_t getUpdatableSerializationBytes() const;
72
+ virtual uint32_t getCompactSerializationBytes() const;
73
+ virtual uint32_t getMemDataStart() const;
74
+ virtual uint8_t getPreInts() const;
74
75
  virtual bool isCompact() const;
75
76
  virtual bool isOutOfOrderFlag() const;
76
77
  virtual void putOutOfOrderFlag(bool oooFlag);
77
78
 
78
- virtual int getLgCouponArrInts() const;
79
- virtual int* getCouponIntArr() const;
79
+ virtual A getAllocator() const;
80
80
 
81
- int lgCouponArrInts;
82
- int couponCount;
83
- bool oooFlag;
84
- int* couponIntArr;
81
+ uint32_t couponCount_;
82
+ bool oooFlag_;
83
+ vector_int coupons_;
85
84
 
86
85
  friend class HllSketchImplFactory<A>;
87
86
  };
@@ -102,10 +102,8 @@ double CubicInterpolation<A>::usingXAndYTables(const double xArr[], const double
102
102
  else if (offset == numEntries-2) { // corner case
103
103
  return (interpolateUsingXAndYTables<A>(xArr, yArr, (offset-2), x));
104
104
  }
105
- else { // main case
106
- return (interpolateUsingXAndYTables<A>(xArr, yArr, (offset-1), x));
107
- }
108
- throw std::logic_error("Exception should be unreachable");
105
+ // main case
106
+ return (interpolateUsingXAndYTables<A>(xArr, yArr, (offset-1), x));
109
107
  }
110
108
 
111
109
  // In C: again-two-registers cubic_interpolate_aux L1368
@@ -24,7 +24,7 @@
24
24
 
25
25
  namespace datasketches {
26
26
 
27
- template<typename A = std::allocator<char>>
27
+ template<typename A = std::allocator<uint8_t>>
28
28
  class CubicInterpolation {
29
29
  public:
30
30
  static double usingXAndYTables(const double xArr[], const double yArr[],
@@ -40,4 +40,4 @@ class CubicInterpolation {
40
40
 
41
41
  #include "CubicInterpolation-internal.hpp"
42
42
 
43
- #endif /* _CUBICINTERPOLATION_HPP_ */
43
+ #endif /* _CUBICINTERPOLATION_HPP_ */
@@ -68,7 +68,7 @@ double HarmonicNumbers<A>::harmonicNumber(const uint64_t x_i) {
68
68
  if (x_i < NUM_EXACT_HARMONIC_NUMBERS) {
69
69
  return tableOfExactHarmonicNumbers[x_i];
70
70
  } else {
71
- double x = x_i;
71
+ double x = static_cast<double>(x_i);
72
72
  double invSq = 1.0 / (x * x);
73
73
  double sum = log(x) + EULER_MASCHERONI_CONSTANT + (1.0 / (2.0 * x));
74
74
  /* note: the number of terms included from this series expansion is appropriate
@@ -25,7 +25,7 @@
25
25
 
26
26
  namespace datasketches {
27
27
 
28
- template<typename A = std::allocator<char>>
28
+ template<typename A = std::allocator<uint8_t>>
29
29
  class HarmonicNumbers {
30
30
  public:
31
31
  /**
@@ -45,4 +45,4 @@ class HarmonicNumbers {
45
45
 
46
46
  #include "HarmonicNumbers-internal.hpp"
47
47
 
48
- #endif /* _HARMONICNUMBERS_HPP_ */
48
+ #endif /* _HARMONICNUMBERS_HPP_ */