datasketches 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/NOTICE +1 -1
  4. data/README.md +0 -2
  5. data/ext/datasketches/cpc_wrapper.cpp +3 -3
  6. data/ext/datasketches/kll_wrapper.cpp +0 -10
  7. data/lib/datasketches/version.rb +1 -1
  8. data/lib/datasketches.rb +1 -1
  9. data/vendor/datasketches-cpp/CMakeLists.txt +23 -20
  10. data/vendor/datasketches-cpp/CODE_OF_CONDUCT.md +3 -0
  11. data/vendor/datasketches-cpp/CONTRIBUTING.md +50 -0
  12. data/vendor/datasketches-cpp/Doxyfile +2827 -0
  13. data/vendor/datasketches-cpp/LICENSE +0 -76
  14. data/vendor/datasketches-cpp/README.md +1 -3
  15. data/vendor/datasketches-cpp/common/CMakeLists.txt +12 -11
  16. data/vendor/datasketches-cpp/common/include/MurmurHash3.h +25 -27
  17. data/vendor/datasketches-cpp/common/include/common_defs.hpp +15 -10
  18. data/vendor/datasketches-cpp/common/include/count_zeros.hpp +11 -2
  19. data/vendor/datasketches-cpp/common/include/kolmogorov_smirnov.hpp +9 -6
  20. data/vendor/datasketches-cpp/common/include/memory_operations.hpp +5 -4
  21. data/vendor/datasketches-cpp/common/include/optional.hpp +148 -0
  22. data/vendor/datasketches-cpp/common/include/quantiles_sorted_view.hpp +95 -2
  23. data/vendor/datasketches-cpp/common/include/quantiles_sorted_view_impl.hpp +1 -1
  24. data/vendor/datasketches-cpp/common/include/serde.hpp +69 -20
  25. data/vendor/datasketches-cpp/common/test/CMakeLists.txt +2 -2
  26. data/vendor/datasketches-cpp/common/test/integration_test.cpp +6 -0
  27. data/vendor/datasketches-cpp/common/test/optional_test.cpp +85 -0
  28. data/vendor/datasketches-cpp/common/test/test_allocator.hpp +14 -14
  29. data/vendor/datasketches-cpp/{python/src/__init__.py → count/CMakeLists.txt} +25 -1
  30. data/vendor/datasketches-cpp/count/include/count_min.hpp +405 -0
  31. data/vendor/datasketches-cpp/count/include/count_min_impl.hpp +497 -0
  32. data/vendor/datasketches-cpp/{MANIFEST.in → count/test/CMakeLists.txt} +23 -20
  33. data/vendor/datasketches-cpp/count/test/count_min_allocation_test.cpp +155 -0
  34. data/vendor/datasketches-cpp/count/test/count_min_test.cpp +303 -0
  35. data/vendor/datasketches-cpp/cpc/include/cpc_common.hpp +14 -20
  36. data/vendor/datasketches-cpp/cpc/include/cpc_compressor.hpp +7 -4
  37. data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +17 -17
  38. data/vendor/datasketches-cpp/cpc/include/cpc_confidence.hpp +3 -3
  39. data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +40 -40
  40. data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +14 -11
  41. data/vendor/datasketches-cpp/cpc/include/cpc_union.hpp +35 -11
  42. data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +8 -8
  43. data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +16 -8
  44. data/vendor/datasketches-cpp/cpc/include/u32_table.hpp +3 -2
  45. data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +5 -5
  46. data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +20 -7
  47. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_deserialize_from_java_test.cpp +60 -0
  48. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_serialize_for_java.cpp +38 -0
  49. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +4 -29
  50. data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +4 -4
  51. data/vendor/datasketches-cpp/{tox.ini → density/CMakeLists.txt} +24 -8
  52. data/vendor/datasketches-cpp/density/include/density_sketch.hpp +256 -0
  53. data/vendor/datasketches-cpp/density/include/density_sketch_impl.hpp +543 -0
  54. data/vendor/datasketches-cpp/{python/datasketches/__init__.py → density/test/CMakeLists.txt} +15 -3
  55. data/vendor/datasketches-cpp/density/test/density_sketch_test.cpp +244 -0
  56. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +21 -9
  57. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +6 -4
  58. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +9 -3
  59. data/vendor/datasketches-cpp/fi/test/CMakeLists.txt +14 -1
  60. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_deserialize_from_java_test.cpp +95 -0
  61. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_serialize_for_java.cpp +83 -0
  62. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_test.cpp +3 -42
  63. data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +2 -2
  64. data/vendor/datasketches-cpp/hll/include/CouponList.hpp +3 -1
  65. data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +19 -11
  66. data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +2 -5
  67. data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +19 -7
  68. data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +1 -1
  69. data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +98 -42
  70. data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +2 -0
  71. data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +94 -61
  72. data/vendor/datasketches-cpp/hll/include/HllArray.hpp +20 -8
  73. data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +4 -4
  74. data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +3 -1
  75. data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +3 -21
  76. data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +8 -0
  77. data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +14 -18
  78. data/vendor/datasketches-cpp/hll/include/coupon_iterator-internal.hpp +1 -1
  79. data/vendor/datasketches-cpp/hll/include/coupon_iterator.hpp +8 -2
  80. data/vendor/datasketches-cpp/hll/include/hll.hpp +79 -65
  81. data/vendor/datasketches-cpp/hll/test/CMakeLists.txt +14 -1
  82. data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +7 -1
  83. data/vendor/datasketches-cpp/hll/test/ToFromByteArrayTest.cpp +0 -68
  84. data/vendor/datasketches-cpp/hll/test/hll_sketch_deserialize_from_java_test.cpp +69 -0
  85. data/vendor/datasketches-cpp/hll/test/hll_sketch_serialize_for_java.cpp +52 -0
  86. data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +0 -1
  87. data/vendor/datasketches-cpp/kll/include/kll_helper_impl.hpp +2 -2
  88. data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +79 -53
  89. data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +61 -132
  90. data/vendor/datasketches-cpp/kll/test/CMakeLists.txt +14 -1
  91. data/vendor/datasketches-cpp/kll/test/kll_sketch_deserialize_from_java_test.cpp +103 -0
  92. data/vendor/datasketches-cpp/kll/test/kll_sketch_serialize_for_java.cpp +62 -0
  93. data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +5 -40
  94. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch.hpp +76 -54
  95. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch_impl.hpp +66 -136
  96. data/vendor/datasketches-cpp/quantiles/test/CMakeLists.txt +14 -1
  97. data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_deserialize_from_java_test.cpp +84 -0
  98. data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_serialize_for_java.cpp +52 -0
  99. data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_test.cpp +15 -39
  100. data/vendor/datasketches-cpp/req/include/req_common.hpp +7 -3
  101. data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +2 -4
  102. data/vendor/datasketches-cpp/req/include/req_sketch.hpp +105 -26
  103. data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +50 -111
  104. data/vendor/datasketches-cpp/req/test/CMakeLists.txt +14 -1
  105. data/vendor/datasketches-cpp/req/test/req_sketch_deserialize_from_java_test.cpp +55 -0
  106. data/vendor/datasketches-cpp/{tuple/include/array_of_doubles_intersection_impl.hpp → req/test/req_sketch_serialize_for_java.cpp} +12 -7
  107. data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +3 -89
  108. data/vendor/datasketches-cpp/sampling/CMakeLists.txt +4 -0
  109. data/vendor/datasketches-cpp/sampling/include/ebpps_sample.hpp +210 -0
  110. data/vendor/datasketches-cpp/sampling/include/ebpps_sample_impl.hpp +535 -0
  111. data/vendor/datasketches-cpp/sampling/include/ebpps_sketch.hpp +281 -0
  112. data/vendor/datasketches-cpp/sampling/include/ebpps_sketch_impl.hpp +531 -0
  113. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +89 -32
  114. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +33 -19
  115. data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +13 -10
  116. data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +23 -19
  117. data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +55 -8
  118. data/vendor/datasketches-cpp/sampling/test/ebpps_allocation_test.cpp +96 -0
  119. data/vendor/datasketches-cpp/sampling/test/ebpps_sample_test.cpp +137 -0
  120. data/vendor/datasketches-cpp/sampling/test/ebpps_sketch_test.cpp +266 -0
  121. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_deserialize_from_java_test.cpp +81 -0
  122. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_serialize_for_java.cpp +54 -0
  123. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +33 -51
  124. data/vendor/datasketches-cpp/sampling/test/var_opt_union_deserialize_from_java_test.cpp +50 -0
  125. data/vendor/datasketches-cpp/sampling/test/var_opt_union_serialize_for_java.cpp +56 -0
  126. data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +0 -20
  127. data/vendor/datasketches-cpp/theta/CMakeLists.txt +1 -0
  128. data/vendor/datasketches-cpp/theta/include/bit_packing.hpp +6279 -0
  129. data/vendor/datasketches-cpp/theta/include/bounds_on_ratios_in_sampled_sets.hpp +1 -0
  130. data/vendor/datasketches-cpp/theta/include/bounds_on_ratios_in_theta_sketched_sets.hpp +7 -6
  131. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser.hpp +14 -8
  132. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser_impl.hpp +60 -46
  133. data/vendor/datasketches-cpp/theta/include/theta_a_not_b.hpp +20 -5
  134. data/vendor/datasketches-cpp/theta/include/theta_constants.hpp +10 -4
  135. data/vendor/datasketches-cpp/theta/include/theta_helpers.hpp +3 -1
  136. data/vendor/datasketches-cpp/theta/include/theta_intersection.hpp +13 -5
  137. data/vendor/datasketches-cpp/theta/include/theta_intersection_base_impl.hpp +5 -5
  138. data/vendor/datasketches-cpp/theta/include/theta_intersection_impl.hpp +3 -3
  139. data/vendor/datasketches-cpp/theta/include/theta_jaccard_similarity.hpp +2 -1
  140. data/vendor/datasketches-cpp/theta/include/theta_jaccard_similarity_base.hpp +1 -0
  141. data/vendor/datasketches-cpp/theta/include/theta_set_difference_base_impl.hpp +1 -1
  142. data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +180 -33
  143. data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +430 -130
  144. data/vendor/datasketches-cpp/theta/include/theta_union.hpp +17 -10
  145. data/vendor/datasketches-cpp/theta/include/theta_union_base_impl.hpp +10 -10
  146. data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +3 -3
  147. data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base.hpp +21 -6
  148. data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base_impl.hpp +13 -3
  149. data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +15 -1
  150. data/vendor/datasketches-cpp/theta/test/bit_packing_test.cpp +80 -0
  151. data/vendor/datasketches-cpp/theta/test/theta_sketch_deserialize_from_java_test.cpp +57 -0
  152. data/vendor/datasketches-cpp/theta/test/theta_sketch_serialize_for_java.cpp +61 -0
  153. data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +39 -188
  154. data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +25 -0
  155. data/vendor/datasketches-cpp/tuple/CMakeLists.txt +8 -7
  156. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_sketch.hpp +19 -144
  157. data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_a_not_b.hpp → array_tuple_a_not_b.hpp} +24 -16
  158. data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_a_not_b_impl.hpp → array_tuple_a_not_b_impl.hpp} +4 -4
  159. data/vendor/datasketches-cpp/tuple/include/array_tuple_intersection.hpp +65 -0
  160. data/vendor/datasketches-cpp/tuple/include/array_tuple_intersection_impl.hpp +31 -0
  161. data/vendor/datasketches-cpp/tuple/include/array_tuple_sketch.hpp +237 -0
  162. data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_sketch_impl.hpp → array_tuple_sketch_impl.hpp} +40 -41
  163. data/vendor/datasketches-cpp/tuple/include/array_tuple_union.hpp +81 -0
  164. data/vendor/datasketches-cpp/tuple/include/array_tuple_union_impl.hpp +43 -0
  165. data/vendor/datasketches-cpp/tuple/include/tuple_a_not_b.hpp +11 -2
  166. data/vendor/datasketches-cpp/tuple/include/tuple_intersection.hpp +17 -10
  167. data/vendor/datasketches-cpp/tuple/include/tuple_jaccard_similarity.hpp +2 -1
  168. data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +95 -32
  169. data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +2 -1
  170. data/vendor/datasketches-cpp/tuple/include/tuple_union.hpp +19 -11
  171. data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +16 -1
  172. data/vendor/datasketches-cpp/tuple/test/aod_sketch_deserialize_from_java_test.cpp +76 -0
  173. data/vendor/datasketches-cpp/tuple/test/aod_sketch_serialize_for_java.cpp +62 -0
  174. data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +5 -129
  175. data/vendor/datasketches-cpp/tuple/test/engagement_test.cpp +85 -89
  176. data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +3 -1
  177. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_deserialize_from_java_test.cpp +47 -0
  178. data/vendor/datasketches-cpp/{python/src/datasketches.cpp → tuple/test/tuple_sketch_serialize_for_java.cpp} +16 -30
  179. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +1 -1
  180. data/vendor/datasketches-cpp/version.cfg.in +1 -1
  181. metadata +61 -79
  182. data/vendor/datasketches-cpp/fi/test/items_sketch_string_from_java.sk +0 -0
  183. data/vendor/datasketches-cpp/fi/test/items_sketch_string_utf8_from_java.sk +0 -0
  184. data/vendor/datasketches-cpp/fi/test/longs_sketch_from_java.sk +0 -0
  185. data/vendor/datasketches-cpp/hll/test/array6_from_java.sk +0 -0
  186. data/vendor/datasketches-cpp/hll/test/compact_array4_from_java.sk +0 -0
  187. data/vendor/datasketches-cpp/hll/test/compact_set_from_java.sk +0 -0
  188. data/vendor/datasketches-cpp/hll/test/list_from_java.sk +0 -0
  189. data/vendor/datasketches-cpp/hll/test/updatable_array4_from_java.sk +0 -0
  190. data/vendor/datasketches-cpp/hll/test/updatable_set_from_java.sk +0 -0
  191. data/vendor/datasketches-cpp/kll/test/kll_sketch_from_java.sk +0 -0
  192. data/vendor/datasketches-cpp/pyproject.toml +0 -23
  193. data/vendor/datasketches-cpp/python/CMakeLists.txt +0 -81
  194. data/vendor/datasketches-cpp/python/README.md +0 -85
  195. data/vendor/datasketches-cpp/python/datasketches/PySerDe.py +0 -104
  196. data/vendor/datasketches-cpp/python/include/py_serde.hpp +0 -113
  197. data/vendor/datasketches-cpp/python/jupyter/CPCSketch.ipynb +0 -345
  198. data/vendor/datasketches-cpp/python/jupyter/FrequentItemsSketch.ipynb +0 -354
  199. data/vendor/datasketches-cpp/python/jupyter/HLLSketch.ipynb +0 -346
  200. data/vendor/datasketches-cpp/python/jupyter/KLLSketch.ipynb +0 -463
  201. data/vendor/datasketches-cpp/python/jupyter/ThetaSketchNotebook.ipynb +0 -403
  202. data/vendor/datasketches-cpp/python/pybind11Path.cmd +0 -21
  203. data/vendor/datasketches-cpp/python/src/cpc_wrapper.cpp +0 -90
  204. data/vendor/datasketches-cpp/python/src/fi_wrapper.cpp +0 -128
  205. data/vendor/datasketches-cpp/python/src/hll_wrapper.cpp +0 -134
  206. data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +0 -210
  207. data/vendor/datasketches-cpp/python/src/ks_wrapper.cpp +0 -68
  208. data/vendor/datasketches-cpp/python/src/py_serde.cpp +0 -111
  209. data/vendor/datasketches-cpp/python/src/quantiles_wrapper.cpp +0 -204
  210. data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +0 -215
  211. data/vendor/datasketches-cpp/python/src/theta_wrapper.cpp +0 -172
  212. data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +0 -490
  213. data/vendor/datasketches-cpp/python/src/vo_wrapper.cpp +0 -173
  214. data/vendor/datasketches-cpp/python/tests/__init__.py +0 -16
  215. data/vendor/datasketches-cpp/python/tests/cpc_test.py +0 -64
  216. data/vendor/datasketches-cpp/python/tests/fi_test.py +0 -110
  217. data/vendor/datasketches-cpp/python/tests/hll_test.py +0 -130
  218. data/vendor/datasketches-cpp/python/tests/kll_test.py +0 -125
  219. data/vendor/datasketches-cpp/python/tests/quantiles_test.py +0 -126
  220. data/vendor/datasketches-cpp/python/tests/req_test.py +0 -126
  221. data/vendor/datasketches-cpp/python/tests/theta_test.py +0 -146
  222. data/vendor/datasketches-cpp/python/tests/vector_of_kll_test.py +0 -148
  223. data/vendor/datasketches-cpp/python/tests/vo_test.py +0 -125
  224. data/vendor/datasketches-cpp/req/test/req_float_empty_from_java.sk +0 -0
  225. data/vendor/datasketches-cpp/req/test/req_float_estimation_from_java.sk +0 -0
  226. data/vendor/datasketches-cpp/req/test/req_float_exact_from_java.sk +0 -0
  227. data/vendor/datasketches-cpp/req/test/req_float_raw_items_from_java.sk +0 -0
  228. data/vendor/datasketches-cpp/req/test/req_float_single_item_from_java.sk +0 -0
  229. data/vendor/datasketches-cpp/sampling/test/binaries_from_java.txt +0 -67
  230. data/vendor/datasketches-cpp/sampling/test/varopt_sketch_long_sampling.sk +0 -0
  231. data/vendor/datasketches-cpp/sampling/test/varopt_sketch_string_exact.sk +0 -0
  232. data/vendor/datasketches-cpp/sampling/test/varopt_union_double_sampling.sk +0 -0
  233. data/vendor/datasketches-cpp/setup.py +0 -110
  234. data/vendor/datasketches-cpp/theta/test/theta_compact_empty_from_java.sk +0 -0
  235. data/vendor/datasketches-cpp/theta/test/theta_compact_estimation_from_java.sk +0 -0
  236. data/vendor/datasketches-cpp/theta/test/theta_compact_exact_from_java.sk +0 -0
  237. data/vendor/datasketches-cpp/theta/test/theta_compact_single_item_from_java.sk +0 -0
  238. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_intersection.hpp +0 -52
  239. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union.hpp +0 -81
  240. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union_impl.hpp +0 -43
  241. data/vendor/datasketches-cpp/tuple/test/aod_1_compact_empty_from_java.sk +0 -1
  242. data/vendor/datasketches-cpp/tuple/test/aod_1_compact_estimation_from_java.sk +0 -0
  243. data/vendor/datasketches-cpp/tuple/test/aod_1_compact_non_empty_no_entries_from_java.sk +0 -0
  244. data/vendor/datasketches-cpp/tuple/test/aod_2_compact_exact_from_java.sk +0 -0
  245. data/vendor/datasketches-cpp/tuple/test/aod_3_compact_empty_from_java.sk +0 -1
@@ -0,0 +1,303 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ #include <catch2/catch.hpp>
21
+ #include <vector>
22
+ #include <cstring>
23
+ #include <sstream>
24
+ #include <fstream>
25
+
26
+ #include "count_min.hpp"
27
+ #include "common_defs.hpp"
28
+
29
+ namespace datasketches {
30
+
31
+ TEST_CASE("CM init - throws") {
32
+ REQUIRE_THROWS_AS(count_min_sketch<uint64_t>(5, 1), std::invalid_argument);
33
+ REQUIRE_THROWS_AS(count_min_sketch<uint64_t>(4, 268435456), std::invalid_argument);
34
+ }
35
+
36
+ TEST_CASE("CM init") {
37
+ uint8_t n_hashes = 3;
38
+ uint32_t n_buckets = 5;
39
+ uint64_t seed = 1234567;
40
+ count_min_sketch<uint64_t> c(n_hashes, n_buckets, seed);
41
+ REQUIRE(c.get_num_hashes() == n_hashes);
42
+ REQUIRE(c.get_num_buckets() == n_buckets);
43
+ REQUIRE(c.get_seed() == seed);
44
+ REQUIRE(c.is_empty());
45
+
46
+ for (auto x: c) {
47
+ REQUIRE(x == 0);
48
+ }
49
+
50
+ // Check the default seed is appropriately set.
51
+ count_min_sketch<uint64_t> c1(n_hashes, n_buckets);
52
+ REQUIRE(c1.get_seed() == DEFAULT_SEED);
53
+ }
54
+
55
+ TEST_CASE("CM parameter suggestions", "[error parameters]") {
56
+
57
+ // Bucket suggestions
58
+ REQUIRE_THROWS(count_min_sketch<uint64_t>::suggest_num_buckets(-1.0), "Confidence must be between 0 and 1.0 (inclusive)." );
59
+ REQUIRE(count_min_sketch<uint64_t>::suggest_num_buckets(0.2) == 14);
60
+ REQUIRE(count_min_sketch<uint64_t>::suggest_num_buckets(0.1) == 28);
61
+ REQUIRE(count_min_sketch<uint64_t>::suggest_num_buckets(0.05) == 55);
62
+ REQUIRE(count_min_sketch<uint64_t>::suggest_num_buckets(0.01) == 272);
63
+
64
+ // Check that the sketch get_epsilon acts inversely to suggest_num_buckets
65
+ uint8_t n_hashes = 3;
66
+ REQUIRE(count_min_sketch<uint64_t>(n_hashes, 14).get_relative_error() <= 0.2);
67
+ REQUIRE(count_min_sketch<uint64_t>(n_hashes, 28).get_relative_error() <= 0.1);
68
+ REQUIRE(count_min_sketch<uint64_t>(n_hashes, 55).get_relative_error() <= 0.05);
69
+ REQUIRE(count_min_sketch<uint64_t>(n_hashes, 272).get_relative_error() <= 0.01);
70
+
71
+ // Hash suggestions
72
+ REQUIRE_THROWS(count_min_sketch<uint64_t>::suggest_num_hashes(10.0), "Confidence must be between 0 and 1.0 (inclusive)." );
73
+ REQUIRE_THROWS(count_min_sketch<uint64_t>::suggest_num_hashes(-1.0), "Confidence must be between 0 and 1.0 (inclusive)." );
74
+ REQUIRE(count_min_sketch<uint64_t>::suggest_num_hashes(0.682689492) == 2); // 1 STDDEV
75
+ REQUIRE(count_min_sketch<uint64_t>::suggest_num_hashes(0.954499736) == 4); // 2 STDDEV
76
+ REQUIRE(count_min_sketch<uint64_t>::suggest_num_hashes(0.997300204) == 6); // 3 STDDEV
77
+ }
78
+
79
+ TEST_CASE("CM one update: uint64_t") {
80
+ uint8_t n_hashes = 3;
81
+ uint32_t n_buckets = 5;
82
+ uint64_t seed = 9223372036854775807; //1234567;
83
+ uint64_t inserted_weight = 0;
84
+ count_min_sketch<uint64_t> c(n_hashes, n_buckets, seed);
85
+ std::string x = "x";
86
+
87
+ REQUIRE(c.is_empty());
88
+ REQUIRE(c.get_estimate("x") == 0); // No items in sketch so estimates should be zero
89
+ c.update(x);
90
+ REQUIRE(!c.is_empty());
91
+ REQUIRE(c.get_estimate(x) == 1);
92
+ inserted_weight += 1;
93
+
94
+ uint64_t w = 9;
95
+ inserted_weight += w;
96
+ c.update(x, w);
97
+ REQUIRE(c.get_estimate(x) == inserted_weight);
98
+
99
+ // Doubles are converted to uint64_t
100
+ double w1 = 10.0;
101
+ inserted_weight += static_cast<uint64_t>(w1);
102
+ c.update(x, static_cast<uint64_t>(w1));
103
+ REQUIRE(c.get_estimate(x) == inserted_weight);
104
+ REQUIRE(c.get_total_weight() == inserted_weight);
105
+ REQUIRE(c.get_estimate(x) <= c.get_upper_bound(x));
106
+ REQUIRE(c.get_estimate(x) >= c.get_lower_bound(x));
107
+ }
108
+
109
+ TEST_CASE("CM frequency cancellation") {
110
+ count_min_sketch<int64_t> c(1, 5);
111
+ c.update("x");
112
+ c.update("y", -1);
113
+ REQUIRE(c.get_total_weight() == 2);
114
+ REQUIRE(c.get_estimate("x") == 1);
115
+ REQUIRE(c.get_estimate("y") == -1);
116
+ }
117
+
118
+ TEST_CASE("CM frequency estimates") {
119
+ int number_of_items = 10;
120
+ std::vector<uint64_t> data(number_of_items);
121
+ std::vector<uint64_t> frequencies(number_of_items);
122
+
123
+ // Populate data vector
124
+ for (int i = 0; i < number_of_items; ++i) {
125
+ data[i] = i;
126
+ frequencies[i] = 1ULL << (number_of_items - i);
127
+ }
128
+
129
+ double relative_error = 0.1;
130
+ double confidence = 0.99;
131
+ uint32_t n_buckets = count_min_sketch<uint64_t>::suggest_num_buckets(relative_error);
132
+ uint8_t n_hashes = count_min_sketch<uint64_t>::suggest_num_hashes(confidence);
133
+
134
+ count_min_sketch<uint64_t> c(n_hashes, n_buckets);
135
+ for (int i = 0; i < number_of_items; ++i) {
136
+ uint64_t value = data[i];
137
+ uint64_t freq = frequencies[i];
138
+ c.update(value, freq);
139
+ }
140
+
141
+ for (const auto i: data) {
142
+ uint64_t est = c.get_estimate(i);
143
+ uint64_t upp = c.get_upper_bound(i);
144
+ uint64_t low = c.get_lower_bound(i);
145
+ REQUIRE(est <= upp);
146
+ REQUIRE(est >= low);
147
+ }
148
+ }
149
+
150
+ TEST_CASE("CM merge - reject", "[reject cases]") {
151
+ double relative_error = 0.25;
152
+ double confidence = 0.9;
153
+ uint32_t n_buckets = count_min_sketch<uint64_t>::suggest_num_buckets(relative_error);
154
+ uint8_t n_hashes = count_min_sketch<uint64_t>::suggest_num_hashes(confidence);
155
+ count_min_sketch<uint64_t> s(n_hashes, n_buckets, 9082435234709287);
156
+
157
+ // Generate sketches that we cannot merge into ie they disagree on at least one of the config entries
158
+ count_min_sketch<uint64_t> s1(n_hashes+1, n_buckets); // incorrect number of hashes
159
+ count_min_sketch<uint64_t> s2(n_hashes, n_buckets + 1); // incorrect number of buckets
160
+ count_min_sketch<uint64_t> s3(n_hashes, n_buckets, 1); // incorrect seed
161
+ std::vector<count_min_sketch<uint64_t>> sketches = {s1, s2, s3};
162
+
163
+ // Fail cases
164
+ REQUIRE_THROWS(s.merge(s), "Cannot merge a sketch with itself." );
165
+ for (count_min_sketch<uint64_t> sk : sketches) {
166
+ REQUIRE_THROWS(s.merge(sk), "Incompatible sketch config." );
167
+ }
168
+ }
169
+
170
+ TEST_CASE("CM merge - pass", "[acceptable cases]") {
171
+ double relative_error = 0.25;
172
+ double confidence = 0.9;
173
+ uint32_t n_buckets = count_min_sketch<uint64_t>::suggest_num_buckets(relative_error);
174
+ uint8_t n_hashes = count_min_sketch<uint64_t>::suggest_num_hashes(confidence);
175
+ count_min_sketch<uint64_t> s(n_hashes, n_buckets);
176
+ uint8_t s_hashes = s.get_num_hashes();
177
+ uint32_t s_buckets = s.get_num_buckets();
178
+ count_min_sketch<uint64_t> t(s_hashes, s_buckets);
179
+
180
+ // Merge in an all-zeros sketch t. Should not change the total weight.
181
+ s.merge(t);
182
+ REQUIRE(s.get_total_weight() == 0 );
183
+
184
+ std::vector<uint64_t> data = {2,3,5,7};
185
+ for (auto d: data) {
186
+ s.update(d);
187
+ t.update(d);
188
+ }
189
+ s.merge(t);
190
+
191
+ REQUIRE(s.get_total_weight() == 2 * t.get_total_weight());
192
+
193
+ // Estimator checks.
194
+ for (auto x: data) {
195
+ REQUIRE(s.get_estimate(x) <= s.get_upper_bound(x));
196
+ REQUIRE(s.get_estimate(x) <= 2); // True frequency x == 2 for all x.
197
+ }
198
+ }
199
+
200
+ TEST_CASE("CountMin sketch: serialize-deserialize empty", "[cm_sketch]") {
201
+ uint8_t n_hashes = 1;
202
+ uint32_t n_buckets = 5;
203
+ std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
204
+ count_min_sketch<uint64_t> c(n_hashes, n_buckets);
205
+ c.serialize(s);
206
+ count_min_sketch<uint64_t> d = count_min_sketch<uint64_t>::deserialize(s, DEFAULT_SEED);
207
+ REQUIRE(c.get_num_hashes() == d.get_num_hashes());
208
+ REQUIRE(c.get_num_buckets() == d.get_num_buckets());
209
+ REQUIRE(c.get_seed() == d.get_seed());
210
+ uint64_t zero = 0;
211
+ REQUIRE(c.get_estimate(zero) == d.get_estimate(zero));
212
+ REQUIRE(c.get_total_weight() == d.get_total_weight());
213
+
214
+ // Check that all entries are equal and 0
215
+ for (auto di: d) {
216
+ REQUIRE(di == 0);
217
+ }
218
+ std::ofstream os("count_min-empty.bin");
219
+ c.serialize(os);
220
+ }
221
+
222
+ TEST_CASE("CountMin sketch: serialize-deserialize non-empty", "[cm_sketch]") {
223
+ uint8_t n_hashes = 3;
224
+ uint32_t n_buckets = 1024;
225
+ std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
226
+ count_min_sketch<uint64_t> c(n_hashes, n_buckets);
227
+ for (uint64_t i = 0; i < 10; ++i) c.update(i, 10 * i * i);
228
+ c.serialize(s);
229
+ count_min_sketch<uint64_t> d = count_min_sketch<uint64_t>::deserialize(s, DEFAULT_SEED);
230
+ REQUIRE(c.get_num_hashes() == d.get_num_hashes());
231
+ REQUIRE(c.get_num_buckets() == d.get_num_buckets());
232
+ REQUIRE(c.get_seed() == d.get_seed());
233
+ REQUIRE(c.get_total_weight() == d.get_total_weight());
234
+ for (uint64_t i = 0; i < 10; ++i) {
235
+ REQUIRE(c.get_estimate(i) == d.get_estimate(i));
236
+ }
237
+
238
+ auto c_it = c.begin();
239
+ auto d_it = d.begin();
240
+ while (c_it != c.end()) {
241
+ REQUIRE(*c_it == *d_it);
242
+ ++c_it;
243
+ ++d_it;
244
+ }
245
+
246
+ std::ofstream os("count_min-non-empty.bin");
247
+ c.serialize(os);
248
+ }
249
+
250
+ TEST_CASE("CountMin sketch: bytes serialize-deserialize empty", "[cm_sketch]") {
251
+ uint8_t n_hashes = 3;
252
+ uint32_t n_buckets = 32;
253
+ count_min_sketch<uint64_t> c(n_hashes, n_buckets);
254
+ auto bytes = c.serialize();
255
+
256
+ REQUIRE_THROWS_AS(count_min_sketch<uint64_t>::deserialize(bytes.data(), bytes.size(), DEFAULT_SEED-1), std::invalid_argument);
257
+ auto d = count_min_sketch<uint64_t>::deserialize(bytes.data(), bytes.size(), DEFAULT_SEED);
258
+ REQUIRE(c.get_num_hashes() == d.get_num_hashes());
259
+ REQUIRE(c.get_num_buckets() == d.get_num_buckets());
260
+ REQUIRE(c.get_seed() == d.get_seed());
261
+ uint64_t zero = 0;
262
+ REQUIRE(c.get_estimate(zero) == d.get_estimate(zero));
263
+ REQUIRE(c.get_total_weight() == d.get_total_weight());
264
+
265
+ // Check that all entries are equal and 0
266
+ for (auto di: d) {
267
+ REQUIRE(di == 0);
268
+ }
269
+ }
270
+
271
+
272
+ TEST_CASE("CountMin sketch: bytes serialize-deserialize non-empty", "[cm_sketch]") {
273
+ uint8_t n_hashes = 5;
274
+ uint32_t n_buckets = 64;
275
+ count_min_sketch<uint64_t> c(n_hashes, n_buckets);
276
+ for(uint64_t i=0; i < 10; ++i) c.update(i,10*i*i);
277
+
278
+ auto bytes = c.serialize();
279
+ REQUIRE_THROWS_AS(count_min_sketch<uint64_t>::deserialize(bytes.data(), bytes.size(), DEFAULT_SEED-1), std::invalid_argument);
280
+ auto d = count_min_sketch<uint64_t>::deserialize(bytes.data(), bytes.size(), DEFAULT_SEED);
281
+
282
+ REQUIRE(c.get_num_hashes() == d.get_num_hashes());
283
+ REQUIRE(c.get_num_buckets() == d.get_num_buckets());
284
+ REQUIRE(c.get_seed() == d.get_seed());
285
+ REQUIRE(c.get_total_weight() == d.get_total_weight());
286
+
287
+ // Check that all entries are equal
288
+ auto c_it = c.begin();
289
+ auto d_it = d.begin();
290
+ while (c_it != c.end()) {
291
+ REQUIRE(*c_it == *d_it);
292
+ ++c_it;
293
+ ++d_it;
294
+ }
295
+
296
+ // Check that the estimates agree
297
+ for (uint64_t i = 0; i < 10; ++i) {
298
+ REQUIRE(c.get_estimate(i) == d.get_estimate(i));
299
+ }
300
+
301
+ }
302
+
303
+ } /* namespace datasketches */
@@ -26,45 +26,39 @@
26
26
 
27
27
  namespace datasketches {
28
28
 
29
+ /// CPC constants
29
30
  namespace cpc_constants {
30
- const uint8_t MIN_LG_K = 4;
31
- const uint8_t MAX_LG_K = 26;
32
- const uint8_t DEFAULT_LG_K = 11;
31
+ /// min log2 of K
32
+ const uint8_t MIN_LG_K = 4;
33
+ /// max log2 of K
34
+ const uint8_t MAX_LG_K = 26;
35
+ /// default log2 of K
36
+ const uint8_t DEFAULT_LG_K = 11;
33
37
  }
34
38
 
35
- // TODO: Redundant and deprecated. Will be removed in next major version release.
36
- static const uint8_t CPC_MIN_LG_K = cpc_constants::MIN_LG_K;
37
- static const uint8_t CPC_MAX_LG_K = cpc_constants::MAX_LG_K;
38
- static const uint8_t CPC_DEFAULT_LG_K = cpc_constants::DEFAULT_LG_K;
39
-
40
- template<typename A> using AllocU8 = typename std::allocator_traits<A>::template rebind_alloc<uint8_t>;
41
- template<typename A> using AllocU16 = typename std::allocator_traits<A>::template rebind_alloc<uint16_t>;
42
- template<typename A> using AllocU32 = typename std::allocator_traits<A>::template rebind_alloc<uint32_t>;
43
- template<typename A> using AllocU64 = typename std::allocator_traits<A>::template rebind_alloc<uint64_t>;
44
-
45
- template<typename A> using vector_u8 = std::vector<uint8_t, AllocU8<A>>;
46
- template<typename A> using vector_u32 = std::vector<uint32_t, AllocU32<A>>;
47
- template<typename A> using vector_u64 = std::vector<uint64_t, AllocU64<A>>;
48
-
49
39
  // forward declaration
50
40
  template<typename A> class u32_table;
51
41
 
52
42
  template<typename A>
53
43
  struct compressed_state {
44
+ using vector_u32 = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
45
+
54
46
  explicit compressed_state(const A& allocator): table_data(allocator), table_data_words(0), table_num_entries(0),
55
47
  window_data(allocator), window_data_words(0) {}
56
- vector_u32<A> table_data;
48
+ vector_u32 table_data;
57
49
  uint32_t table_data_words;
58
50
  uint32_t table_num_entries; // can be different from the number of entries in the sketch in hybrid mode
59
- vector_u32<A> window_data;
51
+ vector_u32 window_data;
60
52
  uint32_t window_data_words;
61
53
  };
62
54
 
63
55
  template<typename A>
64
56
  struct uncompressed_state {
57
+ using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
58
+
65
59
  explicit uncompressed_state(const A& allocator): table(allocator), window(allocator) {}
66
60
  u32_table<A> table;
67
- vector_u8<A> window;
61
+ vector_bytes window;
68
62
  };
69
63
 
70
64
  } /* namespace datasketches */
@@ -47,6 +47,9 @@ inline cpc_compressor<A>& get_compressor();
47
47
  template<typename A>
48
48
  class cpc_compressor {
49
49
  public:
50
+ using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
51
+ using vector_u32 = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
52
+
50
53
  void compress(const cpc_sketch_alloc<A>& source, compressed_state<A>& target) const;
51
54
  void uncompress(const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k, uint32_t num_coupons) const;
52
55
 
@@ -126,17 +129,17 @@ private:
126
129
  uint16_t* make_decoding_table(const uint16_t* encoding_table, unsigned num_byte_values);
127
130
  void validate_decoding_table(const uint16_t* decoding_table, const uint16_t* encoding_table) const;
128
131
 
129
- void compress_surprising_values(const vector_u32<A>& pairs, uint8_t lg_k, compressed_state<A>& result) const;
132
+ void compress_surprising_values(const vector_u32& pairs, uint8_t lg_k, compressed_state<A>& result) const;
130
133
  void compress_sliding_window(const uint8_t* window, uint8_t lg_k, uint32_t num_coupons, compressed_state<A>& target) const;
131
134
 
132
- vector_u32<A> uncompress_surprising_values(const uint32_t* data, uint32_t data_words, uint32_t num_pairs, uint8_t lg_k, const A& allocator) const;
133
- void uncompress_sliding_window(const uint32_t* data, uint32_t data_words, vector_u8<A>& window, uint8_t lg_k, uint32_t num_coupons) const;
135
+ vector_u32 uncompress_surprising_values(const uint32_t* data, uint32_t data_words, uint32_t num_pairs, uint8_t lg_k, const A& allocator) const;
136
+ void uncompress_sliding_window(const uint32_t* data, uint32_t data_words, vector_bytes& window, uint8_t lg_k, uint32_t num_coupons) const;
134
137
 
135
138
  static size_t safe_length_for_compressed_pair_buf(uint32_t k, uint32_t num_pairs, uint8_t num_base_bits);
136
139
  static size_t safe_length_for_compressed_window_buf(uint32_t k);
137
140
  static uint8_t determine_pseudo_phase(uint8_t lg_k, uint32_t c);
138
141
 
139
- static inline vector_u32<A> tricky_get_pairs_from_window(const uint8_t* window, uint32_t k, uint32_t num_pairs_to_get, uint32_t empty_space, const A& allocator);
142
+ static inline vector_u32 tricky_get_pairs_from_window(const uint8_t* window, uint32_t k, uint32_t num_pairs_to_get, uint32_t empty_space, const A& allocator);
140
143
  static inline uint8_t golomb_choose_number_of_base_bits(uint32_t k, uint64_t count);
141
144
  };
142
145
 
@@ -183,7 +183,7 @@ void cpc_compressor<A>::uncompress(const compressed_state<A>& source, uncompress
183
183
  template<typename A>
184
184
  void cpc_compressor<A>::compress_sparse_flavor(const cpc_sketch_alloc<A>& source, compressed_state<A>& result) const {
185
185
  if (source.sliding_window.size() > 0) throw std::logic_error("unexpected sliding window");
186
- vector_u32<A> pairs = source.surprising_value_table.unwrapping_get_items();
186
+ vector_u32 pairs = source.surprising_value_table.unwrapping_get_items();
187
187
  u32_table<A>::introspective_insertion_sort(pairs.data(), 0, pairs.size());
188
188
  compress_surprising_values(pairs, source.get_lg_k(), result);
189
189
  }
@@ -192,7 +192,7 @@ template<typename A>
192
192
  void cpc_compressor<A>::uncompress_sparse_flavor(const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k) const {
193
193
  if (source.window_data.size() > 0) throw std::logic_error("unexpected sliding window");
194
194
  if (source.table_data.size() == 0) throw std::logic_error("table is expected");
195
- vector_u32<A> pairs = uncompress_surprising_values(source.table_data.data(), source.table_data_words, source.table_num_entries,
195
+ vector_u32 pairs = uncompress_surprising_values(source.table_data.data(), source.table_data_words, source.table_num_entries,
196
196
  lg_k, source.table_data.get_allocator());
197
197
  target.table = u32_table<A>::make_from_pairs(pairs.data(), source.table_num_entries, lg_k, pairs.get_allocator());
198
198
  }
@@ -204,12 +204,12 @@ void cpc_compressor<A>::compress_hybrid_flavor(const cpc_sketch_alloc<A>& source
204
204
  if (source.sliding_window.size() == 0) throw std::logic_error("no sliding window");
205
205
  if (source.window_offset != 0) throw std::logic_error("window_offset != 0");
206
206
  const uint32_t k = 1 << source.get_lg_k();
207
- vector_u32<A> pairs_from_table = source.surprising_value_table.unwrapping_get_items();
207
+ vector_u32 pairs_from_table = source.surprising_value_table.unwrapping_get_items();
208
208
  const uint32_t num_pairs_from_table = static_cast<uint32_t>(pairs_from_table.size());
209
209
  if (num_pairs_from_table > 0) u32_table<A>::introspective_insertion_sort(pairs_from_table.data(), 0, num_pairs_from_table);
210
210
  const uint32_t num_pairs_from_window = source.get_num_coupons() - num_pairs_from_table; // because the window offset is zero
211
211
 
212
- vector_u32<A> all_pairs = tricky_get_pairs_from_window(source.sliding_window.data(), k, num_pairs_from_window, num_pairs_from_table, source.get_allocator());
212
+ vector_u32 all_pairs = tricky_get_pairs_from_window(source.sliding_window.data(), k, num_pairs_from_window, num_pairs_from_table, source.get_allocator());
213
213
 
214
214
  u32_table<A>::merge(
215
215
  pairs_from_table.data(), 0, pairs_from_table.size(),
@@ -224,7 +224,7 @@ template<typename A>
224
224
  void cpc_compressor<A>::uncompress_hybrid_flavor(const compressed_state<A>& source, uncompressed_state<A>& target, uint8_t lg_k) const {
225
225
  if (source.window_data.size() > 0) throw std::logic_error("window is not expected");
226
226
  if (source.table_data.size() == 0) throw std::logic_error("table is expected");
227
- vector_u32<A> pairs = uncompress_surprising_values(source.table_data.data(), source.table_data_words, source.table_num_entries,
227
+ vector_u32 pairs = uncompress_surprising_values(source.table_data.data(), source.table_data_words, source.table_num_entries,
228
228
  lg_k, source.table_data.get_allocator());
229
229
 
230
230
  // In the hybrid flavor, some of these pairs actually
@@ -250,7 +250,7 @@ void cpc_compressor<A>::uncompress_hybrid_flavor(const compressed_state<A>& sour
250
250
  template<typename A>
251
251
  void cpc_compressor<A>::compress_pinned_flavor(const cpc_sketch_alloc<A>& source, compressed_state<A>& result) const {
252
252
  compress_sliding_window(source.sliding_window.data(), source.get_lg_k(), source.get_num_coupons(), result);
253
- vector_u32<A> pairs = source.surprising_value_table.unwrapping_get_items();
253
+ vector_u32 pairs = source.surprising_value_table.unwrapping_get_items();
254
254
  if (pairs.size() > 0) {
255
255
  // Here we subtract 8 from the column indices. Because they are stored in the low 6 bits
256
256
  // of each row_col pair, and because no column index is less than 8 for a "Pinned" sketch,
@@ -277,7 +277,7 @@ void cpc_compressor<A>::uncompress_pinned_flavor(const compressed_state<A>& sour
277
277
  target.table = u32_table<A>(2, 6 + lg_k, source.table_data.get_allocator());
278
278
  } else {
279
279
  if (source.table_data.size() == 0) throw std::logic_error("table is expected");
280
- vector_u32<A> pairs = uncompress_surprising_values(source.table_data.data(), source.table_data_words, num_pairs,
280
+ vector_u32 pairs = uncompress_surprising_values(source.table_data.data(), source.table_data_words, num_pairs,
281
281
  lg_k, source.table_data.get_allocator());
282
282
  // undo the compressor's 8-column shift
283
283
  for (uint32_t i = 0; i < num_pairs; i++) {
@@ -291,7 +291,7 @@ void cpc_compressor<A>::uncompress_pinned_flavor(const compressed_state<A>& sour
291
291
  template<typename A>
292
292
  void cpc_compressor<A>::compress_sliding_flavor(const cpc_sketch_alloc<A>& source, compressed_state<A>& result) const {
293
293
  compress_sliding_window(source.sliding_window.data(), source.get_lg_k(), source.get_num_coupons(), result);
294
- vector_u32<A> pairs = source.surprising_value_table.unwrapping_get_items();
294
+ vector_u32 pairs = source.surprising_value_table.unwrapping_get_items();
295
295
  if (pairs.size() > 0) {
296
296
  // Here we apply a complicated transformation to the column indices, which
297
297
  // changes the implied ordering of the pairs, so we must do it before sorting.
@@ -330,7 +330,7 @@ void cpc_compressor<A>::uncompress_sliding_flavor(const compressed_state<A>& sou
330
330
  target.table = u32_table<A>(2, 6 + lg_k, source.table_data.get_allocator());
331
331
  } else {
332
332
  if (source.table_data.size() == 0) throw std::logic_error("table is expected");
333
- vector_u32<A> pairs = uncompress_surprising_values(source.table_data.data(), source.table_data_words, num_pairs,
333
+ vector_u32 pairs = uncompress_surprising_values(source.table_data.data(), source.table_data_words, num_pairs,
334
334
  lg_k, source.table_data.get_allocator());
335
335
 
336
336
  const uint8_t pseudo_phase = determine_pseudo_phase(lg_k, num_coupons);
@@ -356,7 +356,7 @@ void cpc_compressor<A>::uncompress_sliding_flavor(const compressed_state<A>& sou
356
356
  }
357
357
 
358
358
  template<typename A>
359
- void cpc_compressor<A>::compress_surprising_values(const vector_u32<A>& pairs, uint8_t lg_k, compressed_state<A>& result) const {
359
+ void cpc_compressor<A>::compress_surprising_values(const vector_u32& pairs, uint8_t lg_k, compressed_state<A>& result) const {
360
360
  const uint32_t k = 1 << lg_k;
361
361
  const uint32_t num_pairs = static_cast<uint32_t>(pairs.size());
362
362
  const uint8_t num_base_bits = golomb_choose_number_of_base_bits(k + num_pairs, num_pairs);
@@ -374,10 +374,10 @@ void cpc_compressor<A>::compress_surprising_values(const vector_u32<A>& pairs, u
374
374
  }
375
375
 
376
376
  template<typename A>
377
- vector_u32<A> cpc_compressor<A>::uncompress_surprising_values(const uint32_t* data, uint32_t data_words, uint32_t num_pairs,
378
- uint8_t lg_k, const A& allocator) const {
377
+ auto cpc_compressor<A>::uncompress_surprising_values(const uint32_t* data, uint32_t data_words, uint32_t num_pairs,
378
+ uint8_t lg_k, const A& allocator) const -> vector_u32 {
379
379
  const uint32_t k = 1 << lg_k;
380
- vector_u32<A> pairs(num_pairs, 0, allocator);
380
+ vector_u32 pairs(num_pairs, 0, allocator);
381
381
  const uint8_t num_base_bits = golomb_choose_number_of_base_bits(k + num_pairs, num_pairs);
382
382
  low_level_uncompress_pairs(pairs.data(), num_pairs, num_base_bits, data, data_words);
383
383
  return pairs;
@@ -399,7 +399,7 @@ void cpc_compressor<A>::compress_sliding_window(const uint8_t* window, uint8_t l
399
399
  }
400
400
 
401
401
  template<typename A>
402
- void cpc_compressor<A>::uncompress_sliding_window(const uint32_t* data, uint32_t data_words, vector_u8<A>& window,
402
+ void cpc_compressor<A>::uncompress_sliding_window(const uint32_t* data, uint32_t data_words, vector_bytes& window,
403
403
  uint8_t lg_k, uint32_t num_coupons) const {
404
404
  const uint32_t k = 1 << lg_k;
405
405
  window.resize(k); // zeroing not needed here (unlike the Hybrid Flavor)
@@ -722,10 +722,10 @@ void write_unary(
722
722
  // The empty space that this leaves at the beginning of the output array
723
723
  // will be filled in later by the caller.
724
724
  template<typename A>
725
- vector_u32<A> cpc_compressor<A>::tricky_get_pairs_from_window(const uint8_t* window, uint32_t k, uint32_t num_pairs_to_get,
726
- uint32_t empty_space, const A& allocator) {
725
+ auto cpc_compressor<A>::tricky_get_pairs_from_window(const uint8_t* window, uint32_t k, uint32_t num_pairs_to_get,
726
+ uint32_t empty_space, const A& allocator) -> vector_u32 {
727
727
  const size_t output_length = empty_space + num_pairs_to_get;
728
- vector_u32<A> pairs(output_length, 0, allocator);
728
+ vector_u32 pairs(output_length, 0, allocator);
729
729
  size_t pair_index = empty_space;
730
730
  for (unsigned row_index = 0; row_index < k; row_index++) {
731
731
  uint8_t byte = window[row_index];
@@ -30,7 +30,7 @@
30
30
  namespace datasketches {
31
31
 
32
32
  // ln 2.0
33
- static const double ICON_ERROT_CONSTANT = 0.693147180559945286;
33
+ static const double ICON_ERROR_CONSTANT = 0.693147180559945286;
34
34
 
35
35
  // 1, 2, 3, // kappa
36
36
  static const int16_t ICON_LOW_SIDE_DATA [33] = { // Empirically measured at N = 1000 * K.
@@ -102,7 +102,7 @@ double get_icon_confidence_lb(const cpc_sketch_alloc<A>& sketch, int kappa) {
102
102
  const long k = 1 << lg_k;
103
103
  if (lg_k < 4) throw std::logic_error("lgk < 4");
104
104
  if (kappa < 1 || kappa > 3) throw std::invalid_argument("kappa must be between 1 and 3");
105
- double x = ICON_ERROT_CONSTANT;
105
+ double x = ICON_ERROR_CONSTANT;
106
106
  if (lg_k <= 14) x = ((double) ICON_HIGH_SIDE_DATA[3 * (lg_k - 4) + (kappa - 1)]) / 10000.0;
107
107
  const double rel = x / sqrt(k);
108
108
  const double eps = kappa * rel;
@@ -120,7 +120,7 @@ double get_icon_confidence_ub(const cpc_sketch_alloc<A>& sketch, int kappa) {
120
120
  const long k = 1 << lg_k;
121
121
  if (lg_k < 4) throw std::logic_error("lgk < 4");
122
122
  if (kappa < 1 || kappa > 3) throw std::invalid_argument("kappa must be between 1 and 3");
123
- double x = ICON_ERROT_CONSTANT;
123
+ double x = ICON_ERROR_CONSTANT;
124
124
  if (lg_k <= 14) x = ((double) ICON_LOW_SIDE_DATA[3 * (lg_k - 4) + (kappa - 1)]) / 10000.0;
125
125
  const double rel = x / sqrt(k);
126
126
  const double eps = kappa * rel;