datasketches 0.1.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/LICENSE +40 -3
  4. data/NOTICE +1 -1
  5. data/ext/datasketches/cpc_wrapper.cpp +12 -13
  6. data/ext/datasketches/ext.cpp +1 -1
  7. data/ext/datasketches/ext.h +4 -0
  8. data/ext/datasketches/extconf.rb +1 -1
  9. data/ext/datasketches/fi_wrapper.cpp +6 -8
  10. data/ext/datasketches/hll_wrapper.cpp +13 -14
  11. data/ext/datasketches/kll_wrapper.cpp +28 -76
  12. data/ext/datasketches/theta_wrapper.cpp +27 -41
  13. data/ext/datasketches/vo_wrapper.cpp +4 -6
  14. data/lib/datasketches/version.rb +1 -1
  15. data/vendor/datasketches-cpp/CMakeLists.txt +10 -0
  16. data/vendor/datasketches-cpp/LICENSE +40 -3
  17. data/vendor/datasketches-cpp/NOTICE +1 -1
  18. data/vendor/datasketches-cpp/README.md +4 -4
  19. data/vendor/datasketches-cpp/common/include/MurmurHash3.h +18 -7
  20. data/vendor/datasketches-cpp/common/include/binomial_bounds.hpp +8 -8
  21. data/vendor/datasketches-cpp/common/include/bounds_binomial_proportions.hpp +12 -15
  22. data/vendor/datasketches-cpp/common/include/common_defs.hpp +26 -0
  23. data/vendor/datasketches-cpp/common/include/conditional_forward.hpp +20 -8
  24. data/vendor/datasketches-cpp/common/include/count_zeros.hpp +2 -2
  25. data/vendor/datasketches-cpp/common/include/memory_operations.hpp +12 -0
  26. data/vendor/datasketches-cpp/common/include/serde.hpp +7 -7
  27. data/vendor/datasketches-cpp/common/test/CMakeLists.txt +24 -0
  28. data/vendor/datasketches-cpp/common/test/integration_test.cpp +77 -0
  29. data/vendor/datasketches-cpp/common/test/test_allocator.hpp +9 -1
  30. data/vendor/datasketches-cpp/cpc/include/cpc_common.hpp +13 -3
  31. data/vendor/datasketches-cpp/cpc/include/cpc_compressor.hpp +20 -20
  32. data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +116 -105
  33. data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +22 -6
  34. data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +140 -101
  35. data/vendor/datasketches-cpp/cpc/include/cpc_union.hpp +2 -2
  36. data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +20 -20
  37. data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +10 -16
  38. data/vendor/datasketches-cpp/cpc/include/icon_estimator.hpp +6 -6
  39. data/vendor/datasketches-cpp/cpc/include/u32_table.hpp +10 -10
  40. data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +21 -21
  41. data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +1 -0
  42. data/vendor/datasketches-cpp/cpc/test/compression_test.cpp +10 -10
  43. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_allocation_test.cpp +237 -0
  44. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +25 -0
  45. data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +1 -1
  46. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +15 -10
  47. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +102 -105
  48. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +19 -13
  49. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map_impl.hpp +141 -125
  50. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_custom_type_test.cpp +15 -12
  51. data/vendor/datasketches-cpp/fi/test/reverse_purge_hash_map_test.cpp +5 -5
  52. data/vendor/datasketches-cpp/hll/CMakeLists.txt +3 -0
  53. data/vendor/datasketches-cpp/hll/include/AuxHashMap-internal.hpp +81 -109
  54. data/vendor/datasketches-cpp/hll/include/AuxHashMap.hpp +25 -24
  55. data/vendor/datasketches-cpp/hll/include/CompositeInterpolationXTable-internal.hpp +15 -15
  56. data/vendor/datasketches-cpp/hll/include/CompositeInterpolationXTable.hpp +5 -5
  57. data/vendor/datasketches-cpp/hll/include/CouponHashSet-internal.hpp +89 -105
  58. data/vendor/datasketches-cpp/hll/include/CouponHashSet.hpp +13 -13
  59. data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +130 -165
  60. data/vendor/datasketches-cpp/hll/include/CouponList.hpp +21 -22
  61. data/vendor/datasketches-cpp/hll/include/CubicInterpolation-internal.hpp +2 -4
  62. data/vendor/datasketches-cpp/hll/include/CubicInterpolation.hpp +2 -2
  63. data/vendor/datasketches-cpp/hll/include/HarmonicNumbers-internal.hpp +1 -1
  64. data/vendor/datasketches-cpp/hll/include/HarmonicNumbers.hpp +2 -2
  65. data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +88 -83
  66. data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +9 -9
  67. data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +34 -45
  68. data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +7 -8
  69. data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +41 -52
  70. data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +7 -8
  71. data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +220 -251
  72. data/vendor/datasketches-cpp/hll/include/HllArray.hpp +42 -42
  73. data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +36 -38
  74. data/vendor/datasketches-cpp/hll/include/HllSketchImpl-internal.hpp +22 -22
  75. data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +15 -14
  76. data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +47 -44
  77. data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +62 -87
  78. data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +121 -128
  79. data/vendor/datasketches-cpp/hll/include/RelativeErrorTables.hpp +1 -1
  80. data/vendor/datasketches-cpp/hll/include/coupon_iterator-internal.hpp +9 -9
  81. data/vendor/datasketches-cpp/hll/include/coupon_iterator.hpp +5 -5
  82. data/vendor/datasketches-cpp/hll/include/hll.hpp +25 -53
  83. data/vendor/datasketches-cpp/hll/test/AuxHashMapTest.cpp +8 -8
  84. data/vendor/datasketches-cpp/hll/test/CouponHashSetTest.cpp +36 -36
  85. data/vendor/datasketches-cpp/hll/test/CouponListTest.cpp +28 -28
  86. data/vendor/datasketches-cpp/hll/test/CrossCountingTest.cpp +2 -2
  87. data/vendor/datasketches-cpp/hll/test/HllArrayTest.cpp +37 -37
  88. data/vendor/datasketches-cpp/hll/test/HllSketchTest.cpp +57 -61
  89. data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +10 -14
  90. data/vendor/datasketches-cpp/hll/test/IsomorphicTest.cpp +3 -3
  91. data/vendor/datasketches-cpp/hll/test/ToFromByteArrayTest.cpp +4 -4
  92. data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +5 -4
  93. data/vendor/datasketches-cpp/kll/include/kll_helper_impl.hpp +6 -6
  94. data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator.hpp +14 -6
  95. data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator_impl.hpp +40 -25
  96. data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +50 -6
  97. data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +164 -136
  98. data/vendor/datasketches-cpp/kll/include/kolmogorov_smirnov.hpp +67 -0
  99. data/vendor/datasketches-cpp/kll/include/kolmogorov_smirnov_impl.hpp +78 -0
  100. data/vendor/datasketches-cpp/kll/test/CMakeLists.txt +1 -0
  101. data/vendor/datasketches-cpp/kll/test/kll_sketch_custom_type_test.cpp +11 -10
  102. data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +178 -88
  103. data/vendor/datasketches-cpp/kll/test/kolmogorov_smirnov_test.cpp +111 -0
  104. data/vendor/datasketches-cpp/pyproject.toml +4 -2
  105. data/vendor/datasketches-cpp/python/CMakeLists.txt +12 -6
  106. data/vendor/datasketches-cpp/python/README.md +52 -49
  107. data/vendor/datasketches-cpp/python/pybind11Path.cmd +3 -0
  108. data/vendor/datasketches-cpp/python/src/cpc_wrapper.cpp +1 -1
  109. data/vendor/datasketches-cpp/python/src/datasketches.cpp +2 -0
  110. data/vendor/datasketches-cpp/python/src/hll_wrapper.cpp +4 -6
  111. data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +4 -2
  112. data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +246 -0
  113. data/vendor/datasketches-cpp/python/src/theta_wrapper.cpp +38 -28
  114. data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +11 -5
  115. data/vendor/datasketches-cpp/python/src/vo_wrapper.cpp +2 -2
  116. data/vendor/datasketches-cpp/python/tests/hll_test.py +1 -2
  117. data/vendor/datasketches-cpp/python/tests/kll_test.py +5 -5
  118. data/vendor/datasketches-cpp/python/tests/req_test.py +126 -0
  119. data/vendor/datasketches-cpp/python/tests/theta_test.py +28 -3
  120. data/vendor/datasketches-cpp/python/tests/vector_of_kll_test.py +4 -4
  121. data/vendor/datasketches-cpp/python/tests/vo_test.py +3 -3
  122. data/vendor/datasketches-cpp/req/CMakeLists.txt +60 -0
  123. data/vendor/datasketches-cpp/{tuple/include/theta_a_not_b_experimental_impl.hpp → req/include/req_common.hpp} +18 -8
  124. data/vendor/datasketches-cpp/req/include/req_compactor.hpp +137 -0
  125. data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +488 -0
  126. data/vendor/datasketches-cpp/req/include/req_quantile_calculator.hpp +69 -0
  127. data/vendor/datasketches-cpp/req/include/req_quantile_calculator_impl.hpp +60 -0
  128. data/vendor/datasketches-cpp/req/include/req_sketch.hpp +395 -0
  129. data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +810 -0
  130. data/vendor/datasketches-cpp/req/test/CMakeLists.txt +43 -0
  131. data/vendor/datasketches-cpp/req/test/req_float_empty_from_java.sk +0 -0
  132. data/vendor/datasketches-cpp/req/test/req_float_estimation_from_java.sk +0 -0
  133. data/vendor/datasketches-cpp/req/test/req_float_exact_from_java.sk +0 -0
  134. data/vendor/datasketches-cpp/req/test/req_float_raw_items_from_java.sk +0 -0
  135. data/vendor/datasketches-cpp/req/test/req_float_single_item_from_java.sk +0 -0
  136. data/vendor/datasketches-cpp/req/test/req_sketch_custom_type_test.cpp +128 -0
  137. data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +494 -0
  138. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +19 -13
  139. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +130 -127
  140. data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +5 -5
  141. data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +41 -49
  142. data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +1 -0
  143. data/vendor/datasketches-cpp/sampling/test/var_opt_allocation_test.cpp +96 -0
  144. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +6 -6
  145. data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +13 -44
  146. data/vendor/datasketches-cpp/setup.py +11 -6
  147. data/vendor/datasketches-cpp/theta/CMakeLists.txt +30 -3
  148. data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_sampled_sets.hpp +3 -2
  149. data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_theta_sketched_sets.hpp +1 -1
  150. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser.hpp +67 -0
  151. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser_impl.hpp +70 -0
  152. data/vendor/datasketches-cpp/theta/include/theta_a_not_b.hpp +12 -29
  153. data/vendor/datasketches-cpp/theta/include/theta_a_not_b_impl.hpp +5 -46
  154. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_comparators.hpp +0 -0
  155. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_constants.hpp +11 -4
  156. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_helpers.hpp +0 -0
  157. data/vendor/datasketches-cpp/theta/include/theta_intersection.hpp +26 -28
  158. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_intersection_base.hpp +0 -0
  159. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_intersection_base_impl.hpp +0 -0
  160. data/vendor/datasketches-cpp/theta/include/theta_intersection_impl.hpp +8 -90
  161. data/vendor/datasketches-cpp/{tuple/test/theta_union_experimental_test.cpp → theta/include/theta_jaccard_similarity.hpp} +11 -18
  162. data/vendor/datasketches-cpp/{tuple/include/jaccard_similarity.hpp → theta/include/theta_jaccard_similarity_base.hpp} +24 -36
  163. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_set_difference_base.hpp +0 -0
  164. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_set_difference_base_impl.hpp +5 -0
  165. data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +163 -256
  166. data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +250 -651
  167. data/vendor/datasketches-cpp/theta/include/theta_union.hpp +27 -60
  168. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_union_base.hpp +1 -1
  169. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_union_base_impl.hpp +6 -1
  170. data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +13 -69
  171. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base.hpp +10 -21
  172. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base_impl.hpp +44 -30
  173. data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +1 -0
  174. data/vendor/datasketches-cpp/theta/test/theta_a_not_b_test.cpp +23 -1
  175. data/vendor/datasketches-cpp/theta/test/theta_intersection_test.cpp +21 -1
  176. data/vendor/datasketches-cpp/{tuple → theta}/test/theta_jaccard_similarity_test.cpp +60 -5
  177. data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +74 -235
  178. data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +22 -2
  179. data/vendor/datasketches-cpp/tuple/CMakeLists.txt +3 -35
  180. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_sketch_impl.hpp +47 -60
  181. data/vendor/datasketches-cpp/tuple/include/tuple_jaccard_similarity.hpp +38 -0
  182. data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +28 -13
  183. data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +57 -70
  184. data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +1 -6
  185. data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +1 -1
  186. data/vendor/datasketches-cpp/tuple/test/tuple_a_not_b_test.cpp +18 -21
  187. data/vendor/datasketches-cpp/tuple/test/tuple_intersection_test.cpp +13 -16
  188. data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +7 -6
  189. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_allocation_test.cpp +3 -3
  190. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +20 -20
  191. data/vendor/datasketches-cpp/tuple/test/tuple_union_test.cpp +13 -16
  192. metadata +51 -36
  193. data/vendor/datasketches-cpp/tuple/include/theta_a_not_b_experimental.hpp +0 -53
  194. data/vendor/datasketches-cpp/tuple/include/theta_intersection_experimental.hpp +0 -78
  195. data/vendor/datasketches-cpp/tuple/include/theta_intersection_experimental_impl.hpp +0 -43
  196. data/vendor/datasketches-cpp/tuple/include/theta_sketch_experimental.hpp +0 -393
  197. data/vendor/datasketches-cpp/tuple/include/theta_sketch_experimental_impl.hpp +0 -481
  198. data/vendor/datasketches-cpp/tuple/include/theta_union_experimental.hpp +0 -88
  199. data/vendor/datasketches-cpp/tuple/include/theta_union_experimental_impl.hpp +0 -47
  200. data/vendor/datasketches-cpp/tuple/test/theta_a_not_b_experimental_test.cpp +0 -250
  201. data/vendor/datasketches-cpp/tuple/test/theta_compact_empty_from_java.sk +0 -0
  202. data/vendor/datasketches-cpp/tuple/test/theta_compact_estimation_from_java.sk +0 -0
  203. data/vendor/datasketches-cpp/tuple/test/theta_compact_single_item_from_java.sk +0 -0
  204. data/vendor/datasketches-cpp/tuple/test/theta_intersection_experimental_test.cpp +0 -224
  205. data/vendor/datasketches-cpp/tuple/test/theta_sketch_experimental_test.cpp +0 -247
@@ -70,33 +70,33 @@ uint8_t compact_array_of_doubles_sketch_alloc<A>::get_num_values() const {
70
70
  template<typename A>
71
71
  void compact_array_of_doubles_sketch_alloc<A>::serialize(std::ostream& os) const {
72
72
  const uint8_t preamble_longs = 1;
73
- os.write(reinterpret_cast<const char*>(&preamble_longs), sizeof(preamble_longs));
73
+ write(os, preamble_longs);
74
74
  const uint8_t serial_version = SERIAL_VERSION;
75
- os.write(reinterpret_cast<const char*>(&serial_version), sizeof(serial_version));
75
+ write(os, serial_version);
76
76
  const uint8_t family = SKETCH_FAMILY;
77
- os.write(reinterpret_cast<const char*>(&family), sizeof(family));
77
+ write(os, family);
78
78
  const uint8_t type = SKETCH_TYPE;
79
- os.write(reinterpret_cast<const char*>(&type), sizeof(type));
79
+ write(os, type);
80
80
  const uint8_t flags_byte(
81
81
  (this->is_empty() ? 1 << flags::IS_EMPTY : 0) |
82
82
  (this->get_num_retained() > 0 ? 1 << flags::HAS_ENTRIES : 0) |
83
83
  (this->is_ordered() ? 1 << flags::IS_ORDERED : 0)
84
84
  );
85
- os.write(reinterpret_cast<const char*>(&flags_byte), sizeof(flags_byte));
86
- os.write(reinterpret_cast<const char*>(&num_values_), sizeof(num_values_));
85
+ write(os, flags_byte);
86
+ write(os, num_values_);
87
87
  const uint16_t seed_hash = this->get_seed_hash();
88
- os.write(reinterpret_cast<const char*>(&seed_hash), sizeof(seed_hash));
89
- os.write(reinterpret_cast<const char*>(&(this->theta_)), sizeof(uint64_t));
88
+ write(os, seed_hash);
89
+ write(os, this->theta_);
90
90
  if (this->get_num_retained() > 0) {
91
- const uint32_t num_entries = this->entries_.size();
92
- os.write(reinterpret_cast<const char*>(&num_entries), sizeof(num_entries));
91
+ const uint32_t num_entries = static_cast<uint32_t>(this->entries_.size());
92
+ write(os, num_entries);
93
93
  const uint32_t unused32 = 0;
94
- os.write(reinterpret_cast<const char*>(&unused32), sizeof(unused32));
94
+ write(os, unused32);
95
95
  for (const auto& it: this->entries_) {
96
- os.write(reinterpret_cast<const char*>(&it.first), sizeof(uint64_t));
96
+ write(os, it.first);
97
97
  }
98
98
  for (const auto& it: this->entries_) {
99
- os.write(reinterpret_cast<const char*>(it.second.data()), it.second.size() * sizeof(double));
99
+ write(os, it.second.data(), it.second.size() * sizeof(double));
100
100
  }
101
101
  }
102
102
  }
@@ -110,30 +110,29 @@ auto compact_array_of_doubles_sketch_alloc<A>::serialize(unsigned header_size_by
110
110
  vector_bytes bytes(size, 0, this->entries_.get_allocator());
111
111
  uint8_t* ptr = bytes.data() + header_size_bytes;
112
112
 
113
- ptr += copy_to_mem(&preamble_longs, ptr, sizeof(preamble_longs));
113
+ ptr += copy_to_mem(preamble_longs, ptr);
114
114
  const uint8_t serial_version = SERIAL_VERSION;
115
- ptr += copy_to_mem(&serial_version, ptr, sizeof(serial_version));
115
+ ptr += copy_to_mem(serial_version, ptr);
116
116
  const uint8_t family = SKETCH_FAMILY;
117
- ptr += copy_to_mem(&family, ptr, sizeof(family));
117
+ ptr += copy_to_mem(family, ptr);
118
118
  const uint8_t type = SKETCH_TYPE;
119
- ptr += copy_to_mem(&type, ptr, sizeof(type));
119
+ ptr += copy_to_mem(type, ptr);
120
120
  const uint8_t flags_byte(
121
121
  (this->is_empty() ? 1 << flags::IS_EMPTY : 0) |
122
122
  (this->get_num_retained() ? 1 << flags::HAS_ENTRIES : 0) |
123
123
  (this->is_ordered() ? 1 << flags::IS_ORDERED : 0)
124
124
  );
125
- ptr += copy_to_mem(&flags_byte, ptr, sizeof(flags_byte));
126
- ptr += copy_to_mem(&num_values_, ptr, sizeof(num_values_));
125
+ ptr += copy_to_mem(flags_byte, ptr);
126
+ ptr += copy_to_mem(num_values_, ptr);
127
127
  const uint16_t seed_hash = this->get_seed_hash();
128
- ptr += copy_to_mem(&seed_hash, ptr, sizeof(seed_hash));
129
- ptr += copy_to_mem(&(this->theta_), ptr, sizeof(uint64_t));
128
+ ptr += copy_to_mem(seed_hash, ptr);
129
+ ptr += copy_to_mem((this->theta_), ptr);
130
130
  if (this->get_num_retained() > 0) {
131
- const uint32_t num_entries = this->entries_.size();
132
- ptr += copy_to_mem(&num_entries, ptr, sizeof(num_entries));
133
- const uint32_t unused32 = 0;
134
- ptr += copy_to_mem(&unused32, ptr, sizeof(unused32));
131
+ const uint32_t num_entries = static_cast<uint32_t>(this->entries_.size());
132
+ ptr += copy_to_mem(num_entries, ptr);
133
+ ptr += sizeof(uint32_t); // unused
135
134
  for (const auto& it: this->entries_) {
136
- ptr += copy_to_mem(&it.first, ptr, sizeof(uint64_t));
135
+ ptr += copy_to_mem(it.first, ptr);
137
136
  }
138
137
  for (const auto& it: this->entries_) {
139
138
  ptr += copy_to_mem(it.second.data(), ptr, it.second.size() * sizeof(double));
@@ -144,40 +143,30 @@ auto compact_array_of_doubles_sketch_alloc<A>::serialize(unsigned header_size_by
144
143
 
145
144
  template<typename A>
146
145
  compact_array_of_doubles_sketch_alloc<A> compact_array_of_doubles_sketch_alloc<A>::deserialize(std::istream& is, uint64_t seed, const A& allocator) {
147
- uint8_t preamble_longs;
148
- is.read(reinterpret_cast<char*>(&preamble_longs), sizeof(preamble_longs));
149
- uint8_t serial_version;
150
- is.read(reinterpret_cast<char*>(&serial_version), sizeof(serial_version));
151
- uint8_t family;
152
- is.read(reinterpret_cast<char*>(&family), sizeof(family));
153
- uint8_t type;
154
- is.read(reinterpret_cast<char*>(&type), sizeof(type));
155
- uint8_t flags_byte;
156
- is.read(reinterpret_cast<char*>(&flags_byte), sizeof(flags_byte));
157
- uint8_t num_values;
158
- is.read(reinterpret_cast<char*>(&num_values), sizeof(num_values));
159
- uint16_t seed_hash;
160
- is.read(reinterpret_cast<char*>(&seed_hash), sizeof(seed_hash));
146
+ read<uint8_t>(is); // unused
147
+ const auto serial_version = read<uint8_t>(is);
148
+ const auto family = read<uint8_t>(is);
149
+ const auto type = read<uint8_t>(is);
150
+ const auto flags_byte = read<uint8_t>(is);
151
+ const auto num_values = read<uint8_t>(is);
152
+ const auto seed_hash = read<uint16_t>(is);
161
153
  checker<true>::check_serial_version(serial_version, SERIAL_VERSION);
162
154
  checker<true>::check_sketch_family(family, SKETCH_FAMILY);
163
155
  checker<true>::check_sketch_type(type, SKETCH_TYPE);
164
156
  const bool has_entries = flags_byte & (1 << flags::HAS_ENTRIES);
165
157
  if (has_entries) checker<true>::check_seed_hash(seed_hash, compute_seed_hash(seed));
166
158
 
167
- uint64_t theta;
168
- is.read(reinterpret_cast<char*>(&theta), sizeof(theta));
159
+ const auto theta = read<uint64_t>(is);
169
160
  std::vector<Entry, AllocEntry> entries(allocator);
170
161
  if (has_entries) {
171
- uint32_t num_entries;
172
- is.read(reinterpret_cast<char*>(&num_entries), sizeof(num_entries));
173
- uint32_t unused32;
174
- is.read(reinterpret_cast<char*>(&unused32), sizeof(unused32));
162
+ const auto num_entries = read<uint32_t>(is);
163
+ read<uint32_t>(is); // unused
175
164
  entries.reserve(num_entries);
176
165
  std::vector<uint64_t, AllocU64> keys(num_entries, 0, allocator);
177
- is.read(reinterpret_cast<char*>(keys.data()), num_entries * sizeof(uint64_t));
166
+ read(is, keys.data(), num_entries * sizeof(uint64_t));
178
167
  for (size_t i = 0; i < num_entries; ++i) {
179
168
  aod<A> summary(num_values, allocator);
180
- is.read(reinterpret_cast<char*>(summary.data()), num_values * sizeof(double));
169
+ read(is, summary.data(), num_values * sizeof(double));
181
170
  entries.push_back(Entry(keys[i], std::move(summary)));
182
171
  }
183
172
  }
@@ -191,20 +180,19 @@ template<typename A>
191
180
  compact_array_of_doubles_sketch_alloc<A> compact_array_of_doubles_sketch_alloc<A>::deserialize(const void* bytes, size_t size, uint64_t seed, const A& allocator) {
192
181
  ensure_minimum_memory(size, 16);
193
182
  const char* ptr = static_cast<const char*>(bytes);
194
- uint8_t preamble_longs;
195
- ptr += copy_from_mem(ptr, &preamble_longs, sizeof(preamble_longs));
183
+ ptr += sizeof(uint8_t); // unused
196
184
  uint8_t serial_version;
197
- ptr += copy_from_mem(ptr, &serial_version, sizeof(serial_version));
185
+ ptr += copy_from_mem(ptr, serial_version);
198
186
  uint8_t family;
199
- ptr += copy_from_mem(ptr, &family, sizeof(family));
187
+ ptr += copy_from_mem(ptr, family);
200
188
  uint8_t type;
201
- ptr += copy_from_mem(ptr, &type, sizeof(type));
189
+ ptr += copy_from_mem(ptr, type);
202
190
  uint8_t flags_byte;
203
- ptr += copy_from_mem(ptr, &flags_byte, sizeof(flags_byte));
191
+ ptr += copy_from_mem(ptr, flags_byte);
204
192
  uint8_t num_values;
205
- ptr += copy_from_mem(ptr, &num_values, sizeof(num_values));
193
+ ptr += copy_from_mem(ptr, num_values);
206
194
  uint16_t seed_hash;
207
- ptr += copy_from_mem(ptr, &seed_hash, sizeof(seed_hash));
195
+ ptr += copy_from_mem(ptr, seed_hash);
208
196
  checker<true>::check_serial_version(serial_version, SERIAL_VERSION);
209
197
  checker<true>::check_sketch_family(family, SKETCH_FAMILY);
210
198
  checker<true>::check_sketch_type(type, SKETCH_TYPE);
@@ -212,14 +200,13 @@ compact_array_of_doubles_sketch_alloc<A> compact_array_of_doubles_sketch_alloc<A
212
200
  if (has_entries) checker<true>::check_seed_hash(seed_hash, compute_seed_hash(seed));
213
201
 
214
202
  uint64_t theta;
215
- ptr += copy_from_mem(ptr, &theta, sizeof(theta));
203
+ ptr += copy_from_mem(ptr, theta);
216
204
  std::vector<Entry, AllocEntry> entries(allocator);
217
205
  if (has_entries) {
218
206
  ensure_minimum_memory(size, 24);
219
207
  uint32_t num_entries;
220
- ptr += copy_from_mem(ptr, &num_entries, sizeof(num_entries));
221
- uint32_t unused32;
222
- ptr += copy_from_mem(ptr, &unused32, sizeof(unused32));
208
+ ptr += copy_from_mem(ptr, num_entries);
209
+ ptr += sizeof(uint32_t); // unused
223
210
  ensure_minimum_memory(size, 24 + (sizeof(uint64_t) + sizeof(double) * num_values) * num_entries);
224
211
  entries.reserve(num_entries);
225
212
  std::vector<uint64_t, AllocU64> keys(num_entries, 0, allocator);
@@ -0,0 +1,38 @@
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 TUPLE_JACCARD_SIMILARITY_HPP_
21
+ #define TUPLE_JACCARD_SIMILARITY_HPP_
22
+
23
+ #include "theta_jaccard_similarity_base.hpp"
24
+ #include "tuple_union.hpp"
25
+ #include "tuple_intersection.hpp"
26
+
27
+ namespace datasketches {
28
+
29
+ template<
30
+ typename Summary,
31
+ typename IntersectionPolicy,
32
+ typename UnionPolicy = default_union_policy<Summary>,
33
+ typename Allocator = std::allocator<Summary>>
34
+ using tuple_jaccard_similarity = jaccard_similarity_base<tuple_union<Summary, UnionPolicy, Allocator>, tuple_intersection<Summary, IntersectionPolicy, Allocator>, pair_extract_key<uint64_t, Summary>>;
35
+
36
+ } /* namespace datasketches */
37
+
38
+ # endif
@@ -31,7 +31,17 @@ namespace datasketches {
31
31
  template<typename S, typename A> class tuple_sketch;
32
32
  template<typename S, typename U, typename P, typename A> class update_tuple_sketch;
33
33
  template<typename S, typename A> class compact_tuple_sketch;
34
- template<typename A> class theta_sketch_experimental;
34
+ template<typename A> class theta_sketch_alloc;
35
+
36
+ template<typename K, typename V>
37
+ struct pair_extract_key {
38
+ K& operator()(std::pair<K, V>& entry) const {
39
+ return entry.first;
40
+ }
41
+ const K& operator()(const std::pair<K, V>& entry) const {
42
+ return entry.first;
43
+ }
44
+ };
35
45
 
36
46
  template<
37
47
  typename Summary,
@@ -143,7 +153,8 @@ public:
143
153
  virtual const_iterator end() const = 0;
144
154
 
145
155
  protected:
146
- virtual void print_specifics(std::basic_ostream<char>& os) const = 0;
156
+ using ostrstream = std::basic_ostringstream<char, std::char_traits<char>, AllocChar<Allocator>>;
157
+ virtual void print_specifics(ostrstream& os) const = 0;
147
158
 
148
159
  static uint16_t get_seed_hash(uint64_t seed);
149
160
 
@@ -333,7 +344,8 @@ protected:
333
344
  // for builder
334
345
  update_tuple_sketch(uint8_t lg_cur_size, uint8_t lg_nom_size, resize_factor rf, uint64_t theta, uint64_t seed, const Policy& policy, const Allocator& allocator);
335
346
 
336
- virtual void print_specifics(std::basic_ostream<char>& os) const;
347
+ using ostrstream = typename Base::ostrstream;
348
+ virtual void print_specifics(ostrstream& os) const;
337
349
  };
338
350
 
339
351
  // compact sketch
@@ -372,7 +384,7 @@ public:
372
384
  compact_tuple_sketch& operator=(const compact_tuple_sketch&) = default;
373
385
  compact_tuple_sketch& operator=(compact_tuple_sketch&&) = default;
374
386
 
375
- compact_tuple_sketch(const theta_sketch_experimental<AllocU64>& other, const Summary& summary, bool ordered = true);
387
+ compact_tuple_sketch(const theta_sketch_alloc<AllocU64>& other, const Summary& summary, bool ordered = true);
376
388
 
377
389
  virtual Allocator get_allocator() const;
378
390
  virtual bool is_empty() const;
@@ -444,22 +456,25 @@ protected:
444
456
  // for deserialize
445
457
  class deleter_of_summaries {
446
458
  public:
447
- deleter_of_summaries(uint32_t num, bool destroy): num(num), destroy(destroy) {}
448
- void set_destroy(bool destroy) { this->destroy = destroy; }
449
- void operator() (Summary* ptr) const {
459
+ deleter_of_summaries(uint32_t num, bool destroy, const Allocator& allocator):
460
+ allocator_(allocator), num_(num), destroy_(destroy) {}
461
+ void set_destroy(bool destroy) { destroy_ = destroy; }
462
+ void operator() (Summary* ptr) {
450
463
  if (ptr != nullptr) {
451
- if (destroy) {
452
- for (uint32_t i = 0; i < num; ++i) ptr[i].~Summary();
464
+ if (destroy_) {
465
+ for (uint32_t i = 0; i < num_; ++i) ptr[i].~Summary();
453
466
  }
454
- Allocator().deallocate(ptr, num);
467
+ allocator_.deallocate(ptr, num_);
455
468
  }
456
469
  }
457
470
  private:
458
- uint32_t num;
459
- bool destroy;
471
+ Allocator allocator_;
472
+ uint32_t num_;
473
+ bool destroy_;
460
474
  };
461
475
 
462
- virtual void print_specifics(std::basic_ostream<char>& os) const;
476
+ using ostrstream = typename Base::ostrstream;
477
+ virtual void print_specifics(ostrstream& os) const;
463
478
 
464
479
  };
465
480
 
@@ -53,7 +53,7 @@ double tuple_sketch<S, A>::get_upper_bound(uint8_t num_std_devs) const {
53
53
 
54
54
  template<typename S, typename A>
55
55
  string<A> tuple_sketch<S, A>::to_string(bool detail) const {
56
- std::basic_ostringstream<char, std::char_traits<char>, AllocChar<A>> os;
56
+ ostrstream os;
57
57
  os << "### Tuple sketch summary:" << std::endl;
58
58
  os << " num retained entries : " << get_num_retained() << std::endl;
59
59
  os << " seed hash : " << get_seed_hash() << std::endl;
@@ -238,7 +238,7 @@ compact_tuple_sketch<S, A> update_tuple_sketch<S, U, P, A>::compact(bool ordered
238
238
  }
239
239
 
240
240
  template<typename S, typename U, typename P, typename A>
241
- void update_tuple_sketch<S, U, P, A>::print_specifics(std::basic_ostream<char>& os) const {
241
+ void update_tuple_sketch<S, U, P, A>::print_specifics(ostrstream& os) const {
242
242
  os << " lg nominal size : " << (int) map_.lg_nom_size_ << std::endl;
243
243
  os << " lg current size : " << (int) map_.lg_cur_size_ << std::endl;
244
244
  os << " resize factor : " << (1 << map_.rf_) << std::endl;
@@ -279,7 +279,7 @@ entries_(std::move(other.entries_))
279
279
  {}
280
280
 
281
281
  template<typename S, typename A>
282
- compact_tuple_sketch<S, A>::compact_tuple_sketch(const theta_sketch_experimental<AllocU64>& other, const S& summary, bool ordered):
282
+ compact_tuple_sketch<S, A>::compact_tuple_sketch(const theta_sketch_alloc<AllocU64>& other, const S& summary, bool ordered):
283
283
  is_empty_(other.is_empty()),
284
284
  is_ordered_(other.is_ordered() || ordered),
285
285
  seed_hash_(other.get_seed_hash()),
@@ -315,7 +315,7 @@ uint64_t compact_tuple_sketch<S, A>::get_theta64() const {
315
315
 
316
316
  template<typename S, typename A>
317
317
  uint32_t compact_tuple_sketch<S, A>::get_num_retained() const {
318
- return entries_.size();
318
+ return static_cast<uint32_t>(entries_.size());
319
319
  }
320
320
 
321
321
  template<typename S, typename A>
@@ -347,36 +347,36 @@ template<typename SerDe>
347
347
  void compact_tuple_sketch<S, A>::serialize(std::ostream& os, const SerDe& sd) const {
348
348
  const bool is_single_item = entries_.size() == 1 && !this->is_estimation_mode();
349
349
  const uint8_t preamble_longs = this->is_empty() || is_single_item ? 1 : this->is_estimation_mode() ? 3 : 2;
350
- os.write(reinterpret_cast<const char*>(&preamble_longs), sizeof(preamble_longs));
350
+ write(os, preamble_longs);
351
351
  const uint8_t serial_version = SERIAL_VERSION;
352
- os.write(reinterpret_cast<const char*>(&serial_version), sizeof(serial_version));
352
+ write(os, serial_version);
353
353
  const uint8_t family = SKETCH_FAMILY;
354
- os.write(reinterpret_cast<const char*>(&family), sizeof(family));
354
+ write(os, family);
355
355
  const uint8_t type = SKETCH_TYPE;
356
- os.write(reinterpret_cast<const char*>(&type), sizeof(type));
356
+ write(os, type);
357
357
  const uint8_t unused8 = 0;
358
- os.write(reinterpret_cast<const char*>(&unused8), sizeof(unused8));
358
+ write(os, unused8);
359
359
  const uint8_t flags_byte(
360
360
  (1 << flags::IS_COMPACT) |
361
361
  (1 << flags::IS_READ_ONLY) |
362
362
  (this->is_empty() ? 1 << flags::IS_EMPTY : 0) |
363
363
  (this->is_ordered() ? 1 << flags::IS_ORDERED : 0)
364
364
  );
365
- os.write(reinterpret_cast<const char*>(&flags_byte), sizeof(flags_byte));
365
+ write(os, flags_byte);
366
366
  const uint16_t seed_hash = get_seed_hash();
367
- os.write(reinterpret_cast<const char*>(&seed_hash), sizeof(seed_hash));
367
+ write(os, seed_hash);
368
368
  if (!this->is_empty()) {
369
369
  if (!is_single_item) {
370
- const uint32_t num_entries = entries_.size();
371
- os.write(reinterpret_cast<const char*>(&num_entries), sizeof(num_entries));
370
+ const uint32_t num_entries = static_cast<uint32_t>(entries_.size());
371
+ write(os, num_entries);
372
372
  const uint32_t unused32 = 0;
373
- os.write(reinterpret_cast<const char*>(&unused32), sizeof(unused32));
373
+ write(os, unused32);
374
374
  if (this->is_estimation_mode()) {
375
- os.write(reinterpret_cast<const char*>(&(this->theta_)), sizeof(uint64_t));
375
+ write(os, this->theta_);
376
376
  }
377
377
  }
378
378
  for (const auto& it: entries_) {
379
- os.write(reinterpret_cast<const char*>(&it.first), sizeof(uint64_t));
379
+ write(os, it.first);
380
380
  sd.serialize(os, &it.second, 1);
381
381
  }
382
382
  }
@@ -393,36 +393,34 @@ auto compact_tuple_sketch<S, A>::serialize(unsigned header_size_bytes, const Ser
393
393
  uint8_t* ptr = bytes.data() + header_size_bytes;
394
394
  const uint8_t* end_ptr = ptr + size;
395
395
 
396
- ptr += copy_to_mem(&preamble_longs, ptr, sizeof(preamble_longs));
396
+ ptr += copy_to_mem(preamble_longs, ptr);
397
397
  const uint8_t serial_version = SERIAL_VERSION;
398
- ptr += copy_to_mem(&serial_version, ptr, sizeof(serial_version));
398
+ ptr += copy_to_mem(serial_version, ptr);
399
399
  const uint8_t family = SKETCH_FAMILY;
400
- ptr += copy_to_mem(&family, ptr, sizeof(family));
400
+ ptr += copy_to_mem(family, ptr);
401
401
  const uint8_t type = SKETCH_TYPE;
402
- ptr += copy_to_mem(&type, ptr, sizeof(type));
403
- const uint8_t unused8 = 0;
404
- ptr += copy_to_mem(&unused8, ptr, sizeof(unused8));
402
+ ptr += copy_to_mem(type, ptr);
403
+ ptr += sizeof(uint8_t); // unused
405
404
  const uint8_t flags_byte(
406
405
  (1 << flags::IS_COMPACT) |
407
406
  (1 << flags::IS_READ_ONLY) |
408
407
  (this->is_empty() ? 1 << flags::IS_EMPTY : 0) |
409
408
  (this->is_ordered() ? 1 << flags::IS_ORDERED : 0)
410
409
  );
411
- ptr += copy_to_mem(&flags_byte, ptr, sizeof(flags_byte));
410
+ ptr += copy_to_mem(flags_byte, ptr);
412
411
  const uint16_t seed_hash = get_seed_hash();
413
- ptr += copy_to_mem(&seed_hash, ptr, sizeof(seed_hash));
412
+ ptr += copy_to_mem(seed_hash, ptr);
414
413
  if (!this->is_empty()) {
415
414
  if (!is_single_item) {
416
- const uint32_t num_entries = entries_.size();
417
- ptr += copy_to_mem(&num_entries, ptr, sizeof(num_entries));
418
- const uint32_t unused32 = 0;
419
- ptr += copy_to_mem(&unused32, ptr, sizeof(unused32));
415
+ const uint32_t num_entries = static_cast<uint32_t>(entries_.size());
416
+ ptr += copy_to_mem(num_entries, ptr);
417
+ ptr += sizeof(uint32_t); // unused
420
418
  if (this->is_estimation_mode()) {
421
- ptr += copy_to_mem(&theta_, ptr, sizeof(uint64_t));
419
+ ptr += copy_to_mem(theta_, ptr);
422
420
  }
423
421
  }
424
422
  for (const auto& it: entries_) {
425
- ptr += copy_to_mem(&it.first, ptr, sizeof(uint64_t));
423
+ ptr += copy_to_mem(it.first, ptr);
426
424
  ptr += sd.serialize(ptr, end_ptr - ptr, &it.second, 1);
427
425
  }
428
426
  }
@@ -432,20 +430,13 @@ auto compact_tuple_sketch<S, A>::serialize(unsigned header_size_bytes, const Ser
432
430
  template<typename S, typename A>
433
431
  template<typename SerDe>
434
432
  compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(std::istream& is, uint64_t seed, const SerDe& sd, const A& allocator) {
435
- uint8_t preamble_longs;
436
- is.read(reinterpret_cast<char*>(&preamble_longs), sizeof(preamble_longs));
437
- uint8_t serial_version;
438
- is.read(reinterpret_cast<char*>(&serial_version), sizeof(serial_version));
439
- uint8_t family;
440
- is.read(reinterpret_cast<char*>(&family), sizeof(family));
441
- uint8_t type;
442
- is.read(reinterpret_cast<char*>(&type), sizeof(type));
443
- uint8_t unused8;
444
- is.read(reinterpret_cast<char*>(&unused8), sizeof(unused8));
445
- uint8_t flags_byte;
446
- is.read(reinterpret_cast<char*>(&flags_byte), sizeof(flags_byte));
447
- uint16_t seed_hash;
448
- is.read(reinterpret_cast<char*>(&seed_hash), sizeof(seed_hash));
433
+ const auto preamble_longs = read<uint8_t>(is);
434
+ const auto serial_version = read<uint8_t>(is);
435
+ const auto family = read<uint8_t>(is);
436
+ const auto type = read<uint8_t>(is);
437
+ read<uint8_t>(is); // unused
438
+ const auto flags_byte = read<uint8_t>(is);
439
+ const auto seed_hash = read<uint16_t>(is);
449
440
  checker<true>::check_serial_version(serial_version, SERIAL_VERSION);
450
441
  checker<true>::check_sketch_family(family, SKETCH_FAMILY);
451
442
  checker<true>::check_sketch_type(type, SKETCH_TYPE);
@@ -458,11 +449,10 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(std::istream&
458
449
  if (preamble_longs == 1) {
459
450
  num_entries = 1;
460
451
  } else {
461
- is.read(reinterpret_cast<char*>(&num_entries), sizeof(num_entries));
462
- uint32_t unused32;
463
- is.read(reinterpret_cast<char*>(&unused32), sizeof(unused32));
452
+ num_entries = read<uint32_t>(is);
453
+ read<uint32_t>(is); // unused
464
454
  if (preamble_longs > 2) {
465
- is.read(reinterpret_cast<char*>(&theta), sizeof(theta));
455
+ theta = read<uint64_t>(is);
466
456
  }
467
457
  }
468
458
  }
@@ -470,10 +460,9 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(std::istream&
470
460
  std::vector<Entry, AllocEntry> entries(alloc);
471
461
  if (!is_empty) {
472
462
  entries.reserve(num_entries);
473
- std::unique_ptr<S, deleter_of_summaries> summary(alloc.allocate(1), deleter_of_summaries(1, false));
463
+ std::unique_ptr<S, deleter_of_summaries> summary(alloc.allocate(1), deleter_of_summaries(1, false, allocator));
474
464
  for (size_t i = 0; i < num_entries; ++i) {
475
- uint64_t key;
476
- is.read(reinterpret_cast<char*>(&key), sizeof(uint64_t));
465
+ const auto key = read<uint64_t>(is);
477
466
  sd.deserialize(is, summary.get(), 1);
478
467
  entries.push_back(Entry(key, std::move(*summary)));
479
468
  (*summary).~S();
@@ -491,19 +480,18 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(const void* b
491
480
  const char* ptr = static_cast<const char*>(bytes);
492
481
  const char* base = ptr;
493
482
  uint8_t preamble_longs;
494
- ptr += copy_from_mem(ptr, &preamble_longs, sizeof(preamble_longs));
483
+ ptr += copy_from_mem(ptr, preamble_longs);
495
484
  uint8_t serial_version;
496
- ptr += copy_from_mem(ptr, &serial_version, sizeof(serial_version));
485
+ ptr += copy_from_mem(ptr, serial_version);
497
486
  uint8_t family;
498
- ptr += copy_from_mem(ptr, &family, sizeof(family));
487
+ ptr += copy_from_mem(ptr, family);
499
488
  uint8_t type;
500
- ptr += copy_from_mem(ptr, &type, sizeof(type));
501
- uint8_t unused8;
502
- ptr += copy_from_mem(ptr, &unused8, sizeof(unused8));
489
+ ptr += copy_from_mem(ptr, type);
490
+ ptr += sizeof(uint8_t); // unused
503
491
  uint8_t flags_byte;
504
- ptr += copy_from_mem(ptr, &flags_byte, sizeof(flags_byte));
492
+ ptr += copy_from_mem(ptr, flags_byte);
505
493
  uint16_t seed_hash;
506
- ptr += copy_from_mem(ptr, &seed_hash, sizeof(seed_hash));
494
+ ptr += copy_from_mem(ptr, seed_hash);
507
495
  checker<true>::check_serial_version(serial_version, SERIAL_VERSION);
508
496
  checker<true>::check_sketch_family(family, SKETCH_FAMILY);
509
497
  checker<true>::check_sketch_type(type, SKETCH_TYPE);
@@ -518,12 +506,11 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(const void* b
518
506
  num_entries = 1;
519
507
  } else {
520
508
  ensure_minimum_memory(size, 8); // read the first prelong before this method
521
- ptr += copy_from_mem(ptr, &num_entries, sizeof(num_entries));
522
- uint32_t unused32;
523
- ptr += copy_from_mem(ptr, &unused32, sizeof(unused32));
509
+ ptr += copy_from_mem(ptr, num_entries);
510
+ ptr += sizeof(uint32_t); // unused
524
511
  if (preamble_longs > 2) {
525
512
  ensure_minimum_memory(size, (preamble_longs - 1) << 3);
526
- ptr += copy_from_mem(ptr, &theta, sizeof(theta));
513
+ ptr += copy_from_mem(ptr, theta);
527
514
  }
528
515
  }
529
516
  }
@@ -533,10 +520,10 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(const void* b
533
520
  std::vector<Entry, AllocEntry> entries(alloc);
534
521
  if (!is_empty) {
535
522
  entries.reserve(num_entries);
536
- std::unique_ptr<S, deleter_of_summaries> summary(alloc.allocate(1), deleter_of_summaries(1, false));
523
+ std::unique_ptr<S, deleter_of_summaries> summary(alloc.allocate(1), deleter_of_summaries(1, false, allocator));
537
524
  for (size_t i = 0; i < num_entries; ++i) {
538
525
  uint64_t key;
539
- ptr += copy_from_mem(ptr, &key, sizeof(key));
526
+ ptr += copy_from_mem(ptr, key);
540
527
  ptr += sd.deserialize(ptr, base + size - ptr, summary.get(), 1);
541
528
  entries.push_back(Entry(key, std::move(*summary)));
542
529
  (*summary).~S();
@@ -548,26 +535,26 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(const void* b
548
535
 
549
536
  template<typename S, typename A>
550
537
  auto compact_tuple_sketch<S, A>::begin() -> iterator {
551
- return iterator(entries_.data(), entries_.size(), 0);
538
+ return iterator(entries_.data(), static_cast<uint32_t>(entries_.size()), 0);
552
539
  }
553
540
 
554
541
  template<typename S, typename A>
555
542
  auto compact_tuple_sketch<S, A>::end() -> iterator {
556
- return iterator(nullptr, 0, entries_.size());
543
+ return iterator(nullptr, 0, static_cast<uint32_t>(entries_.size()));
557
544
  }
558
545
 
559
546
  template<typename S, typename A>
560
547
  auto compact_tuple_sketch<S, A>::begin() const -> const_iterator {
561
- return const_iterator(entries_.data(), entries_.size(), 0);
548
+ return const_iterator(entries_.data(), static_cast<uint32_t>(entries_.size()), 0);
562
549
  }
563
550
 
564
551
  template<typename S, typename A>
565
552
  auto compact_tuple_sketch<S, A>::end() const -> const_iterator {
566
- return const_iterator(nullptr, 0, entries_.size());
553
+ return const_iterator(nullptr, 0, static_cast<uint32_t>(entries_.size()));
567
554
  }
568
555
 
569
556
  template<typename S, typename A>
570
- void compact_tuple_sketch<S, A>::print_specifics(std::basic_ostream<char>&) const {}
557
+ void compact_tuple_sketch<S, A>::print_specifics(ostrstream&) const {}
571
558
 
572
559
  // builder
573
560
 
@@ -43,11 +43,6 @@ target_sources(tuple_test
43
43
  tuple_union_test.cpp
44
44
  tuple_intersection_test.cpp
45
45
  tuple_a_not_b_test.cpp
46
- array_of_doubles_sketch_test.cpp
47
- theta_sketch_experimental_test.cpp
48
- theta_union_experimental_test.cpp
49
- theta_intersection_experimental_test.cpp
50
- theta_a_not_b_experimental_test.cpp
51
- theta_jaccard_similarity_test.cpp
52
46
  tuple_jaccard_similarity_test.cpp
47
+ array_of_doubles_sketch_test.cpp
53
48
  )
@@ -75,7 +75,7 @@ TEST_CASE("aod sketch: serialization compatibility with java - empty configured
75
75
  }
76
76
 
77
77
  TEST_CASE("aod sketch: serialization compatibility with java - non-empty no entries", "[tuple_sketch]") {
78
- auto update_sketch = update_array_of_doubles_sketch::builder().set_p(0.01).build();
78
+ auto update_sketch = update_array_of_doubles_sketch::builder().set_p(0.01f).build();
79
79
  std::vector<double> a = {1};
80
80
  update_sketch.update(1, a);
81
81
  REQUIRE_FALSE(update_sketch.is_empty());