datasketches 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/ext/datasketches/cpc_wrapper.cpp +12 -13
- data/ext/datasketches/ext.cpp +1 -1
- data/ext/datasketches/ext.h +4 -0
- data/ext/datasketches/extconf.rb +1 -1
- data/ext/datasketches/fi_wrapper.cpp +6 -8
- data/ext/datasketches/hll_wrapper.cpp +13 -14
- data/ext/datasketches/kll_wrapper.cpp +28 -76
- data/ext/datasketches/theta_wrapper.cpp +27 -41
- data/ext/datasketches/vo_wrapper.cpp +4 -6
- data/lib/datasketches/version.rb +1 -1
- data/vendor/datasketches-cpp/CMakeLists.txt +1 -0
- data/vendor/datasketches-cpp/README.md +4 -4
- data/vendor/datasketches-cpp/common/include/MurmurHash3.h +7 -0
- data/vendor/datasketches-cpp/common/include/memory_operations.hpp +12 -0
- data/vendor/datasketches-cpp/common/test/CMakeLists.txt +24 -0
- data/vendor/datasketches-cpp/common/test/integration_test.cpp +77 -0
- data/vendor/datasketches-cpp/common/test/test_allocator.hpp +9 -1
- data/vendor/datasketches-cpp/cpc/include/cpc_common.hpp +3 -0
- data/vendor/datasketches-cpp/cpc/include/cpc_compressor.hpp +2 -2
- data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +28 -19
- data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +8 -5
- data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +19 -14
- data/vendor/datasketches-cpp/cpc/include/cpc_union.hpp +2 -2
- data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +6 -6
- data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +0 -6
- data/vendor/datasketches-cpp/cpc/include/icon_estimator.hpp +3 -3
- data/vendor/datasketches-cpp/cpc/include/u32_table.hpp +3 -3
- data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +9 -9
- data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +1 -0
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_allocation_test.cpp +237 -0
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +15 -10
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +40 -28
- data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +19 -13
- data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map_impl.hpp +140 -124
- data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_custom_type_test.cpp +15 -12
- data/vendor/datasketches-cpp/fi/test/reverse_purge_hash_map_test.cpp +3 -3
- data/vendor/datasketches-cpp/hll/CMakeLists.txt +3 -0
- data/vendor/datasketches-cpp/hll/include/AuxHashMap-internal.hpp +32 -57
- data/vendor/datasketches-cpp/hll/include/AuxHashMap.hpp +9 -8
- data/vendor/datasketches-cpp/hll/include/CompositeInterpolationXTable.hpp +2 -2
- data/vendor/datasketches-cpp/hll/include/CouponHashSet-internal.hpp +34 -48
- data/vendor/datasketches-cpp/hll/include/CouponHashSet.hpp +10 -10
- data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +45 -77
- data/vendor/datasketches-cpp/hll/include/CouponList.hpp +11 -12
- data/vendor/datasketches-cpp/hll/include/CubicInterpolation.hpp +2 -2
- data/vendor/datasketches-cpp/hll/include/HarmonicNumbers.hpp +2 -2
- data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +15 -14
- data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +1 -1
- data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +10 -21
- data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +2 -3
- data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +10 -21
- data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +2 -3
- data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +28 -55
- data/vendor/datasketches-cpp/hll/include/HllArray.hpp +8 -8
- data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +9 -11
- data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +2 -1
- data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +34 -31
- data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +3 -28
- data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +1 -1
- data/vendor/datasketches-cpp/hll/include/RelativeErrorTables.hpp +1 -1
- data/vendor/datasketches-cpp/hll/include/hll.hpp +6 -34
- data/vendor/datasketches-cpp/hll/test/AuxHashMapTest.cpp +7 -7
- data/vendor/datasketches-cpp/hll/test/CouponHashSetTest.cpp +2 -2
- data/vendor/datasketches-cpp/hll/test/CouponListTest.cpp +3 -3
- data/vendor/datasketches-cpp/hll/test/HllArrayTest.cpp +2 -2
- data/vendor/datasketches-cpp/hll/test/HllSketchTest.cpp +46 -50
- data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator.hpp +1 -1
- data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator_impl.hpp +3 -3
- data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +10 -3
- data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +93 -75
- data/vendor/datasketches-cpp/kll/test/kll_sketch_custom_type_test.cpp +11 -10
- data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +45 -42
- data/vendor/datasketches-cpp/python/CMakeLists.txt +2 -0
- data/vendor/datasketches-cpp/python/README.md +6 -3
- data/vendor/datasketches-cpp/python/src/datasketches.cpp +2 -0
- data/vendor/datasketches-cpp/python/src/hll_wrapper.cpp +0 -2
- data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +3 -1
- data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +246 -0
- data/vendor/datasketches-cpp/python/src/theta_wrapper.cpp +36 -26
- data/vendor/datasketches-cpp/python/tests/hll_test.py +0 -1
- data/vendor/datasketches-cpp/python/tests/kll_test.py +3 -3
- data/vendor/datasketches-cpp/python/tests/req_test.py +126 -0
- data/vendor/datasketches-cpp/python/tests/theta_test.py +28 -3
- data/vendor/datasketches-cpp/req/CMakeLists.txt +60 -0
- data/vendor/datasketches-cpp/{tuple/include/theta_a_not_b_experimental_impl.hpp → req/include/req_common.hpp} +17 -8
- data/vendor/datasketches-cpp/req/include/req_compactor.hpp +137 -0
- data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +501 -0
- data/vendor/datasketches-cpp/req/include/req_quantile_calculator.hpp +69 -0
- data/vendor/datasketches-cpp/req/include/req_quantile_calculator_impl.hpp +60 -0
- data/vendor/datasketches-cpp/req/include/req_sketch.hpp +395 -0
- data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +810 -0
- data/vendor/datasketches-cpp/req/test/CMakeLists.txt +43 -0
- data/vendor/datasketches-cpp/req/test/req_float_empty_from_java.sk +0 -0
- data/vendor/datasketches-cpp/req/test/req_float_estimation_from_java.sk +0 -0
- data/vendor/datasketches-cpp/req/test/req_float_exact_from_java.sk +0 -0
- data/vendor/datasketches-cpp/req/test/req_float_raw_items_from_java.sk +0 -0
- data/vendor/datasketches-cpp/req/test/req_float_single_item_from_java.sk +0 -0
- data/vendor/datasketches-cpp/req/test/req_sketch_custom_type_test.cpp +128 -0
- data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +494 -0
- data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +10 -9
- data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +82 -70
- data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +5 -5
- data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +7 -7
- data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +1 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_allocation_test.cpp +96 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +0 -31
- data/vendor/datasketches-cpp/setup.py +5 -3
- data/vendor/datasketches-cpp/theta/CMakeLists.txt +30 -3
- data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_sampled_sets.hpp +2 -1
- data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_theta_sketched_sets.hpp +1 -1
- data/vendor/datasketches-cpp/theta/include/theta_a_not_b.hpp +12 -29
- data/vendor/datasketches-cpp/theta/include/theta_a_not_b_impl.hpp +5 -46
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_comparators.hpp +0 -0
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_constants.hpp +2 -0
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_helpers.hpp +0 -0
- data/vendor/datasketches-cpp/theta/include/theta_intersection.hpp +22 -29
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_intersection_base.hpp +0 -0
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_intersection_base_impl.hpp +0 -0
- data/vendor/datasketches-cpp/theta/include/theta_intersection_impl.hpp +8 -90
- data/vendor/datasketches-cpp/{tuple/test/theta_union_experimental_test.cpp → theta/include/theta_jaccard_similarity.hpp} +11 -18
- data/vendor/datasketches-cpp/{tuple/include/jaccard_similarity.hpp → theta/include/theta_jaccard_similarity_base.hpp} +6 -22
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_set_difference_base.hpp +0 -0
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_set_difference_base_impl.hpp +5 -0
- data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +132 -266
- data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +200 -650
- data/vendor/datasketches-cpp/theta/include/theta_union.hpp +27 -60
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_union_base.hpp +1 -1
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_union_base_impl.hpp +5 -0
- data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +13 -69
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base.hpp +3 -19
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base_impl.hpp +6 -1
- data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +1 -0
- data/vendor/datasketches-cpp/{tuple → theta}/test/theta_jaccard_similarity_test.cpp +2 -3
- data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +37 -234
- data/vendor/datasketches-cpp/tuple/CMakeLists.txt +3 -35
- data/vendor/datasketches-cpp/tuple/include/tuple_jaccard_similarity.hpp +38 -0
- data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +28 -13
- data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +6 -6
- data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +1 -6
- data/vendor/datasketches-cpp/tuple/test/tuple_a_not_b_test.cpp +1 -4
- data/vendor/datasketches-cpp/tuple/test/tuple_intersection_test.cpp +1 -4
- data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +2 -1
- data/vendor/datasketches-cpp/tuple/test/tuple_sketch_allocation_test.cpp +2 -2
- data/vendor/datasketches-cpp/tuple/test/tuple_union_test.cpp +1 -4
- metadata +43 -34
- data/vendor/datasketches-cpp/tuple/include/theta_a_not_b_experimental.hpp +0 -53
- data/vendor/datasketches-cpp/tuple/include/theta_intersection_experimental.hpp +0 -78
- data/vendor/datasketches-cpp/tuple/include/theta_intersection_experimental_impl.hpp +0 -43
- data/vendor/datasketches-cpp/tuple/include/theta_sketch_experimental.hpp +0 -393
- data/vendor/datasketches-cpp/tuple/include/theta_sketch_experimental_impl.hpp +0 -481
- data/vendor/datasketches-cpp/tuple/include/theta_union_experimental.hpp +0 -88
- data/vendor/datasketches-cpp/tuple/include/theta_union_experimental_impl.hpp +0 -47
- data/vendor/datasketches-cpp/tuple/test/theta_a_not_b_experimental_test.cpp +0 -250
- data/vendor/datasketches-cpp/tuple/test/theta_compact_empty_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/test/theta_compact_estimation_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/test/theta_compact_single_item_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/test/theta_intersection_experimental_test.cpp +0 -224
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e62d3e98b646fb074ae5bccf506a3ec9659bfde99d98721e2e3d7377ea68a3ce
|
4
|
+
data.tar.gz: ef7a1d11de9801e0d40d0071a46f695555a026a54c8e31d23624c01045faafe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8808ddf87374a66de48f0434f22b8813cd0170d40ce1dc518a480235f6bd359322fb1e354e224355911f5569a32dce99457515dfd6a8a591223ea6a1e834dfb8
|
7
|
+
data.tar.gz: 5fdeee4c5b69a495d90242e2a3e6157fbca0931bebeb77ba025840c15f14e571c9a672b527082324b2e72e17ae6e0d301b7978cf21be6ae77766cd1b4f18c3d0
|
data/CHANGELOG.md
CHANGED
@@ -3,8 +3,7 @@
|
|
3
3
|
#include <cpc_sketch.hpp>
|
4
4
|
#include <cpc_union.hpp>
|
5
5
|
|
6
|
-
#include
|
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>(),
|
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
|
-
|
25
|
+
[](cpc_sketch& self, Rice::Object datum) {
|
27
26
|
if (FIXNUM_P(datum.value())) {
|
28
|
-
return self.update(
|
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(
|
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
|
-
|
36
|
+
[](cpc_sketch& self) {
|
38
37
|
return self.get_estimate();
|
39
38
|
})
|
40
39
|
.define_method(
|
41
40
|
"serialize",
|
42
|
-
|
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
|
-
|
49
|
+
[](cpc_sketch& self) {
|
51
50
|
return self.to_string();
|
52
51
|
})
|
53
|
-
.
|
52
|
+
.define_singleton_function(
|
54
53
|
"deserialize",
|
55
|
-
|
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>(),
|
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
|
-
|
64
|
+
[](cpc_union& self, cpc_sketch& sketch) {
|
66
65
|
self.update(sketch);
|
67
66
|
});
|
68
67
|
}
|
data/ext/datasketches/ext.cpp
CHANGED
data/ext/datasketches/extconf.rb
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
#include <frequent_items_sketch.hpp>
|
4
4
|
|
5
|
-
#include
|
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
|
-
|
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
|
-
|
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
|
-
|
33
|
+
[](datasketches::frequent_items_sketch<T>& self) {
|
35
34
|
return self.to_string();
|
36
35
|
})
|
37
|
-
.
|
36
|
+
.define_singleton_function(
|
38
37
|
"deserialize",
|
39
|
-
|
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
|
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
|
-
|
19
|
+
[](hll_sketch& self, Rice::Object datum) {
|
21
20
|
if (FIXNUM_P(datum.value())) {
|
22
|
-
return self.update(
|
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(
|
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
|
-
|
30
|
+
[](hll_sketch& self) {
|
32
31
|
return self.get_estimate();
|
33
32
|
})
|
34
33
|
.define_method(
|
35
34
|
"serialize_compact",
|
36
|
-
|
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
|
-
|
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
|
-
|
50
|
+
[](hll_sketch& self) {
|
52
51
|
return self.to_string();
|
53
52
|
})
|
54
|
-
.
|
53
|
+
.define_singleton_function(
|
55
54
|
"deserialize",
|
56
|
-
|
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
|
-
|
64
|
+
[](hll_union& self, hll_sketch& sketch) {
|
66
65
|
self.update(sketch);
|
67
66
|
})
|
68
67
|
.define_method(
|
69
68
|
"estimate",
|
70
|
-
|
69
|
+
[](hll_union& self) {
|
71
70
|
return self.get_estimate();
|
72
71
|
})
|
73
72
|
.define_method(
|
74
73
|
"result",
|
75
|
-
|
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
|
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
|
-
|
12
|
-
std::vector<int> from_ruby<std::vector<int>>(Rice::Object x)
|
9
|
+
namespace Rice::detail
|
13
10
|
{
|
14
|
-
|
15
|
-
std::vector<
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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>(),
|
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
|
-
|
39
|
+
[](kll_sketch<T>& self, Rice::Object obj) {
|
88
40
|
if (obj.is_a(rb_cArray)) {
|
89
|
-
auto fractions =
|
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(
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
69
|
+
[](kll_sketch<T>& self, const T item) {
|
118
70
|
self.update(item);
|
119
71
|
})
|
120
72
|
.define_method(
|
121
73
|
"serialize",
|
122
|
-
|
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
|
-
|
82
|
+
[](kll_sketch<T>& self) {
|
131
83
|
return self.to_string();
|
132
84
|
})
|
133
|
-
.
|
85
|
+
.define_singleton_function(
|
134
86
|
"deserialize",
|
135
|
-
|
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
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
.
|
37
|
+
.define_singleton_function(
|
38
38
|
"new",
|
39
|
-
|
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
|
-
|
47
|
-
.define_method("compact", &update_theta_sketch::compact,
|
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
|
-
|
50
|
+
[](update_theta_sketch& self, Rice::Object datum) {
|
51
51
|
if (FIXNUM_P(datum.value())) {
|
52
|
-
return self.update(
|
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(
|
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
|
-
|
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
|
-
.
|
66
|
+
.define_singleton_function(
|
81
67
|
"new",
|
82
|
-
|
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
|
-
|
90
|
-
.define_method("update", &theta_union::update)
|
91
|
-
.define_method("result", &theta_union::get_result,
|
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>(),
|
95
|
-
.define_method("update", &theta_intersection::update)
|
96
|
-
.define_method("result", &theta_intersection::get_result,
|
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>(),
|
101
|
-
.define_method("compute", &theta_a_not_b::compute
|
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
|
}
|