datasketches 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/ext/datasketches/cpc_wrapper.cpp +12 -13
  4. data/ext/datasketches/ext.cpp +1 -1
  5. data/ext/datasketches/ext.h +4 -0
  6. data/ext/datasketches/extconf.rb +1 -1
  7. data/ext/datasketches/fi_wrapper.cpp +6 -8
  8. data/ext/datasketches/hll_wrapper.cpp +13 -14
  9. data/ext/datasketches/kll_wrapper.cpp +28 -76
  10. data/ext/datasketches/theta_wrapper.cpp +27 -41
  11. data/ext/datasketches/vo_wrapper.cpp +4 -6
  12. data/lib/datasketches/version.rb +1 -1
  13. data/vendor/datasketches-cpp/CMakeLists.txt +1 -0
  14. data/vendor/datasketches-cpp/README.md +4 -4
  15. data/vendor/datasketches-cpp/common/include/MurmurHash3.h +7 -0
  16. data/vendor/datasketches-cpp/common/include/memory_operations.hpp +12 -0
  17. data/vendor/datasketches-cpp/common/test/CMakeLists.txt +24 -0
  18. data/vendor/datasketches-cpp/common/test/integration_test.cpp +77 -0
  19. data/vendor/datasketches-cpp/common/test/test_allocator.hpp +9 -1
  20. data/vendor/datasketches-cpp/cpc/include/cpc_common.hpp +3 -0
  21. data/vendor/datasketches-cpp/cpc/include/cpc_compressor.hpp +2 -2
  22. data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +28 -19
  23. data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +8 -5
  24. data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +19 -14
  25. data/vendor/datasketches-cpp/cpc/include/cpc_union.hpp +2 -2
  26. data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +6 -6
  27. data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +0 -6
  28. data/vendor/datasketches-cpp/cpc/include/icon_estimator.hpp +3 -3
  29. data/vendor/datasketches-cpp/cpc/include/u32_table.hpp +3 -3
  30. data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +9 -9
  31. data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +1 -0
  32. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_allocation_test.cpp +237 -0
  33. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +15 -10
  34. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +40 -28
  35. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +19 -13
  36. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map_impl.hpp +140 -124
  37. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_custom_type_test.cpp +15 -12
  38. data/vendor/datasketches-cpp/fi/test/reverse_purge_hash_map_test.cpp +3 -3
  39. data/vendor/datasketches-cpp/hll/CMakeLists.txt +3 -0
  40. data/vendor/datasketches-cpp/hll/include/AuxHashMap-internal.hpp +32 -57
  41. data/vendor/datasketches-cpp/hll/include/AuxHashMap.hpp +9 -8
  42. data/vendor/datasketches-cpp/hll/include/CompositeInterpolationXTable.hpp +2 -2
  43. data/vendor/datasketches-cpp/hll/include/CouponHashSet-internal.hpp +34 -48
  44. data/vendor/datasketches-cpp/hll/include/CouponHashSet.hpp +10 -10
  45. data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +45 -77
  46. data/vendor/datasketches-cpp/hll/include/CouponList.hpp +11 -12
  47. data/vendor/datasketches-cpp/hll/include/CubicInterpolation.hpp +2 -2
  48. data/vendor/datasketches-cpp/hll/include/HarmonicNumbers.hpp +2 -2
  49. data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +15 -14
  50. data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +1 -1
  51. data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +10 -21
  52. data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +2 -3
  53. data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +10 -21
  54. data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +2 -3
  55. data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +28 -55
  56. data/vendor/datasketches-cpp/hll/include/HllArray.hpp +8 -8
  57. data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +9 -11
  58. data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +2 -1
  59. data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +34 -31
  60. data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +3 -28
  61. data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +1 -1
  62. data/vendor/datasketches-cpp/hll/include/RelativeErrorTables.hpp +1 -1
  63. data/vendor/datasketches-cpp/hll/include/hll.hpp +6 -34
  64. data/vendor/datasketches-cpp/hll/test/AuxHashMapTest.cpp +7 -7
  65. data/vendor/datasketches-cpp/hll/test/CouponHashSetTest.cpp +2 -2
  66. data/vendor/datasketches-cpp/hll/test/CouponListTest.cpp +3 -3
  67. data/vendor/datasketches-cpp/hll/test/HllArrayTest.cpp +2 -2
  68. data/vendor/datasketches-cpp/hll/test/HllSketchTest.cpp +46 -50
  69. data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator.hpp +1 -1
  70. data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator_impl.hpp +3 -3
  71. data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +10 -3
  72. data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +93 -75
  73. data/vendor/datasketches-cpp/kll/test/kll_sketch_custom_type_test.cpp +11 -10
  74. data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +45 -42
  75. data/vendor/datasketches-cpp/python/CMakeLists.txt +2 -0
  76. data/vendor/datasketches-cpp/python/README.md +6 -3
  77. data/vendor/datasketches-cpp/python/src/datasketches.cpp +2 -0
  78. data/vendor/datasketches-cpp/python/src/hll_wrapper.cpp +0 -2
  79. data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +3 -1
  80. data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +246 -0
  81. data/vendor/datasketches-cpp/python/src/theta_wrapper.cpp +36 -26
  82. data/vendor/datasketches-cpp/python/tests/hll_test.py +0 -1
  83. data/vendor/datasketches-cpp/python/tests/kll_test.py +3 -3
  84. data/vendor/datasketches-cpp/python/tests/req_test.py +126 -0
  85. data/vendor/datasketches-cpp/python/tests/theta_test.py +28 -3
  86. data/vendor/datasketches-cpp/req/CMakeLists.txt +60 -0
  87. data/vendor/datasketches-cpp/{tuple/include/theta_a_not_b_experimental_impl.hpp → req/include/req_common.hpp} +17 -8
  88. data/vendor/datasketches-cpp/req/include/req_compactor.hpp +137 -0
  89. data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +501 -0
  90. data/vendor/datasketches-cpp/req/include/req_quantile_calculator.hpp +69 -0
  91. data/vendor/datasketches-cpp/req/include/req_quantile_calculator_impl.hpp +60 -0
  92. data/vendor/datasketches-cpp/req/include/req_sketch.hpp +395 -0
  93. data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +810 -0
  94. data/vendor/datasketches-cpp/req/test/CMakeLists.txt +43 -0
  95. data/vendor/datasketches-cpp/req/test/req_float_empty_from_java.sk +0 -0
  96. data/vendor/datasketches-cpp/req/test/req_float_estimation_from_java.sk +0 -0
  97. data/vendor/datasketches-cpp/req/test/req_float_exact_from_java.sk +0 -0
  98. data/vendor/datasketches-cpp/req/test/req_float_raw_items_from_java.sk +0 -0
  99. data/vendor/datasketches-cpp/req/test/req_float_single_item_from_java.sk +0 -0
  100. data/vendor/datasketches-cpp/req/test/req_sketch_custom_type_test.cpp +128 -0
  101. data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +494 -0
  102. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +10 -9
  103. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +82 -70
  104. data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +5 -5
  105. data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +7 -7
  106. data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +1 -0
  107. data/vendor/datasketches-cpp/sampling/test/var_opt_allocation_test.cpp +96 -0
  108. data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +0 -31
  109. data/vendor/datasketches-cpp/setup.py +5 -3
  110. data/vendor/datasketches-cpp/theta/CMakeLists.txt +30 -3
  111. data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_sampled_sets.hpp +2 -1
  112. data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_theta_sketched_sets.hpp +1 -1
  113. data/vendor/datasketches-cpp/theta/include/theta_a_not_b.hpp +12 -29
  114. data/vendor/datasketches-cpp/theta/include/theta_a_not_b_impl.hpp +5 -46
  115. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_comparators.hpp +0 -0
  116. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_constants.hpp +2 -0
  117. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_helpers.hpp +0 -0
  118. data/vendor/datasketches-cpp/theta/include/theta_intersection.hpp +22 -29
  119. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_intersection_base.hpp +0 -0
  120. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_intersection_base_impl.hpp +0 -0
  121. data/vendor/datasketches-cpp/theta/include/theta_intersection_impl.hpp +8 -90
  122. data/vendor/datasketches-cpp/{tuple/test/theta_union_experimental_test.cpp → theta/include/theta_jaccard_similarity.hpp} +11 -18
  123. data/vendor/datasketches-cpp/{tuple/include/jaccard_similarity.hpp → theta/include/theta_jaccard_similarity_base.hpp} +6 -22
  124. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_set_difference_base.hpp +0 -0
  125. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_set_difference_base_impl.hpp +5 -0
  126. data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +132 -266
  127. data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +200 -650
  128. data/vendor/datasketches-cpp/theta/include/theta_union.hpp +27 -60
  129. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_union_base.hpp +1 -1
  130. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_union_base_impl.hpp +5 -0
  131. data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +13 -69
  132. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base.hpp +3 -19
  133. data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base_impl.hpp +6 -1
  134. data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +1 -0
  135. data/vendor/datasketches-cpp/{tuple → theta}/test/theta_jaccard_similarity_test.cpp +2 -3
  136. data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +37 -234
  137. data/vendor/datasketches-cpp/tuple/CMakeLists.txt +3 -35
  138. data/vendor/datasketches-cpp/tuple/include/tuple_jaccard_similarity.hpp +38 -0
  139. data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +28 -13
  140. data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +6 -6
  141. data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +1 -6
  142. data/vendor/datasketches-cpp/tuple/test/tuple_a_not_b_test.cpp +1 -4
  143. data/vendor/datasketches-cpp/tuple/test/tuple_intersection_test.cpp +1 -4
  144. data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +2 -1
  145. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_allocation_test.cpp +2 -2
  146. data/vendor/datasketches-cpp/tuple/test/tuple_union_test.cpp +1 -4
  147. metadata +43 -34
  148. data/vendor/datasketches-cpp/tuple/include/theta_a_not_b_experimental.hpp +0 -53
  149. data/vendor/datasketches-cpp/tuple/include/theta_intersection_experimental.hpp +0 -78
  150. data/vendor/datasketches-cpp/tuple/include/theta_intersection_experimental_impl.hpp +0 -43
  151. data/vendor/datasketches-cpp/tuple/include/theta_sketch_experimental.hpp +0 -393
  152. data/vendor/datasketches-cpp/tuple/include/theta_sketch_experimental_impl.hpp +0 -481
  153. data/vendor/datasketches-cpp/tuple/include/theta_union_experimental.hpp +0 -88
  154. data/vendor/datasketches-cpp/tuple/include/theta_union_experimental_impl.hpp +0 -47
  155. data/vendor/datasketches-cpp/tuple/test/theta_a_not_b_experimental_test.cpp +0 -250
  156. data/vendor/datasketches-cpp/tuple/test/theta_compact_empty_from_java.sk +0 -0
  157. data/vendor/datasketches-cpp/tuple/test/theta_compact_estimation_from_java.sk +0 -0
  158. data/vendor/datasketches-cpp/tuple/test/theta_compact_single_item_from_java.sk +0 -0
  159. data/vendor/datasketches-cpp/tuple/test/theta_intersection_experimental_test.cpp +0 -224
  160. data/vendor/datasketches-cpp/tuple/test/theta_sketch_experimental_test.cpp +0 -247
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d74bd4504918fd8217f9cf7d8c24442b5c196b2d874a042f6a2f30a24ae51db
4
- data.tar.gz: 7521194ca0d05808b234c6cb1bb5150874c28f7e9536820f728b33b0aec8c52a
3
+ metadata.gz: e62d3e98b646fb074ae5bccf506a3ec9659bfde99d98721e2e3d7377ea68a3ce
4
+ data.tar.gz: ef7a1d11de9801e0d40d0071a46f695555a026a54c8e31d23624c01045faafe6
5
5
  SHA512:
6
- metadata.gz: db41c21f18a51bf285e32556c52e06453810448d1d75d11cd1022576a98d5069977d65fe6bab7e5bd6425468531414fdd801a1bde1bfdf82fc05f455d97b80fd
7
- data.tar.gz: 892e9f2c4b891194cfc1af8387494e78eb2e703b4a56f7c91e1b4784f0bd2439f35f8e25f92e954be44418d2964e804f892ab687df2acf8e9b64d43e0049cca0
6
+ metadata.gz: 8808ddf87374a66de48f0434f22b8813cd0170d40ce1dc518a480235f6bd359322fb1e354e224355911f5569a32dce99457515dfd6a8a591223ea6a1e834dfb8
7
+ data.tar.gz: 5fdeee4c5b69a495d90242e2a3e6157fbca0931bebeb77ba025840c15f14e571c9a672b527082324b2e72e17ae6e0d301b7978cf21be6ae77766cd1b4f18c3d0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.2.0 (2021-05-17)
2
+
3
+ - Updated DataSketches to 3.0.0
4
+ - Updated to Rice 4
5
+
1
6
  ## 0.1.2 (2021-01-21)
2
7
 
3
8
  - Added `CpcUnion` and `UpdateThetaSketch`
@@ -3,8 +3,7 @@
3
3
  #include <cpc_sketch.hpp>
4
4
  #include <cpc_union.hpp>
5
5
 
6
- #include <rice/Constructor.hpp>
7
- #include <rice/Module.hpp>
6
+ #include "ext.h"
8
7
 
9
8
  using datasketches::cpc_sketch;
10
9
  using datasketches::cpc_union;
@@ -16,30 +15,30 @@ using Rice::Arg;
16
15
 
17
16
  void init_cpc(Rice::Module& m) {
18
17
  Rice::define_class_under<cpc_sketch>(m, "CpcSketch")
19
- .define_constructor(Rice::Constructor<cpc_sketch, uint8_t, uint64_t>(), (Rice::Arg("lg_k")=CPC_DEFAULT_LG_K, Rice::Arg("seed")=DEFAULT_SEED))
18
+ .define_constructor(Rice::Constructor<cpc_sketch, uint8_t, uint64_t>(), Rice::Arg("lg_k")=CPC_DEFAULT_LG_K, Rice::Arg("seed")=DEFAULT_SEED)
20
19
  .define_method("lg_k", &cpc_sketch::get_lg_k)
21
20
  .define_method("empty?", &cpc_sketch::is_empty)
22
21
  .define_method("lower_bound", &cpc_sketch::get_lower_bound)
23
22
  .define_method("upper_bound", &cpc_sketch::get_upper_bound)
24
23
  .define_method(
25
24
  "update",
26
- *[](cpc_sketch& self, Rice::Object datum) {
25
+ [](cpc_sketch& self, Rice::Object datum) {
27
26
  if (FIXNUM_P(datum.value())) {
28
- return self.update(from_ruby<int64_t>(datum));
27
+ return self.update(Rice::detail::From_Ruby<int64_t>().convert(datum));
29
28
  } else if (datum.is_a(rb_cNumeric)) {
30
- return self.update(from_ruby<double>(datum));
29
+ return self.update(Rice::detail::From_Ruby<double>().convert(datum));
31
30
  } else {
32
31
  return self.update(datum.to_s().str());
33
32
  }
34
33
  })
35
34
  .define_method(
36
35
  "estimate",
37
- *[](cpc_sketch& self) {
36
+ [](cpc_sketch& self) {
38
37
  return self.get_estimate();
39
38
  })
40
39
  .define_method(
41
40
  "serialize",
42
- *[](cpc_sketch& self) {
41
+ [](cpc_sketch& self) {
43
42
  std::ostringstream oss;
44
43
  self.serialize(oss);
45
44
  return oss.str();
@@ -47,22 +46,22 @@ void init_cpc(Rice::Module& m) {
47
46
  // TODO change to summary?
48
47
  .define_method(
49
48
  "to_string",
50
- *[](cpc_sketch& self) {
49
+ [](cpc_sketch& self) {
51
50
  return self.to_string();
52
51
  })
53
- .define_singleton_method(
52
+ .define_singleton_function(
54
53
  "deserialize",
55
- *[](std::string& is) {
54
+ [](const std::string& is) {
56
55
  std::istringstream iss(is);
57
56
  return cpc_sketch::deserialize(iss);
58
57
  });
59
58
 
60
59
  Rice::define_class_under<cpc_union>(m, "CpcUnion")
61
- .define_constructor(Rice::Constructor<cpc_union, uint8_t, uint64_t>(), (Rice::Arg("lg_k"), Rice::Arg("seed")=DEFAULT_SEED))
60
+ .define_constructor(Rice::Constructor<cpc_union, uint8_t, uint64_t>(), Rice::Arg("lg_k"), Rice::Arg("seed")=DEFAULT_SEED)
62
61
  .define_method("result", &cpc_union::get_result)
63
62
  .define_method(
64
63
  "update",
65
- *[](cpc_union& self, cpc_sketch& sketch) {
64
+ [](cpc_union& self, cpc_sketch& sketch) {
66
65
  self.update(sketch);
67
66
  });
68
67
  }
@@ -1,4 +1,4 @@
1
- #include <rice/Module.hpp>
1
+ #include "ext.h"
2
2
 
3
3
  void init_cpc(Rice::Module& m);
4
4
  void init_fi(Rice::Module& m);
@@ -0,0 +1,4 @@
1
+ #pragma once
2
+
3
+ #include <rice/rice.hpp>
4
+ #include <rice/stl.hpp>
@@ -1,6 +1,6 @@
1
1
  require "mkmf-rice"
2
2
 
3
- $CXXFLAGS += " -std=c++11"
3
+ $CXXFLAGS += " -std=c++17"
4
4
 
5
5
  ext = File.expand_path(".", __dir__)
6
6
  datasketches = File.expand_path("../../vendor/datasketches-cpp", __dir__)
@@ -2,8 +2,7 @@
2
2
 
3
3
  #include <frequent_items_sketch.hpp>
4
4
 
5
- #include <rice/Constructor.hpp>
6
- #include <rice/Module.hpp>
5
+ #include "ext.h"
7
6
 
8
7
  template<typename T>
9
8
  void bind_fi_sketch(Rice::Module& m, const char* name) {
@@ -18,12 +17,12 @@ void bind_fi_sketch(Rice::Module& m, const char* name) {
18
17
  .define_method("maximum_error", &datasketches::frequent_items_sketch<T>::get_maximum_error)
19
18
  .define_method(
20
19
  "update",
21
- *[](datasketches::frequent_items_sketch<T>& self, const T item) {
20
+ [](datasketches::frequent_items_sketch<T>& self, const T item) {
22
21
  self.update(item);
23
22
  })
24
23
  .define_method(
25
24
  "serialize",
26
- *[](datasketches::frequent_items_sketch<T>& self) {
25
+ [](datasketches::frequent_items_sketch<T>& self) {
27
26
  std::ostringstream oss;
28
27
  self.serialize(oss);
29
28
  return oss.str();
@@ -31,13 +30,12 @@ void bind_fi_sketch(Rice::Module& m, const char* name) {
31
30
  // TODO change to summary?
32
31
  .define_method(
33
32
  "to_string",
34
- *[](datasketches::frequent_items_sketch<T>& self) {
33
+ [](datasketches::frequent_items_sketch<T>& self) {
35
34
  return self.to_string();
36
35
  })
37
- .define_singleton_method(
36
+ .define_singleton_function(
38
37
  "deserialize",
39
- // TODO figure out segfault
40
- *[](std::string is) {
38
+ [](const std::string& is) {
41
39
  std::istringstream iss(is);
42
40
  return datasketches::frequent_items_sketch<T>::deserialize(iss);
43
41
  });
@@ -2,8 +2,7 @@
2
2
 
3
3
  #include <hll.hpp>
4
4
 
5
- #include <rice/Constructor.hpp>
6
- #include <rice/Module.hpp>
5
+ #include "ext.h"
7
6
 
8
7
  using datasketches::hll_sketch;
9
8
  using datasketches::hll_union;
@@ -17,30 +16,30 @@ void init_hll(Rice::Module& m) {
17
16
  .define_method("composite_estimate", &hll_sketch::get_composite_estimate)
18
17
  .define_method(
19
18
  "update",
20
- *[](hll_sketch& self, Rice::Object datum) {
19
+ [](hll_sketch& self, Rice::Object datum) {
21
20
  if (FIXNUM_P(datum.value())) {
22
- return self.update(from_ruby<int64_t>(datum));
21
+ return self.update(Rice::detail::From_Ruby<int64_t>().convert(datum));
23
22
  } else if (datum.is_a(rb_cNumeric)) {
24
- return self.update(from_ruby<double>(datum));
23
+ return self.update(Rice::detail::From_Ruby<double>().convert(datum));
25
24
  } else {
26
25
  return self.update(datum.to_s().str());
27
26
  }
28
27
  })
29
28
  .define_method(
30
29
  "estimate",
31
- *[](hll_sketch& self) {
30
+ [](hll_sketch& self) {
32
31
  return self.get_estimate();
33
32
  })
34
33
  .define_method(
35
34
  "serialize_compact",
36
- *[](hll_sketch& self) {
35
+ [](hll_sketch& self) {
37
36
  std::ostringstream oss;
38
37
  self.serialize_compact(oss);
39
38
  return oss.str();
40
39
  })
41
40
  .define_method(
42
41
  "serialize_updatable",
43
- *[](hll_sketch& self) {
42
+ [](hll_sketch& self) {
44
43
  std::ostringstream oss;
45
44
  self.serialize_updatable(oss);
46
45
  return oss.str();
@@ -48,12 +47,12 @@ void init_hll(Rice::Module& m) {
48
47
  // TODO change to summary?
49
48
  .define_method(
50
49
  "to_string",
51
- *[](hll_sketch& self) {
50
+ [](hll_sketch& self) {
52
51
  return self.to_string();
53
52
  })
54
- .define_singleton_method(
53
+ .define_singleton_function(
55
54
  "deserialize",
56
- *[](std::string& is) {
55
+ [](const std::string& is) {
57
56
  std::istringstream iss(is);
58
57
  return hll_sketch::deserialize(iss);
59
58
  });
@@ -62,17 +61,17 @@ void init_hll(Rice::Module& m) {
62
61
  .define_constructor(Rice::Constructor<hll_union, int>())
63
62
  .define_method(
64
63
  "update",
65
- *[](hll_union& self, hll_sketch& sketch) {
64
+ [](hll_union& self, hll_sketch& sketch) {
66
65
  self.update(sketch);
67
66
  })
68
67
  .define_method(
69
68
  "estimate",
70
- *[](hll_union& self) {
69
+ [](hll_union& self) {
71
70
  return self.get_estimate();
72
71
  })
73
72
  .define_method(
74
73
  "result",
75
- *[](hll_union& self) {
74
+ [](hll_union& self) {
76
75
  return self.get_result();
77
76
  });
78
77
  }
@@ -2,79 +2,31 @@
2
2
 
3
3
  #include <kll_sketch.hpp>
4
4
 
5
- #include <rice/Array.hpp>
6
- #include <rice/Constructor.hpp>
7
- #include <rice/Module.hpp>
5
+ #include "ext.h"
8
6
 
9
7
  using datasketches::kll_sketch;
10
8
 
11
- template<>
12
- std::vector<int> from_ruby<std::vector<int>>(Rice::Object x)
9
+ namespace Rice::detail
13
10
  {
14
- auto a = Rice::Array(x);
15
- std::vector<int> vec(a.size());
16
- for (long i = 0; i < a.size(); i++) {
17
- vec[i] = from_ruby<int>(a[i]);
18
- }
19
- return vec;
20
- }
21
-
22
- template<>
23
- std::vector<float> from_ruby<std::vector<float>>(Rice::Object x)
24
- {
25
- auto a = Rice::Array(x);
26
- std::vector<float> vec(a.size());
27
- for (long i = 0; i < a.size(); i++) {
28
- vec[i] = from_ruby<float>(a[i]);
29
- }
30
- return vec;
31
- }
32
-
33
- template<>
34
- std::vector<double> from_ruby<std::vector<double>>(Rice::Object x)
35
- {
36
- auto a = Rice::Array(x);
37
- std::vector<double> vec(a.size());
38
- for (long i = 0; i < a.size(); i++) {
39
- vec[i] = from_ruby<double>(a[i]);
40
- }
41
- return vec;
42
- }
43
-
44
- template<>
45
- Rice::Object to_ruby<std::vector<int>>(std::vector<int> const & x)
46
- {
47
- auto a = Rice::Array();
48
- for (size_t i = 0; i < x.size(); i++) {
49
- a.push(x[i]);
50
- }
51
- return a;
52
- }
53
-
54
- template<>
55
- Rice::Object to_ruby<std::vector<float>>(std::vector<float> const & x)
56
- {
57
- auto a = Rice::Array();
58
- for (size_t i = 0; i < x.size(); i++) {
59
- a.push(x[i]);
60
- }
61
- return a;
62
- }
63
-
64
- template<>
65
- Rice::Object to_ruby<std::vector<double>>(std::vector<double> const & x)
66
- {
67
- auto a = Rice::Array();
68
- for (size_t i = 0; i < x.size(); i++) {
69
- a.push(x[i]);
70
- }
71
- return a;
11
+ template<typename T>
12
+ class To_Ruby<std::vector<T>>
13
+ {
14
+ public:
15
+ VALUE convert(std::vector<T> const & x)
16
+ {
17
+ auto a = rb_ary_new2(x.size());
18
+ for (const auto& v : x) {
19
+ detail::protect(rb_ary_push, a, To_Ruby<T>().convert(v));
20
+ }
21
+ return a;
22
+ }
23
+ };
72
24
  }
73
25
 
74
26
  template<typename T>
75
27
  void bind_kll_sketch(Rice::Module& m, const char* name) {
76
28
  Rice::define_class_under<kll_sketch<T>>(m, name)
77
- .define_constructor(Rice::Constructor<kll_sketch<T>, uint16_t>(), (Rice::Arg("k")=kll_sketch<T>::DEFAULT_K))
29
+ .define_constructor(Rice::Constructor<kll_sketch<T>, uint16_t>(), Rice::Arg("k")=kll_sketch<T>::DEFAULT_K)
78
30
  .define_method("empty?", &kll_sketch<T>::is_empty)
79
31
  .define_method("n", &kll_sketch<T>::get_n)
80
32
  .define_method("num_retained", &kll_sketch<T>::get_num_retained)
@@ -84,42 +36,42 @@ void bind_kll_sketch(Rice::Module& m, const char* name) {
84
36
  .define_method("quantile", &kll_sketch<T>::get_quantile)
85
37
  .define_method(
86
38
  "quantiles",
87
- *[](kll_sketch<T>& self, Rice::Object obj) {
39
+ [](kll_sketch<T>& self, Rice::Object obj) {
88
40
  if (obj.is_a(rb_cArray)) {
89
- auto fractions = from_ruby<std::vector<double>>(obj);
41
+ auto fractions = Rice::detail::From_Ruby<std::vector<double>>().convert(obj);
90
42
  return self.get_quantiles(&fractions[0], fractions.size());
91
43
  } else {
92
- return self.get_quantiles(from_ruby<size_t>(obj));
44
+ return self.get_quantiles(Rice::detail::From_Ruby<size_t>().convert(obj));
93
45
  }
94
46
  })
95
47
  .define_method(
96
48
  "rank",
97
- *[](kll_sketch<T>& self, const T item) {
49
+ [](kll_sketch<T>& self, const T item) {
98
50
  return self.get_rank(item);
99
51
  })
100
52
  .define_method(
101
53
  "pmf",
102
- *[](kll_sketch<T>& self, std::vector<T> split_points) {
54
+ [](kll_sketch<T>& self, std::vector<T> split_points) {
103
55
  return self.get_PMF(&split_points[0], split_points.size());
104
56
  })
105
57
  .define_method(
106
58
  "cdf",
107
- *[](kll_sketch<T>& self, std::vector<T> split_points) {
59
+ [](kll_sketch<T>& self, std::vector<T> split_points) {
108
60
  return self.get_CDF(&split_points[0], split_points.size());
109
61
  })
110
62
  .define_method(
111
63
  "merge",
112
- *[](kll_sketch<T>& self, const kll_sketch<T>& other) {
64
+ [](kll_sketch<T>& self, const kll_sketch<T>& other) {
113
65
  self.merge(other);
114
66
  })
115
67
  .define_method(
116
68
  "update",
117
- *[](kll_sketch<T>& self, const T item) {
69
+ [](kll_sketch<T>& self, const T item) {
118
70
  self.update(item);
119
71
  })
120
72
  .define_method(
121
73
  "serialize",
122
- *[](kll_sketch<T>& self) {
74
+ [](kll_sketch<T>& self) {
123
75
  std::ostringstream oss;
124
76
  self.serialize(oss);
125
77
  return oss.str();
@@ -127,12 +79,12 @@ void bind_kll_sketch(Rice::Module& m, const char* name) {
127
79
  // TODO change to summary?
128
80
  .define_method(
129
81
  "to_string",
130
- *[](kll_sketch<T>& self) {
82
+ [](kll_sketch<T>& self) {
131
83
  return self.to_string();
132
84
  })
133
- .define_singleton_method(
85
+ .define_singleton_function(
134
86
  "deserialize",
135
- *[](std::string& is) {
87
+ [](const std::string& is) {
136
88
  std::istringstream iss(is);
137
89
  return kll_sketch<T>::deserialize(iss);
138
90
  });
@@ -5,8 +5,7 @@
5
5
  #include <theta_intersection.hpp>
6
6
  #include <theta_a_not_b.hpp>
7
7
 
8
- #include <rice/Constructor.hpp>
9
- #include <rice/Module.hpp>
8
+ #include "ext.h"
10
9
 
11
10
  using datasketches::theta_sketch;
12
11
  using datasketches::update_theta_sketch;
@@ -24,79 +23,66 @@ void init_theta(Rice::Module& m) {
24
23
  .define_method("empty?", &theta_sketch::is_empty)
25
24
  .define_method("estimate", &theta_sketch::get_estimate)
26
25
  .define_method("lower_bound", &theta_sketch::get_lower_bound)
27
- .define_method("upper_bound", &theta_sketch::get_upper_bound)
28
- .define_method(
29
- "serialize",
30
- *[](theta_sketch& self) {
31
- std::ostringstream oss;
32
- self.serialize(oss);
33
- return oss.str();
26
+ .define_method("upper_bound", &theta_sketch::get_upper_bound);
27
+
28
+ Rice::define_class_under<compact_theta_sketch, theta_sketch>(m, "CompactThetaSketch")
29
+ .define_singleton_function(
30
+ "deserialize",
31
+ [](const std::string& is) {
32
+ std::istringstream iss(is);
33
+ return compact_theta_sketch::deserialize(iss);
34
34
  });
35
35
 
36
36
  Rice::define_class_under<update_theta_sketch, theta_sketch>(m, "UpdateThetaSketch")
37
- .define_singleton_method(
37
+ .define_singleton_function(
38
38
  "new",
39
- *[](uint8_t lg_k, double p, uint64_t seed) {
39
+ [](uint8_t lg_k, double p, uint64_t seed) {
40
40
  update_theta_sketch::builder builder;
41
41
  builder.set_lg_k(lg_k);
42
42
  builder.set_p(p);
43
43
  builder.set_seed(seed);
44
44
  return builder.build();
45
45
  },
46
- (Arg("lg_k")=update_theta_sketch::builder::DEFAULT_LG_K, Arg("p")=1.0, Arg("seed")=DEFAULT_SEED))
47
- .define_method("compact", &update_theta_sketch::compact, (Arg("ordered")=true))
46
+ Arg("lg_k")=update_theta_sketch::builder::DEFAULT_LG_K, Arg("p")=1.0, Arg("seed")=DEFAULT_SEED)
47
+ .define_method("compact", &update_theta_sketch::compact, Arg("ordered")=true)
48
48
  .define_method(
49
49
  "update",
50
- *[](update_theta_sketch& self, Rice::Object datum) {
50
+ [](update_theta_sketch& self, Rice::Object datum) {
51
51
  if (FIXNUM_P(datum.value())) {
52
- return self.update(from_ruby<int64_t>(datum));
52
+ return self.update(Rice::detail::From_Ruby<int64_t>().convert(datum));
53
53
  } else if (datum.is_a(rb_cNumeric)) {
54
- return self.update(from_ruby<double>(datum));
54
+ return self.update(Rice::detail::From_Ruby<double>().convert(datum));
55
55
  } else {
56
56
  return self.update(datum.to_s().str());
57
57
  }
58
58
  })
59
59
  .define_method(
60
60
  "estimate",
61
- *[](update_theta_sketch& self) {
61
+ [](update_theta_sketch& self) {
62
62
  return self.get_estimate();
63
- })
64
- .define_singleton_method(
65
- "deserialize",
66
- *[](std::string& is) {
67
- std::istringstream iss(is);
68
- return update_theta_sketch::deserialize(iss);
69
- });
70
-
71
- Rice::define_class_under<compact_theta_sketch, theta_sketch>(m, "CompactThetaSketch")
72
- .define_singleton_method(
73
- "deserialize",
74
- *[](std::string& is) {
75
- std::istringstream iss(is);
76
- return compact_theta_sketch::deserialize(iss);
77
63
  });
78
64
 
79
65
  Rice::define_class_under<theta_union>(m, "ThetaUnion")
80
- .define_singleton_method(
66
+ .define_singleton_function(
81
67
  "new",
82
- *[](uint8_t lg_k, double p, uint64_t seed) {
68
+ [](uint8_t lg_k, double p, uint64_t seed) {
83
69
  theta_union::builder builder;
84
70
  builder.set_lg_k(lg_k);
85
71
  builder.set_p(p);
86
72
  builder.set_seed(seed);
87
73
  return builder.build();
88
74
  },
89
- (Arg("lg_k")=update_theta_sketch::builder::DEFAULT_LG_K, Arg("p")=1.0, Arg("seed")=DEFAULT_SEED))
90
- .define_method("update", &theta_union::update)
91
- .define_method("result", &theta_union::get_result, (Arg("ordered")=true));
75
+ Arg("lg_k")=update_theta_sketch::builder::DEFAULT_LG_K, Arg("p")=1.0, Arg("seed")=DEFAULT_SEED)
76
+ .define_method("update", &theta_union::update<const theta_sketch&>)
77
+ .define_method("result", &theta_union::get_result, Arg("ordered")=true);
92
78
 
93
79
  Rice::define_class_under<theta_intersection>(m, "ThetaIntersection")
94
- .define_constructor(Rice::Constructor<theta_intersection, uint64_t>(), (Arg("seed")=DEFAULT_SEED))
95
- .define_method("update", &theta_intersection::update)
96
- .define_method("result", &theta_intersection::get_result, (Arg("ordered")=true))
80
+ .define_constructor(Rice::Constructor<theta_intersection, uint64_t>(), Arg("seed")=DEFAULT_SEED)
81
+ .define_method("update", &theta_intersection::update<const theta_sketch&>)
82
+ .define_method("result", &theta_intersection::get_result, Arg("ordered")=true)
97
83
  .define_method("result?", &theta_intersection::has_result);
98
84
 
99
85
  Rice::define_class_under<theta_a_not_b>(m, "ThetaANotB")
100
- .define_constructor(Rice::Constructor<theta_a_not_b, uint64_t>(), (Arg("seed")=DEFAULT_SEED))
101
- .define_method("compute", &theta_a_not_b::compute, (Arg("a"), Arg("b"), Arg("ordered")=true));
86
+ .define_constructor(Rice::Constructor<theta_a_not_b, uint64_t>(), Arg("seed")=DEFAULT_SEED)
87
+ .define_method("compute", &theta_a_not_b::compute<const theta_sketch&, const theta_sketch&>, Arg("a"), Arg("b"), Arg("ordered")=true);
102
88
  }