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
@@ -29,6 +29,7 @@
29
29
  namespace datasketches {
30
30
 
31
31
  /**
32
+ * Bounds on ratios in sampled sets.
32
33
  * This class is used to compute the bounds on the estimate of the ratio <i>|B| / |A|</i>, where:
33
34
  * <ul>
34
35
  * <li><i>|A|</i> is the unknown size of a set <i>A</i> of unique identifiers.</li>
@@ -28,6 +28,7 @@
28
28
  namespace datasketches {
29
29
 
30
30
  /**
31
+ * Bounds on ratios in Theta sketched sets.
31
32
  * This is to compute the bounds on the estimate of the ratio <i>B / A</i>, where:
32
33
  * <ul>
33
34
  * <li><i>A</i> is a Theta Sketch of population <i>PopA</i>.</li>
@@ -50,8 +51,8 @@ class bounds_on_ratios_in_theta_sketched_sets {
50
51
  public:
51
52
  /**
52
53
  * Gets the approximate lower bound for B over A based on a 95% confidence interval
53
- * @param sketchA the sketch A
54
- * @param sketchB the sketch B
54
+ * @param sketch_a the sketch A
55
+ * @param sketch_b the sketch B
55
56
  * @return the approximate lower bound for B over A
56
57
  */
57
58
  template<typename SketchA, typename SketchB>
@@ -72,8 +73,8 @@ public:
72
73
 
73
74
  /**
74
75
  * Gets the approximate upper bound for B over A based on a 95% confidence interval
75
- * @param sketchA the sketch A
76
- * @param sketchB the sketch B
76
+ * @param sketch_a the sketch A
77
+ * @param sketch_b the sketch B
77
78
  * @return the approximate upper bound for B over A
78
79
  */
79
80
  template<typename SketchA, typename SketchB>
@@ -94,8 +95,8 @@ public:
94
95
 
95
96
  /**
96
97
  * Gets the estimate for B over A
97
- * @param sketchA the sketch A
98
- * @param sketchB the sketch B
98
+ * @param sketch_a the sketch A
99
+ * @param sketch_b the sketch B
99
100
  * @return the estimate for B over A
100
101
  */
101
102
  template<typename SketchA, typename SketchB>
@@ -20,7 +20,7 @@
20
20
  #ifndef COMPACT_THETA_SKETCH_PARSER_HPP_
21
21
  #define COMPACT_THETA_SKETCH_PARSER_HPP_
22
22
 
23
- #include <stdint.h>
23
+ #include <cstdint>
24
24
 
25
25
  namespace datasketches {
26
26
 
@@ -33,7 +33,8 @@ public:
33
33
  uint16_t seed_hash;
34
34
  uint32_t num_entries;
35
35
  uint64_t theta;
36
- const uint64_t* entries;
36
+ const void* entries_start_ptr;
37
+ uint8_t entry_bits;
37
38
  };
38
39
 
39
40
  static compact_theta_sketch_data parse(const void* ptr, size_t size, uint64_t seed, bool dump_on_error = false);
@@ -45,18 +46,23 @@ private:
45
46
  static const size_t COMPACT_SKETCH_TYPE_BYTE = 2;
46
47
  static const size_t COMPACT_SKETCH_FLAGS_BYTE = 5;
47
48
  static const size_t COMPACT_SKETCH_SEED_HASH_U16 = 3;
48
- static const size_t COMPACT_SKETCH_NUM_ENTRIES_U32 = 2;
49
- static const size_t COMPACT_SKETCH_SINGLE_ENTRY_U64 = 1;
50
- static const size_t COMPACT_SKETCH_ENTRIES_EXACT_U64 = 2;
51
- static const size_t COMPACT_SKETCH_THETA_U64 = 2;
52
- static const size_t COMPACT_SKETCH_ENTRIES_ESTIMATION_U64 = 3;
49
+ static const size_t COMPACT_SKETCH_SINGLE_ENTRY_U64 = 1; // ver 3
50
+ static const size_t COMPACT_SKETCH_NUM_ENTRIES_U32 = 2; // ver 1-3
51
+ static const size_t COMPACT_SKETCH_ENTRIES_EXACT_U64 = 2; // ver 1-3
52
+ static const size_t COMPACT_SKETCH_ENTRIES_ESTIMATION_U64 = 3; // ver 1-3
53
+ static const size_t COMPACT_SKETCH_THETA_U64 = 2; // ver 1-3
54
+ static const size_t COMPACT_SKETCH_V4_ENTRY_BITS_BYTE = 3;
55
+ static const size_t COMPACT_SKETCH_V4_NUM_ENTRIES_BYTES_BYTE = 4;
56
+ static const size_t COMPACT_SKETCH_V4_THETA_U64 = 1;
57
+ static const size_t COMPACT_SKETCH_V4_PACKED_DATA_EXACT_BYTE = 8;
58
+ static const size_t COMPACT_SKETCH_V4_PACKED_DATA_ESTIMATION_BYTE = 16;
53
59
 
54
60
  static const uint8_t COMPACT_SKETCH_IS_EMPTY_FLAG = 2;
55
61
  static const uint8_t COMPACT_SKETCH_IS_ORDERED_FLAG = 4;
56
62
 
57
- static const uint8_t COMPACT_SKETCH_SERIAL_VERSION = 3;
58
63
  static const uint8_t COMPACT_SKETCH_TYPE = 3;
59
64
 
65
+ static void check_memory_size(const void* ptr, size_t actual_bytes, size_t expected_bytes, bool dump_on_error);
60
66
  static std::string hex_dump(const uint8_t* ptr, size_t size);
61
67
  };
62
68
 
@@ -26,106 +26,120 @@
26
26
 
27
27
  namespace datasketches {
28
28
 
29
+ template<typename T>
30
+ T whole_bytes_to_hold_bits(T bits) {
31
+ static_assert(std::is_integral<T>::value, "integral type expected");
32
+ return (bits >> 3) + ((bits & 7) > 0);
33
+ }
34
+
29
35
  template<bool dummy>
30
36
  auto compact_theta_sketch_parser<dummy>::parse(const void* ptr, size_t size, uint64_t seed, bool dump_on_error) -> compact_theta_sketch_data {
31
- if (size < 8) throw std::out_of_range("at least 8 bytes expected, actual " + std::to_string(size)
32
- + (dump_on_error ? (", sketch dump: " + hex_dump(reinterpret_cast<const uint8_t*>(ptr), size)) : ""));
33
-
37
+ check_memory_size(ptr, size, 8, dump_on_error);
38
+ checker<true>::check_sketch_type(reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_TYPE_BYTE], COMPACT_SKETCH_TYPE);
34
39
  uint8_t serial_version = reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_SERIAL_VERSION_BYTE];
35
-
36
40
  switch(serial_version) {
37
- case COMPACT_SKETCH_SERIAL_VERSION: {
38
- checker<true>::check_sketch_type(reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_TYPE_BYTE], COMPACT_SKETCH_TYPE);
41
+ case 4: {
42
+ // version 4 sketches are ordered and always have entries (single item in exact mode is v3)
43
+ const uint16_t seed_hash = reinterpret_cast<const uint16_t*>(ptr)[COMPACT_SKETCH_SEED_HASH_U16];
44
+ checker<true>::check_seed_hash(seed_hash, compute_seed_hash(seed));
45
+ const bool has_theta = reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_PRE_LONGS_BYTE] > 1;
46
+ uint64_t theta = theta_constants::MAX_THETA;
47
+ if (has_theta) {
48
+ check_memory_size(ptr, size, 16, dump_on_error);
49
+ theta = reinterpret_cast<const uint64_t*>(ptr)[COMPACT_SKETCH_V4_THETA_U64];
50
+ }
51
+ const uint8_t num_entries_bytes = reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_V4_NUM_ENTRIES_BYTES_BYTE];
52
+ size_t data_offset_bytes = has_theta ? COMPACT_SKETCH_V4_PACKED_DATA_ESTIMATION_BYTE : COMPACT_SKETCH_V4_PACKED_DATA_EXACT_BYTE;
53
+ check_memory_size(ptr, size, data_offset_bytes + num_entries_bytes, dump_on_error);
54
+ uint32_t num_entries = 0;
55
+ const uint8_t* num_entries_ptr = reinterpret_cast<const uint8_t*>(ptr) + data_offset_bytes;
56
+ for (unsigned i = 0; i < num_entries_bytes; ++i) {
57
+ num_entries |= (*num_entries_ptr++) << (i << 3);
58
+ }
59
+ data_offset_bytes += num_entries_bytes;
60
+ const uint8_t entry_bits = reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_V4_ENTRY_BITS_BYTE];
61
+ const size_t expected_bits = entry_bits * num_entries;
62
+ const size_t expected_size_bytes = data_offset_bytes + whole_bytes_to_hold_bits(expected_bits);
63
+ check_memory_size(ptr, size, expected_size_bytes, dump_on_error);
64
+ return {false, true, seed_hash, num_entries, theta,
65
+ reinterpret_cast<const uint8_t*>(ptr) + data_offset_bytes, entry_bits};
66
+ }
67
+ case 3: {
39
68
  uint64_t theta = theta_constants::MAX_THETA;
40
69
  const uint16_t seed_hash = reinterpret_cast<const uint16_t*>(ptr)[COMPACT_SKETCH_SEED_HASH_U16];
41
70
  if (reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_FLAGS_BYTE] & (1 << COMPACT_SKETCH_IS_EMPTY_FLAG)) {
42
- return {true, true, seed_hash, 0, theta, nullptr};
71
+ return {true, true, seed_hash, 0, theta, nullptr, 64};
43
72
  }
44
73
  checker<true>::check_seed_hash(seed_hash, compute_seed_hash(seed));
45
74
  const bool has_theta = reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_PRE_LONGS_BYTE] > 2;
46
75
  if (has_theta) {
47
- if (size < 16) throw std::out_of_range("at least 16 bytes expected, actual " + std::to_string(size));
76
+ check_memory_size(ptr, size, (COMPACT_SKETCH_THETA_U64 + 1) * sizeof(uint64_t), dump_on_error);
48
77
  theta = reinterpret_cast<const uint64_t*>(ptr)[COMPACT_SKETCH_THETA_U64];
49
78
  }
50
79
  if (reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_PRE_LONGS_BYTE] == 1) {
51
- if (size < 16) throw std::out_of_range("at least 16 bytes expected, actual " + std::to_string(size));
52
- return {false, true, seed_hash, 1, theta, reinterpret_cast<const uint64_t*>(ptr) + COMPACT_SKETCH_SINGLE_ENTRY_U64};
80
+ check_memory_size(ptr, size, 16, dump_on_error);
81
+ return {false, true, seed_hash, 1, theta, reinterpret_cast<const uint64_t*>(ptr) + COMPACT_SKETCH_SINGLE_ENTRY_U64, 64};
53
82
  }
54
83
  const uint32_t num_entries = reinterpret_cast<const uint32_t*>(ptr)[COMPACT_SKETCH_NUM_ENTRIES_U32];
55
84
  const size_t entries_start_u64 = has_theta ? COMPACT_SKETCH_ENTRIES_ESTIMATION_U64 : COMPACT_SKETCH_ENTRIES_EXACT_U64;
56
85
  const uint64_t* entries = reinterpret_cast<const uint64_t*>(ptr) + entries_start_u64;
57
86
  const size_t expected_size_bytes = (entries_start_u64 + num_entries) * sizeof(uint64_t);
58
- if (size < expected_size_bytes) {
59
- throw std::out_of_range(std::to_string(expected_size_bytes) + " bytes expected, actual " + std::to_string(size)
60
- + (dump_on_error ? (", sketch dump: " + hex_dump(reinterpret_cast<const uint8_t*>(ptr), size)) : ""));
61
- }
87
+ check_memory_size(ptr, size, expected_size_bytes, dump_on_error);
62
88
  const bool is_ordered = reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_FLAGS_BYTE] & (1 << COMPACT_SKETCH_IS_ORDERED_FLAG);
63
- return {false, is_ordered, seed_hash, num_entries, theta, entries};
89
+ return {false, is_ordered, seed_hash, num_entries, theta, entries, 64};
64
90
  }
65
91
  case 1: {
66
92
  uint16_t seed_hash = compute_seed_hash(seed);
67
- checker<true>::check_sketch_type(reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_TYPE_BYTE], COMPACT_SKETCH_TYPE);
68
93
  const uint32_t num_entries = reinterpret_cast<const uint32_t*>(ptr)[COMPACT_SKETCH_NUM_ENTRIES_U32];
69
94
  uint64_t theta = reinterpret_cast<const uint64_t*>(ptr)[COMPACT_SKETCH_THETA_U64];
70
95
  bool is_empty = (num_entries == 0) && (theta == theta_constants::MAX_THETA);
71
- if (is_empty) {
72
- return {true, true, seed_hash, 0, theta, nullptr};
73
- }
96
+ if (is_empty) return {true, true, seed_hash, 0, theta, nullptr, 64};
74
97
  const uint64_t* entries = reinterpret_cast<const uint64_t*>(ptr) + COMPACT_SKETCH_ENTRIES_ESTIMATION_U64;
75
98
  const size_t expected_size_bytes = (COMPACT_SKETCH_ENTRIES_ESTIMATION_U64 + num_entries) * sizeof(uint64_t);
76
- if (size < expected_size_bytes) {
77
- throw std::out_of_range(std::to_string(expected_size_bytes) + " bytes expected, actual " + std::to_string(size)
78
- + (dump_on_error ? (", sketch dump: " + hex_dump(reinterpret_cast<const uint8_t*>(ptr), size)) : ""));
79
- }
80
- return {false, true, seed_hash, num_entries, theta, entries};
99
+ check_memory_size(ptr, size, expected_size_bytes, dump_on_error);
100
+ return {false, true, seed_hash, num_entries, theta, entries, 64};
81
101
  }
82
102
  case 2: {
83
- uint8_t preamble_size = reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_PRE_LONGS_BYTE];
84
- checker<true>::check_sketch_type(reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_TYPE_BYTE], COMPACT_SKETCH_TYPE);
103
+ uint8_t preamble_size = reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_PRE_LONGS_BYTE];
85
104
  const uint16_t seed_hash = reinterpret_cast<const uint16_t*>(ptr)[COMPACT_SKETCH_SEED_HASH_U16];
86
105
  checker<true>::check_seed_hash(seed_hash, compute_seed_hash(seed));
87
106
  if (preamble_size == 1) {
88
- return {true, true, seed_hash, 0, theta_constants::MAX_THETA, nullptr};
107
+ return {true, true, seed_hash, 0, theta_constants::MAX_THETA, nullptr, 64};
89
108
  } else if (preamble_size == 2) {
90
109
  const uint32_t num_entries = reinterpret_cast<const uint32_t*>(ptr)[COMPACT_SKETCH_NUM_ENTRIES_U32];
91
110
  if (num_entries == 0) {
92
- return {true, true, seed_hash, 0, theta_constants::MAX_THETA, nullptr};
111
+ return {true, true, seed_hash, 0, theta_constants::MAX_THETA, nullptr, 64};
93
112
  } else {
94
113
  const size_t expected_size_bytes = (preamble_size + num_entries) << 3;
95
- if (size < expected_size_bytes) {
96
- throw std::out_of_range(std::to_string(expected_size_bytes) + " bytes expected, actual " + std::to_string(size)
97
- + (dump_on_error ? (", sketch dump: " + hex_dump(reinterpret_cast<const uint8_t*>(ptr), size)) : ""));
98
- }
114
+ check_memory_size(ptr, size, expected_size_bytes, dump_on_error);
99
115
  const uint64_t* entries = reinterpret_cast<const uint64_t*>(ptr) + COMPACT_SKETCH_ENTRIES_EXACT_U64;
100
- return {false, true, seed_hash, num_entries, theta_constants::MAX_THETA, entries};
116
+ return {false, true, seed_hash, num_entries, theta_constants::MAX_THETA, entries, 64};
101
117
  }
102
118
  } else if (preamble_size == 3) {
103
119
  const uint32_t num_entries = reinterpret_cast<const uint32_t*>(ptr)[COMPACT_SKETCH_NUM_ENTRIES_U32];
104
120
  uint64_t theta = reinterpret_cast<const uint64_t*>(ptr)[COMPACT_SKETCH_THETA_U64];
105
121
  bool is_empty = (num_entries == 0) && (theta == theta_constants::MAX_THETA);
106
- if (is_empty) {
107
- return {true, true, seed_hash, 0, theta, nullptr};
108
- }
122
+ if (is_empty) return {true, true, seed_hash, 0, theta, nullptr, 64};
109
123
  const uint64_t* entries = reinterpret_cast<const uint64_t*>(ptr) + COMPACT_SKETCH_ENTRIES_ESTIMATION_U64;
110
124
  const size_t expected_size_bytes = (COMPACT_SKETCH_ENTRIES_ESTIMATION_U64 + num_entries) * sizeof(uint64_t);
111
- if (size < expected_size_bytes) {
112
- throw std::out_of_range(std::to_string(expected_size_bytes) + " bytes expected, actual " + std::to_string(size)
113
- + (dump_on_error ? (", sketch dump: " + hex_dump(reinterpret_cast<const uint8_t*>(ptr), size)) : ""));
114
- }
115
- return {false, true, seed_hash, num_entries, theta, entries};
125
+ check_memory_size(ptr, size, expected_size_bytes, dump_on_error);
126
+ return {false, true, seed_hash, num_entries, theta, entries, 64};
116
127
  } else {
117
128
  throw std::invalid_argument(std::to_string(preamble_size) + " longs of premable, but expected 1, 2, or 3");
118
129
  }
119
130
  }
120
131
  default:
121
- // this should always fail since the valid cases are handled above
122
- checker<true>::check_serial_version(reinterpret_cast<const uint8_t*>(ptr)[COMPACT_SKETCH_SERIAL_VERSION_BYTE], COMPACT_SKETCH_SERIAL_VERSION);
123
- // this throw is never reached, because check_serial_version will throw an informative exception.
124
- // This is only here to avoid a compiler warning about a path without a return value.
125
- throw std::invalid_argument("unexpected sketch serialization version");
132
+ throw std::invalid_argument("unsupported serial version " + std::to_string(serial_version));
126
133
  }
127
134
  }
128
135
 
136
+ template<bool dummy>
137
+ void compact_theta_sketch_parser<dummy>::check_memory_size(const void* ptr, size_t actual_bytes, size_t expected_bytes, bool dump_on_error) {
138
+ if (actual_bytes < expected_bytes) throw std::out_of_range("at least " + std::to_string(expected_bytes)
139
+ + " bytes expected, actual " + std::to_string(actual_bytes)
140
+ + (dump_on_error ? (", sketch dump: " + hex_dump(reinterpret_cast<const uint8_t*>(ptr), actual_bytes)) : ""));
141
+ }
142
+
129
143
  template<bool dummy>
130
144
  std::string compact_theta_sketch_parser<dummy>::hex_dump(const uint8_t* ptr, size_t size) {
131
145
  std::stringstream s;
@@ -25,6 +25,16 @@
25
25
 
26
26
  namespace datasketches {
27
27
 
28
+ // forward declaration
29
+ template<typename A> class theta_a_not_b_alloc;
30
+
31
+ // alias with default allocator for convenience
32
+ using theta_a_not_b = theta_a_not_b_alloc<std::allocator<uint64_t>>;
33
+
34
+ /**
35
+ * Theta A-not-B (set difference).
36
+ * Computes set difference of Theta sketches.
37
+ */
28
38
  template<typename Allocator = std::allocator<uint64_t>>
29
39
  class theta_a_not_b_alloc {
30
40
  public:
@@ -33,11 +43,19 @@ public:
33
43
  using CompactSketch = compact_theta_sketch_alloc<Allocator>;
34
44
  using State = theta_set_difference_base<Entry, ExtractKey, CompactSketch, Allocator>;
35
45
 
46
+ /**
47
+ * Constructor
48
+ * @param seed for the hash function that was used to create the sketch
49
+ * @param allocator to use for allocating and deallocating memory
50
+ */
36
51
  explicit theta_a_not_b_alloc(uint64_t seed = DEFAULT_SEED, const Allocator& allocator = Allocator());
37
52
 
38
53
  /**
39
- * Computes the a-not-b set operation given two sketches.
40
- * @return the result of a-not-b
54
+ * Computes the A-not-B set operation given two sketches.
55
+ * @param a sketch A
56
+ * @param b sketch B
57
+ * @param ordered optional flag to specify if an ordered sketch should be produced
58
+ * @return the result of A-not-B as a compact sketch
41
59
  */
42
60
  template<typename FwdSketch, typename Sketch>
43
61
  CompactSketch compute(FwdSketch&& a, const Sketch& b, bool ordered = true) const;
@@ -46,9 +64,6 @@ private:
46
64
  State state_;
47
65
  };
48
66
 
49
- // alias with default allocator for convenience
50
- using theta_a_not_b = theta_a_not_b_alloc<std::allocator<uint64_t>>;
51
-
52
67
  } /* namespace datasketches */
53
68
 
54
69
  #include "theta_a_not_b_impl.hpp"
@@ -25,15 +25,21 @@
25
25
 
26
26
  namespace datasketches {
27
27
 
28
+ /// Theta constants
28
29
  namespace theta_constants {
30
+ /// hash table resize factor
29
31
  using resize_factor = datasketches::resize_factor;
30
- //enum resize_factor { X1, X2, X4, X8 };
31
- const uint64_t MAX_THETA = LLONG_MAX; // signed max for compatibility with Java
32
+ /// default resize factor
33
+ const resize_factor DEFAULT_RESIZE_FACTOR = resize_factor::X8;
34
+
35
+ /// max theta - signed max for compatibility with Java
36
+ const uint64_t MAX_THETA = LLONG_MAX;
37
+ /// min log2 of K
32
38
  const uint8_t MIN_LG_K = 5;
39
+ /// max log2 of K
33
40
  const uint8_t MAX_LG_K = 26;
34
-
41
+ /// default log2 of K
35
42
  const uint8_t DEFAULT_LG_K = 12;
36
- const resize_factor DEFAULT_RESIZE_FACTOR = resize_factor::X8;
37
43
  }
38
44
 
39
45
  } /* namespace datasketches */
@@ -20,8 +20,10 @@
20
20
  #ifndef THETA_HELPERS_HPP_
21
21
  #define THETA_HELPERS_HPP_
22
22
 
23
- #include <string>
24
23
  #include <stdexcept>
24
+ #include <string>
25
+
26
+ #include "theta_constants.hpp"
25
27
 
26
28
  namespace datasketches {
27
29
 
@@ -25,6 +25,16 @@
25
25
 
26
26
  namespace datasketches {
27
27
 
28
+ // forward declaration
29
+ template<typename A> class theta_intersection_alloc;
30
+
31
+ // alias with default allocator for convenience
32
+ using theta_intersection = theta_intersection_alloc<std::allocator<uint64_t>>;
33
+
34
+ /**
35
+ * Theta intersection.
36
+ * Computes intersection of Theta sketches.
37
+ */
28
38
  template<typename Allocator = std::allocator<uint64_t>>
29
39
  class theta_intersection_alloc {
30
40
  public:
@@ -33,6 +43,7 @@ public:
33
43
  using Sketch = theta_sketch_alloc<Allocator>;
34
44
  using CompactSketch = compact_theta_sketch_alloc<Allocator>;
35
45
 
46
+ // there is no payload in Theta sketch entry
36
47
  struct nop_policy {
37
48
  void operator()(uint64_t internal_entry, uint64_t incoming_entry) const {
38
49
  unused(incoming_entry);
@@ -41,7 +52,7 @@ public:
41
52
  };
42
53
  using State = theta_intersection_base<Entry, ExtractKey, nop_policy, Sketch, CompactSketch, Allocator>;
43
54
 
44
- /*
55
+ /**
45
56
  * Constructor
46
57
  * @param seed for the hash function that was used to create the sketch
47
58
  * @param allocator to use for allocating and deallocating memory
@@ -61,7 +72,7 @@ public:
61
72
  * Produces a copy of the current state of the intersection.
62
73
  * If update() was not called, the state is the infinite "universe",
63
74
  * which is considered an undefined state, and throws an exception.
64
- * @param ordered optional flag to specify if ordered sketch should be produced
75
+ * @param ordered optional flag to specify if an ordered sketch should be produced
65
76
  * @return the result of the intersection
66
77
  */
67
78
  CompactSketch get_result(bool ordered = true) const;
@@ -76,9 +87,6 @@ private:
76
87
  State state_;
77
88
  };
78
89
 
79
- // alias with default allocator for convenience
80
- using theta_intersection = theta_intersection_alloc<std::allocator<uint64_t>>;
81
-
82
90
  } /* namespace datasketches */
83
91
 
84
92
  #include "theta_intersection_impl.hpp"
@@ -49,8 +49,8 @@ void theta_intersection_base<EN, EK, P, S, CS, A>::update(SS&& sketch) {
49
49
  if (!is_valid_) { // first update, copy or move incoming sketch
50
50
  is_valid_ = true;
51
51
  const uint8_t lg_size = lg_size_from_count(sketch.get_num_retained(), theta_update_sketch_base<EN, EK, A>::REBUILD_THRESHOLD);
52
- table_ = hash_table(lg_size, lg_size, resize_factor::X1, 1, table_.theta_, table_.seed_, table_.allocator_, table_.is_empty_);
53
- for (auto& entry: sketch) {
52
+ table_ = hash_table(lg_size, lg_size - 1, resize_factor::X1, 1, table_.theta_, table_.seed_, table_.allocator_, table_.is_empty_);
53
+ for (auto&& entry: sketch) {
54
54
  auto result = table_.find(EK()(entry));
55
55
  if (result.second) {
56
56
  throw std::invalid_argument("duplicate key, possibly corrupted input sketch");
@@ -64,7 +64,7 @@ void theta_intersection_base<EN, EK, P, S, CS, A>::update(SS&& sketch) {
64
64
  matched_entries.reserve(max_matches);
65
65
  uint32_t match_count = 0;
66
66
  uint32_t count = 0;
67
- for (auto& entry: sketch) {
67
+ for (auto&& entry: sketch) {
68
68
  if (EK()(entry) < table_.theta_) {
69
69
  auto result = table_.find(EK()(entry));
70
70
  if (result.second) {
@@ -88,8 +88,8 @@ void theta_intersection_base<EN, EK, P, S, CS, A>::update(SS&& sketch) {
88
88
  if (table_.theta_ == theta_constants::MAX_THETA) table_.is_empty_ = true;
89
89
  } else {
90
90
  const uint8_t lg_size = lg_size_from_count(match_count, theta_update_sketch_base<EN, EK, A>::REBUILD_THRESHOLD);
91
- table_ = hash_table(lg_size, lg_size, resize_factor::X1, 1, table_.theta_, table_.seed_, table_.allocator_, table_.is_empty_);
92
- for (uint32_t i = 0; i < match_count; i++) {
91
+ table_ = hash_table(lg_size, lg_size - 1, resize_factor::X1, 1, table_.theta_, table_.seed_, table_.allocator_, table_.is_empty_);
92
+ for (uint32_t i = 0; i < match_count; ++i) {
93
93
  auto result = table_.find(EK()(matched_entries[i]));
94
94
  table_.insert(result.first, std::move(matched_entries[i]));
95
95
  }
@@ -28,9 +28,9 @@ state_(seed, nop_policy(), allocator)
28
28
  {}
29
29
 
30
30
  template<typename A>
31
- template<typename SS>
32
- void theta_intersection_alloc<A>::update(SS&& sketch) {
33
- state_.update(std::forward<SS>(sketch));
31
+ template<typename FwdSketch>
32
+ void theta_intersection_alloc<A>::update(FwdSketch&& sketch) {
33
+ state_.update(std::forward<FwdSketch>(sketch));
34
34
  }
35
35
 
36
36
  template<typename A>
@@ -26,10 +26,11 @@
26
26
 
27
27
  namespace datasketches {
28
28
 
29
+ /// Theta Jaccard similarity alias
29
30
  template<typename Allocator = std::allocator<uint64_t>>
30
31
  using theta_jaccard_similarity_alloc = jaccard_similarity_base<theta_union_alloc<Allocator>, theta_intersection_alloc<Allocator>, trivial_extract_key>;
31
32
 
32
- // alias with default allocator for convenience
33
+ /// Theta Jaccard similarity alias with default allocator
33
34
  using theta_jaccard_similarity = theta_jaccard_similarity_alloc<std::allocator<uint64_t>>;
34
35
 
35
36
  } /* namespace datasketches */
@@ -30,6 +30,7 @@
30
30
 
31
31
  namespace datasketches {
32
32
 
33
+ /// Base class for Jaccard similarity
33
34
  template<typename Union, typename Intersection, typename ExtractKey>
34
35
  class jaccard_similarity_base {
35
36
  public:
@@ -65,7 +65,7 @@ CS theta_set_difference_base<EN, EK, CS, A>::compute(FwdSketch&& a, const Sketch
65
65
  }
66
66
 
67
67
  // scan A lookup B
68
- for (auto& entry: a) {
68
+ for (auto&& entry: a) {
69
69
  const uint64_t hash = EK()(entry);
70
70
  if (hash < theta) {
71
71
  auto result = table.find(hash);