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
@@ -205,7 +205,6 @@ APPENDIX A: How to apply the Apache License to your work.
205
205
  -------------------------------------------------------------
206
206
 
207
207
 
208
-
209
208
  APPENDIX B: Additional licenses relevant to this product.
210
209
 
211
210
  This product includes a number of source files with code that has been
@@ -215,43 +214,6 @@ APPENDIX B: Additional licenses relevant to this product.
215
214
  conditions of the following licenses.
216
215
 
217
216
 
218
-
219
- =============================================================
220
- MIT License
221
- =============================================================
222
- Original source code:
223
- https://github.com/benjaminjack/python_cpp_example
224
- -------------------------------------------------------------
225
- Copyright (c) 2017 Benjamin R. Jack
226
-
227
- MIT License (https://opensource.org/licenses/MIT):
228
-
229
- Permission is hereby granted, free of charge, to any person
230
- obtaining a copy of this software and associated documentation
231
- files (the "Software"), to deal in the Software without restriction,
232
- including without limitation the rights to use, copy, modify, merge,
233
- publish, distribute, sublicense, and/or sell copies of the Software,
234
- and to permit persons to whom the Software is furnished to do so,
235
- subject to the following conditions:
236
-
237
- The above copyright notice and this permission notice shall be
238
- included in all copies or substantial portions of the Software.
239
-
240
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
241
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
242
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
243
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
244
- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
245
- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
246
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
247
- SOFTWARE.
248
- -------------------------------------------------------------
249
- Code locations:
250
- * https://github.com/apache/datasketches-cpp/blob/master/setup.py
251
- that is adapted from the above.
252
-
253
-
254
-
255
217
  =============================================================
256
218
  Boost License (https://www.boost.org/LICENSE_1_0.txt)
257
219
  =============================================================
@@ -287,44 +249,6 @@ APPENDIX B: Additional licenses relevant to this product.
287
249
  of CMake configuration if configured to build tests.
288
250
 
289
251
 
290
- =============================================================
291
- BSD License
292
- =============================================================
293
- Original source code:
294
- https://github.com/pybind/pybind11/blob/master/LICENSE
295
-
296
- Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>, All rights reserved.
297
-
298
- Redistribution and use in source and binary forms, with or without
299
- modification, are permitted provided that the following conditions are met:
300
-
301
- 1. Redistributions of source code must retain the above copyright notice, this
302
- list of conditions and the following disclaimer.
303
-
304
- 2. Redistributions in binary form must reproduce the above copyright notice,
305
- this list of conditions and the following disclaimer in the documentation
306
- and/or other materials provided with the distribution.
307
-
308
- 3. Neither the name of the copyright holder nor the names of its contributors
309
- may be used to endorse or promote products derived from this software
310
- without specific prior written permission.
311
-
312
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
313
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
314
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
315
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
316
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
317
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
318
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
319
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
320
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
321
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
322
- -------------------------------------------------------------
323
- Code Locations:
324
- Found only in the convenience binaries distributed from PyPI, which rely
325
- on pybind11 code during compilation.
326
-
327
-
328
252
  =============================================================
329
253
  Public Domain
330
254
  =============================================================
@@ -14,9 +14,7 @@ If you are interested in making contributions to this site please see our [Commu
14
14
 
15
15
  This code requires C++11.
16
16
 
17
- This includes Python bindings. For the Python interface, see the README notes in [the python subdirectory](https://github.com/apache/datasketches-cpp/tree/master/python).
18
-
19
- This library is header-only. The build process provided is only for building unit tests and the python library.
17
+ This library is header-only. The build process provided is only for building unit tests.
20
18
 
21
19
  Building the unit tests requires cmake 3.12.0 or higher.
22
20
 
@@ -35,19 +35,20 @@ install(TARGETS common EXPORT ${PROJECT_NAME})
35
35
 
36
36
  install(FILES
37
37
  ${CMAKE_CURRENT_BINARY_DIR}/include/version.hpp
38
+ include/binomial_bounds.hpp
39
+ include/bounds_binomial_proportions.hpp
40
+ include/ceiling_power_of_2.hpp
38
41
  include/common_defs.hpp
42
+ include/conditional_back_inserter.hpp
43
+ include/conditional_forward.hpp
44
+ include/count_zeros.hpp
45
+ include/inv_pow2_table.hpp
46
+ include/kolmogorov_smirnov_impl.hpp
47
+ include/kolmogorov_smirnov.hpp
39
48
  include/memory_operations.hpp
40
49
  include/MurmurHash3.h
41
- include/serde.hpp
42
- include/count_zeros.hpp
43
- include/inv_pow2_table.hpp
44
- include/binomial_bounds.hpp
45
- include/conditional_back_inserter.hpp
46
- include/conditional_forward.hpp
47
- include/ceiling_power_of_2.hpp
48
- include/bounds_binomial_proportions.hpp
50
+ include/optional.hpp
51
+ include/quantiles_sorted_view_impl.hpp
49
52
  include/quantiles_sorted_view.hpp
50
- include/quantiles_sorted_view_impl.hpp
51
- include/kolmogorov_smirnov.hpp
52
- include/kolmogorov_smirnov_impl.hpp
53
+ include/serde.hpp
53
54
  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/DataSketches")
@@ -29,14 +29,13 @@ typedef unsigned char uint8_t;
29
29
  typedef unsigned int uint32_t;
30
30
  typedef unsigned __int64 uint64_t;
31
31
 
32
- #define FORCE_INLINE __forceinline
32
+ #define MURMUR3_FORCE_INLINE __forceinline
33
33
 
34
34
  #include <stdlib.h>
35
35
 
36
- #define ROTL32(x,y) _rotl(x,y)
37
- #define ROTL64(x,y) _rotl64(x,y)
36
+ #define MURMUR3_ROTL64(x,y) _rotl64(x,y)
38
37
 
39
- #define BIG_CONSTANT(x) (x)
38
+ #define MURMUR3_BIG_CONSTANT(x) (x)
40
39
 
41
40
  // Other compilers
42
41
 
@@ -44,22 +43,16 @@ typedef unsigned __int64 uint64_t;
44
43
 
45
44
  #include <stdint.h>
46
45
 
47
- #define FORCE_INLINE inline __attribute__((always_inline))
48
-
49
- inline uint32_t rotl32 ( uint32_t x, int8_t r )
50
- {
51
- return (x << r) | (x >> (32 - r));
52
- }
46
+ #define MURMUR3_FORCE_INLINE inline __attribute__((always_inline))
53
47
 
54
48
  inline uint64_t rotl64 ( uint64_t x, int8_t r )
55
49
  {
56
50
  return (x << r) | (x >> (64 - r));
57
51
  }
58
52
 
59
- #define ROTL32(x,y) rotl32(x,y)
60
- #define ROTL64(x,y) rotl64(x,y)
53
+ #define MURMUR3_ROTL64(x,y) rotl64(x,y)
61
54
 
62
- #define BIG_CONSTANT(x) (x##LLU)
55
+ #define MURMUR3_BIG_CONSTANT(x) (x##LLU)
63
56
 
64
57
  #endif // !defined(_MSC_VER)
65
58
 
@@ -78,7 +71,7 @@ typedef struct {
78
71
  // Block read - if your platform needs to do endian-swapping or can only
79
72
  // handle aligned reads, do the conversion here
80
73
 
81
- FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, size_t i )
74
+ MURMUR3_FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, size_t i )
82
75
  {
83
76
  uint64_t res;
84
77
  memcpy(&res, p + i, sizeof(res));
@@ -88,20 +81,21 @@ FORCE_INLINE uint64_t getblock64 ( const uint64_t * p, size_t i )
88
81
  //-----------------------------------------------------------------------------
89
82
  // Finalization mix - force all bits of a hash block to avalanche
90
83
 
91
- FORCE_INLINE uint64_t fmix64 ( uint64_t k )
84
+ MURMUR3_FORCE_INLINE uint64_t fmix64 ( uint64_t k )
92
85
  {
93
86
  k ^= k >> 33;
94
- k *= BIG_CONSTANT(0xff51afd7ed558ccd);
87
+ k *= MURMUR3_BIG_CONSTANT(0xff51afd7ed558ccd);
95
88
  k ^= k >> 33;
96
- k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
89
+ k *= MURMUR3_BIG_CONSTANT(0xc4ceb9fe1a85ec53);
97
90
  k ^= k >> 33;
98
91
 
99
92
  return k;
100
93
  }
101
94
 
102
- FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t seed, HashState& out) {
103
- static const uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
104
- static const uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
95
+ MURMUR3_FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes,
96
+ uint64_t seed, HashState& out) {
97
+ static const uint64_t c1 = MURMUR3_BIG_CONSTANT(0x87c37b91114253d5);
98
+ static const uint64_t c2 = MURMUR3_BIG_CONSTANT(0x4cf5ad432745937f);
105
99
 
106
100
  const uint8_t* data = (const uint8_t*)key;
107
101
 
@@ -118,13 +112,13 @@ FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t
118
112
  uint64_t k1 = getblock64(blocks, i * 2 + 0);
119
113
  uint64_t k2 = getblock64(blocks, i * 2 + 1);
120
114
 
121
- k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; out.h1 ^= k1;
122
- out.h1 = ROTL64(out.h1,27);
115
+ k1 *= c1; k1 = MURMUR3_ROTL64(k1,31); k1 *= c2; out.h1 ^= k1;
116
+ out.h1 = MURMUR3_ROTL64(out.h1,27);
123
117
  out.h1 += out.h2;
124
118
  out.h1 = out.h1*5+0x52dce729;
125
119
 
126
- k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; out.h2 ^= k2;
127
- out.h2 = ROTL64(out.h2,31);
120
+ k2 *= c2; k2 = MURMUR3_ROTL64(k2,33); k2 *= c1; out.h2 ^= k2;
121
+ out.h2 = MURMUR3_ROTL64(out.h2,31);
128
122
  out.h2 += out.h1;
129
123
  out.h2 = out.h2*5+0x38495ab5;
130
124
  }
@@ -144,7 +138,7 @@ FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t
144
138
  case 11: k2 ^= ((uint64_t)tail[10]) << 16; // falls through
145
139
  case 10: k2 ^= ((uint64_t)tail[ 9]) << 8; // falls through
146
140
  case 9: k2 ^= ((uint64_t)tail[ 8]) << 0;
147
- k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; out.h2 ^= k2;
141
+ k2 *= c2; k2 = MURMUR3_ROTL64(k2,33); k2 *= c1; out.h2 ^= k2;
148
142
  // falls through
149
143
  case 8: k1 ^= ((uint64_t)tail[ 7]) << 56; // falls through
150
144
  case 7: k1 ^= ((uint64_t)tail[ 6]) << 48; // falls through
@@ -154,7 +148,7 @@ FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t
154
148
  case 3: k1 ^= ((uint64_t)tail[ 2]) << 16; // falls through
155
149
  case 2: k1 ^= ((uint64_t)tail[ 1]) << 8; // falls through
156
150
  case 1: k1 ^= ((uint64_t)tail[ 0]) << 0;
157
- k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; out.h1 ^= k1;
151
+ k1 *= c1; k1 = MURMUR3_ROTL64(k1,31); k1 *= c2; out.h1 ^= k1;
158
152
  };
159
153
 
160
154
  //----------
@@ -175,10 +169,14 @@ FORCE_INLINE void MurmurHash3_x64_128(const void* key, size_t lenBytes, uint64_t
175
169
 
176
170
  //-----------------------------------------------------------------------------
177
171
 
178
- FORCE_INLINE uint16_t compute_seed_hash(uint64_t seed) {
172
+ MURMUR3_FORCE_INLINE uint16_t compute_seed_hash(uint64_t seed) {
179
173
  HashState hashes;
180
174
  MurmurHash3_x64_128(&seed, sizeof(seed), 0, hashes);
181
175
  return static_cast<uint16_t>(hashes.h1 & 0xffff);
182
176
  }
183
177
 
178
+ #undef MURMUR3_FORCE_INLINE
179
+ #undef MURMUR3_ROTL64
180
+ #undef MURMUR3_BIG_CONSTANT
181
+
184
182
  #endif // _MURMURHASH3_H_
@@ -26,27 +26,32 @@
26
26
  #include <iostream>
27
27
  #include <random>
28
28
  #include <chrono>
29
+ #include <thread>
29
30
 
31
+ /// DataSketches namespace
30
32
  namespace datasketches {
31
33
 
32
34
  static const uint64_t DEFAULT_SEED = 9001;
33
35
 
34
36
  enum resize_factor { X1 = 0, X2, X4, X8 };
35
37
 
36
- template<typename A> using AllocChar = typename std::allocator_traits<A>::template rebind_alloc<char>;
37
- template<typename A> using string = std::basic_string<char, std::char_traits<char>, AllocChar<A>>;
38
-
39
- // random bit
40
- static std::independent_bits_engine<std::mt19937, 1, uint32_t>
41
- random_bit(static_cast<uint32_t>(std::chrono::system_clock::now().time_since_epoch().count()));
38
+ template<typename A> using string = std::basic_string<char, std::char_traits<char>, typename std::allocator_traits<A>::template rebind_alloc<char>>;
42
39
 
43
40
  // common random declarations
44
41
  namespace random_utils {
45
42
  static std::random_device rd; // possibly unsafe in MinGW with GCC < 9.2
46
- static std::mt19937_64 rand(rd());
47
- static std::uniform_real_distribution<> next_double(0.0, 1.0);
48
- }
43
+ static thread_local std::mt19937_64 rand(rd());
44
+ static thread_local std::uniform_real_distribution<> next_double(0.0, 1.0);
49
45
 
46
+ // thread-safe random bit
47
+ static thread_local std::independent_bits_engine<std::mt19937, 1, uint32_t>
48
+ random_bit(static_cast<uint32_t>(std::chrono::system_clock::now().time_since_epoch().count()
49
+ + std::hash<std::thread::id>{}(std::this_thread::get_id())));
50
+
51
+ inline void override_seed(uint64_t s) {
52
+ rand.seed(s);
53
+ }
54
+ }
50
55
 
51
56
  // utility function to hide unused compiler warning
52
57
  // usually has no additional cost
@@ -77,7 +82,7 @@ static inline void read(std::istream& is, T* ptr, size_t size_bytes) {
77
82
  }
78
83
 
79
84
  template<typename T>
80
- static inline void write(std::ostream& os, T& value) {
85
+ static inline void write(std::ostream& os, T value) {
81
86
  os.write(reinterpret_cast<const char*>(&value), sizeof(T));
82
87
  }
83
88
 
@@ -22,8 +22,6 @@
22
22
 
23
23
  #include <cstdint>
24
24
 
25
- #include <stdio.h>
26
-
27
25
  namespace datasketches {
28
26
 
29
27
  static const uint8_t byte_leading_zeros_table[256] = {
@@ -91,6 +89,17 @@ static inline uint8_t count_leading_zeros_in_u64(uint64_t input) {
91
89
  return 56 + byte_leading_zeros_table[(input ) & FCLZ_MASK_08];
92
90
  }
93
91
 
92
+ static inline uint8_t count_leading_zeros_in_u32(uint32_t input) {
93
+ if (input > FCLZ_MASK_24)
94
+ return byte_leading_zeros_table[(input >> 24) & FCLZ_MASK_08];
95
+ if (input > FCLZ_MASK_16)
96
+ return 8 + byte_leading_zeros_table[(input >> 16) & FCLZ_MASK_08];
97
+ if (input > FCLZ_MASK_08)
98
+ return 16 + byte_leading_zeros_table[(input >> 8) & FCLZ_MASK_08];
99
+ if (true)
100
+ return 24 + byte_leading_zeros_table[(input ) & FCLZ_MASK_08];
101
+ }
102
+
94
103
  static inline uint8_t count_trailing_zeros_in_u32(uint32_t input) {
95
104
  for (int i = 0; i < 4; i++) {
96
105
  const int byte = input & 0xff;
@@ -22,13 +22,16 @@
22
22
 
23
23
  namespace datasketches {
24
24
 
25
+ /**
26
+ * Kolmogorov-Smirnov test for KLL or Quantiles sketches
27
+ */
25
28
  class kolmogorov_smirnov {
26
29
  public:
27
30
  /**
28
31
  * Computes the raw delta area between two quantile sketches for the Kolmogorov-Smirnov Test.
29
32
  * Will work for a type-matched pair of KLL or Quantiles sketches of the same parameterized type T.
30
- * @param sketch1 KLL sketch 1
31
- * @param sketch2 KLL sketch 2
33
+ * @param sketch1 sketch 1
34
+ * @param sketch2 sketch 2
32
35
  * @return the raw delta between two KLL quantile sketches
33
36
  */
34
37
  template<typename Sketch>
@@ -39,8 +42,8 @@ public:
39
42
  * Adjusts the computed threshold by the error epsilons of the two given sketches.
40
43
  * See <a href="https://en.wikipedia.org/wiki/Kolmogorov-Smirnov_test">Kolmogorov–Smirnov Test</a>
41
44
  * Will work for a type-matched pair of KLL or Quantiles sketches of the same parameterized type T.
42
- * @param sketch1 KLL sketch 1
43
- * @param sketch2 KLL sketch 2
45
+ * @param sketch1 sketch 1
46
+ * @param sketch2 sketch 2
44
47
  * @param p Target p-value. Typically .001 to .1, e.g., .05.
45
48
  * @return the adjusted threshold to be compared with the raw delta
46
49
  */
@@ -52,8 +55,8 @@ public:
52
55
  * Will work for a type-matched pair of KLL or Quantiles sketches of the same parameterized type T.
53
56
  * Note: if the given sketches have insufficient data or if the sketch sizes are too small,
54
57
  * this will return false.
55
- * @param sketch1 KLL sketch 1
56
- * @param sketch2 KLL sketch 2
58
+ * @param sketch1 sketch 1
59
+ * @param sketch2 sketch 2
57
60
  * @param p Target p-value. Typically .001 to .1, e.g., .05.
58
61
  * @return Boolean indicating whether we can reject the null hypothesis (that the sketches
59
62
  * reflect the same underlying distribution) using the provided p-value.
@@ -24,6 +24,7 @@
24
24
  #include <exception>
25
25
  #include <iostream>
26
26
  #include <string>
27
+ #include <cstring>
27
28
 
28
29
  namespace datasketches {
29
30
 
@@ -54,14 +55,14 @@ static inline size_t copy_to_mem(const void* src, void* dst, size_t size) {
54
55
  }
55
56
 
56
57
  template<typename T>
57
- static inline size_t copy_to_mem(const T& item, void* dst) {
58
- memcpy(dst, &item, sizeof(T));
58
+ static inline size_t copy_from_mem(const void* src, T& item) {
59
+ memcpy(&item, src, sizeof(T));
59
60
  return sizeof(T);
60
61
  }
61
62
 
62
63
  template<typename T>
63
- static inline size_t copy_from_mem(const void* src, T& item) {
64
- memcpy(&item, src, sizeof(T));
64
+ static inline size_t copy_to_mem(T item, void* dst) {
65
+ memcpy(dst, &item, sizeof(T));
65
66
  return sizeof(T);
66
67
  }
67
68
 
@@ -0,0 +1,148 @@
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
+ #ifndef _OPTIONAL_HPP_
21
+ #define _OPTIONAL_HPP_
22
+
23
+ // This is a simplistic substitute for std::optional until we require C++17
24
+
25
+ #if (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))
26
+ #include <optional>
27
+ using std::optional;
28
+ #else
29
+
30
+ #include <type_traits>
31
+
32
+ namespace datasketches {
33
+
34
+ template<typename T>
35
+ class optional {
36
+ public:
37
+
38
+ optional() noexcept: initialized_(false) {}
39
+
40
+ optional(const T& value) noexcept(std::is_nothrow_copy_constructible<T>::value) {
41
+ new (&value_) T(value);
42
+ initialized_ = true;
43
+ }
44
+
45
+ optional(T&& value) noexcept(std::is_nothrow_move_constructible<T>::value) {
46
+ new (&value_) T(std::move(value));
47
+ initialized_ = true;
48
+ }
49
+
50
+ // conversion from compatible types
51
+ template<typename TT>
52
+ optional(const optional<TT>& other) noexcept(std::is_nothrow_constructible<T, TT>::value): initialized_(false) {
53
+ if (other.initialized_) {
54
+ new (&value_) T(other.value_);
55
+ initialized_ = true;
56
+ }
57
+ }
58
+
59
+ optional(const optional& other) noexcept(std::is_nothrow_copy_constructible<T>::value): initialized_(false) {
60
+ if (other.initialized_) {
61
+ new (&value_) T(other.value_);
62
+ initialized_ = true;
63
+ }
64
+ }
65
+
66
+ optional(optional&& other) noexcept(std::is_nothrow_move_constructible<T>::value): initialized_(false) {
67
+ if (other.initialized_) {
68
+ new (&value_) T(std::move(other.value_));
69
+ initialized_ = true;
70
+ }
71
+ }
72
+
73
+ ~optional() noexcept(std::is_nothrow_destructible<T>::value) {
74
+ if (initialized_) value_.~T();
75
+ }
76
+
77
+ explicit operator bool() const noexcept {
78
+ return initialized_;
79
+ }
80
+
81
+ optional& operator=(const optional& other)
82
+ noexcept(std::is_nothrow_copy_constructible<T>::value && std::is_nothrow_copy_assignable<T>::value) {
83
+ if (initialized_) {
84
+ if (other.initialized_) {
85
+ value_ = other.value_;
86
+ } else {
87
+ reset();
88
+ }
89
+ } else {
90
+ if (other.initialized_) {
91
+ new (&value_) T(other.value_);
92
+ initialized_ = true;
93
+ }
94
+ }
95
+ return *this;
96
+ }
97
+
98
+ optional& operator=(optional&& other)
99
+ noexcept(std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value) {
100
+ if (initialized_) {
101
+ if (other.initialized_) {
102
+ value_ = std::move(other.value_);
103
+ } else {
104
+ reset();
105
+ }
106
+ } else {
107
+ if (other.initialized_) {
108
+ new (&value_) T(std::move(other.value_));
109
+ initialized_ = true;
110
+ }
111
+ }
112
+ return *this;
113
+ }
114
+
115
+ template<typename... Args>
116
+ void emplace(Args&&... args) noexcept(std::is_nothrow_constructible<T, Args...>::value) {
117
+ new (&value_) T(args...);
118
+ initialized_ = true;
119
+ }
120
+
121
+ T& operator*() & noexcept { return value_; }
122
+ const T& operator*() const & noexcept { return value_; }
123
+ T&& operator*() && noexcept { return std::move(value_); }
124
+ const T&& operator*() const && noexcept { return std::move(value_); }
125
+
126
+ T* operator->() noexcept { return &value_; }
127
+ const T* operator->() const noexcept { return &value_; }
128
+
129
+ void reset() noexcept(std::is_nothrow_destructible<T>::value) {
130
+ if (initialized_) value_.~T();
131
+ initialized_ = false;
132
+ }
133
+
134
+ private:
135
+ union {
136
+ T value_;
137
+ };
138
+ bool initialized_;
139
+
140
+ // for converting constructor
141
+ template<typename TT> friend class optional;
142
+ };
143
+
144
+ } // namespace
145
+
146
+ #endif // C++17
147
+
148
+ #endif // _OPTIONAL_HPP_