datasketches 0.3.1 → 0.4.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 +10 -0
- data/NOTICE +1 -1
- data/README.md +0 -2
- data/ext/datasketches/cpc_wrapper.cpp +3 -3
- data/ext/datasketches/kll_wrapper.cpp +0 -10
- data/lib/datasketches/version.rb +1 -1
- data/lib/datasketches.rb +1 -1
- data/vendor/datasketches-cpp/CMakeLists.txt +23 -20
- data/vendor/datasketches-cpp/CODE_OF_CONDUCT.md +3 -0
- data/vendor/datasketches-cpp/CONTRIBUTING.md +50 -0
- data/vendor/datasketches-cpp/Doxyfile +2827 -0
- data/vendor/datasketches-cpp/LICENSE +0 -76
- data/vendor/datasketches-cpp/README.md +1 -3
- data/vendor/datasketches-cpp/common/CMakeLists.txt +12 -11
- data/vendor/datasketches-cpp/common/include/MurmurHash3.h +25 -27
- data/vendor/datasketches-cpp/common/include/common_defs.hpp +15 -10
- data/vendor/datasketches-cpp/common/include/count_zeros.hpp +11 -2
- data/vendor/datasketches-cpp/common/include/kolmogorov_smirnov.hpp +9 -6
- data/vendor/datasketches-cpp/common/include/memory_operations.hpp +5 -4
- data/vendor/datasketches-cpp/common/include/optional.hpp +148 -0
- data/vendor/datasketches-cpp/common/include/quantiles_sorted_view.hpp +95 -2
- data/vendor/datasketches-cpp/common/include/quantiles_sorted_view_impl.hpp +1 -1
- data/vendor/datasketches-cpp/common/include/serde.hpp +69 -20
- data/vendor/datasketches-cpp/common/test/CMakeLists.txt +2 -2
- data/vendor/datasketches-cpp/common/test/integration_test.cpp +6 -0
- data/vendor/datasketches-cpp/common/test/optional_test.cpp +85 -0
- data/vendor/datasketches-cpp/common/test/test_allocator.hpp +14 -14
- data/vendor/datasketches-cpp/{python/src/__init__.py → count/CMakeLists.txt} +25 -1
- data/vendor/datasketches-cpp/count/include/count_min.hpp +405 -0
- data/vendor/datasketches-cpp/count/include/count_min_impl.hpp +497 -0
- data/vendor/datasketches-cpp/{MANIFEST.in → count/test/CMakeLists.txt} +23 -20
- data/vendor/datasketches-cpp/count/test/count_min_allocation_test.cpp +155 -0
- data/vendor/datasketches-cpp/count/test/count_min_test.cpp +303 -0
- data/vendor/datasketches-cpp/cpc/include/cpc_common.hpp +14 -20
- data/vendor/datasketches-cpp/cpc/include/cpc_compressor.hpp +7 -4
- data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +17 -17
- data/vendor/datasketches-cpp/cpc/include/cpc_confidence.hpp +3 -3
- data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +40 -40
- data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +14 -11
- data/vendor/datasketches-cpp/cpc/include/cpc_union.hpp +35 -11
- data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +8 -8
- data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +16 -8
- data/vendor/datasketches-cpp/cpc/include/u32_table.hpp +3 -2
- data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +5 -5
- data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +20 -7
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_deserialize_from_java_test.cpp +60 -0
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_serialize_for_java.cpp +38 -0
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +4 -29
- data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +4 -4
- data/vendor/datasketches-cpp/{tox.ini → density/CMakeLists.txt} +24 -8
- data/vendor/datasketches-cpp/density/include/density_sketch.hpp +256 -0
- data/vendor/datasketches-cpp/density/include/density_sketch_impl.hpp +543 -0
- data/vendor/datasketches-cpp/{python/datasketches/__init__.py → density/test/CMakeLists.txt} +15 -3
- data/vendor/datasketches-cpp/density/test/density_sketch_test.cpp +244 -0
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +21 -9
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +6 -4
- data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +9 -3
- data/vendor/datasketches-cpp/fi/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_deserialize_from_java_test.cpp +95 -0
- data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_serialize_for_java.cpp +83 -0
- data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_test.cpp +3 -42
- data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +2 -2
- data/vendor/datasketches-cpp/hll/include/CouponList.hpp +3 -1
- data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +19 -11
- data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +2 -5
- data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +19 -7
- data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +1 -1
- data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +98 -42
- data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +2 -0
- data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +94 -61
- data/vendor/datasketches-cpp/hll/include/HllArray.hpp +20 -8
- data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +4 -4
- data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +3 -1
- data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +3 -21
- data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +8 -0
- data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +14 -18
- data/vendor/datasketches-cpp/hll/include/coupon_iterator-internal.hpp +1 -1
- data/vendor/datasketches-cpp/hll/include/coupon_iterator.hpp +8 -2
- data/vendor/datasketches-cpp/hll/include/hll.hpp +79 -65
- data/vendor/datasketches-cpp/hll/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +7 -1
- data/vendor/datasketches-cpp/hll/test/ToFromByteArrayTest.cpp +0 -68
- data/vendor/datasketches-cpp/hll/test/hll_sketch_deserialize_from_java_test.cpp +69 -0
- data/vendor/datasketches-cpp/hll/test/hll_sketch_serialize_for_java.cpp +52 -0
- data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +0 -1
- data/vendor/datasketches-cpp/kll/include/kll_helper_impl.hpp +2 -2
- data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +79 -53
- data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +61 -132
- data/vendor/datasketches-cpp/kll/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/kll/test/kll_sketch_deserialize_from_java_test.cpp +103 -0
- data/vendor/datasketches-cpp/kll/test/kll_sketch_serialize_for_java.cpp +62 -0
- data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +5 -40
- data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch.hpp +76 -54
- data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch_impl.hpp +66 -136
- data/vendor/datasketches-cpp/quantiles/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_deserialize_from_java_test.cpp +84 -0
- data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_serialize_for_java.cpp +52 -0
- data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_test.cpp +15 -39
- data/vendor/datasketches-cpp/req/include/req_common.hpp +7 -3
- data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +2 -4
- data/vendor/datasketches-cpp/req/include/req_sketch.hpp +105 -26
- data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +50 -111
- data/vendor/datasketches-cpp/req/test/CMakeLists.txt +14 -1
- data/vendor/datasketches-cpp/req/test/req_sketch_deserialize_from_java_test.cpp +55 -0
- data/vendor/datasketches-cpp/{tuple/include/array_of_doubles_intersection_impl.hpp → req/test/req_sketch_serialize_for_java.cpp} +12 -7
- data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +3 -89
- data/vendor/datasketches-cpp/sampling/CMakeLists.txt +4 -0
- data/vendor/datasketches-cpp/sampling/include/ebpps_sample.hpp +210 -0
- data/vendor/datasketches-cpp/sampling/include/ebpps_sample_impl.hpp +535 -0
- data/vendor/datasketches-cpp/sampling/include/ebpps_sketch.hpp +281 -0
- data/vendor/datasketches-cpp/sampling/include/ebpps_sketch_impl.hpp +531 -0
- data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +89 -32
- data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +33 -19
- data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +13 -10
- data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +23 -19
- data/vendor/datasketches-cpp/sampling/test/CMakeLists.txt +55 -8
- data/vendor/datasketches-cpp/sampling/test/ebpps_allocation_test.cpp +96 -0
- data/vendor/datasketches-cpp/sampling/test/ebpps_sample_test.cpp +137 -0
- data/vendor/datasketches-cpp/sampling/test/ebpps_sketch_test.cpp +266 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_deserialize_from_java_test.cpp +81 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_serialize_for_java.cpp +54 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +33 -51
- data/vendor/datasketches-cpp/sampling/test/var_opt_union_deserialize_from_java_test.cpp +50 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_union_serialize_for_java.cpp +56 -0
- data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +0 -20
- data/vendor/datasketches-cpp/theta/CMakeLists.txt +1 -0
- data/vendor/datasketches-cpp/theta/include/bit_packing.hpp +6279 -0
- data/vendor/datasketches-cpp/theta/include/bounds_on_ratios_in_sampled_sets.hpp +1 -0
- data/vendor/datasketches-cpp/theta/include/bounds_on_ratios_in_theta_sketched_sets.hpp +7 -6
- data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser.hpp +14 -8
- data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser_impl.hpp +60 -46
- data/vendor/datasketches-cpp/theta/include/theta_a_not_b.hpp +20 -5
- data/vendor/datasketches-cpp/theta/include/theta_constants.hpp +10 -4
- data/vendor/datasketches-cpp/theta/include/theta_helpers.hpp +3 -1
- data/vendor/datasketches-cpp/theta/include/theta_intersection.hpp +13 -5
- data/vendor/datasketches-cpp/theta/include/theta_intersection_base_impl.hpp +5 -5
- data/vendor/datasketches-cpp/theta/include/theta_intersection_impl.hpp +3 -3
- data/vendor/datasketches-cpp/theta/include/theta_jaccard_similarity.hpp +2 -1
- data/vendor/datasketches-cpp/theta/include/theta_jaccard_similarity_base.hpp +1 -0
- data/vendor/datasketches-cpp/theta/include/theta_set_difference_base_impl.hpp +1 -1
- data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +180 -33
- data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +430 -130
- data/vendor/datasketches-cpp/theta/include/theta_union.hpp +17 -10
- data/vendor/datasketches-cpp/theta/include/theta_union_base_impl.hpp +10 -10
- data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +3 -3
- data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base.hpp +21 -6
- data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base_impl.hpp +13 -3
- data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +15 -1
- data/vendor/datasketches-cpp/theta/test/bit_packing_test.cpp +80 -0
- data/vendor/datasketches-cpp/theta/test/theta_sketch_deserialize_from_java_test.cpp +57 -0
- data/vendor/datasketches-cpp/theta/test/theta_sketch_serialize_for_java.cpp +61 -0
- data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +39 -188
- data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +25 -0
- data/vendor/datasketches-cpp/tuple/CMakeLists.txt +8 -7
- data/vendor/datasketches-cpp/tuple/include/array_of_doubles_sketch.hpp +19 -144
- data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_a_not_b.hpp → array_tuple_a_not_b.hpp} +24 -16
- data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_a_not_b_impl.hpp → array_tuple_a_not_b_impl.hpp} +4 -4
- data/vendor/datasketches-cpp/tuple/include/array_tuple_intersection.hpp +65 -0
- data/vendor/datasketches-cpp/tuple/include/array_tuple_intersection_impl.hpp +31 -0
- data/vendor/datasketches-cpp/tuple/include/array_tuple_sketch.hpp +237 -0
- data/vendor/datasketches-cpp/tuple/include/{array_of_doubles_sketch_impl.hpp → array_tuple_sketch_impl.hpp} +40 -41
- data/vendor/datasketches-cpp/tuple/include/array_tuple_union.hpp +81 -0
- data/vendor/datasketches-cpp/tuple/include/array_tuple_union_impl.hpp +43 -0
- data/vendor/datasketches-cpp/tuple/include/tuple_a_not_b.hpp +11 -2
- data/vendor/datasketches-cpp/tuple/include/tuple_intersection.hpp +17 -10
- data/vendor/datasketches-cpp/tuple/include/tuple_jaccard_similarity.hpp +2 -1
- data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +95 -32
- data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +2 -1
- data/vendor/datasketches-cpp/tuple/include/tuple_union.hpp +19 -11
- data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +16 -1
- data/vendor/datasketches-cpp/tuple/test/aod_sketch_deserialize_from_java_test.cpp +76 -0
- data/vendor/datasketches-cpp/tuple/test/aod_sketch_serialize_for_java.cpp +62 -0
- data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +5 -129
- data/vendor/datasketches-cpp/tuple/test/engagement_test.cpp +85 -89
- data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +3 -1
- data/vendor/datasketches-cpp/tuple/test/tuple_sketch_deserialize_from_java_test.cpp +47 -0
- data/vendor/datasketches-cpp/{python/src/datasketches.cpp → tuple/test/tuple_sketch_serialize_for_java.cpp} +16 -30
- data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +1 -1
- data/vendor/datasketches-cpp/version.cfg.in +1 -1
- metadata +61 -79
- data/vendor/datasketches-cpp/fi/test/items_sketch_string_from_java.sk +0 -0
- data/vendor/datasketches-cpp/fi/test/items_sketch_string_utf8_from_java.sk +0 -0
- data/vendor/datasketches-cpp/fi/test/longs_sketch_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/array6_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/compact_array4_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/compact_set_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/list_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/updatable_array4_from_java.sk +0 -0
- data/vendor/datasketches-cpp/hll/test/updatable_set_from_java.sk +0 -0
- data/vendor/datasketches-cpp/kll/test/kll_sketch_from_java.sk +0 -0
- data/vendor/datasketches-cpp/pyproject.toml +0 -23
- data/vendor/datasketches-cpp/python/CMakeLists.txt +0 -81
- data/vendor/datasketches-cpp/python/README.md +0 -85
- data/vendor/datasketches-cpp/python/datasketches/PySerDe.py +0 -104
- data/vendor/datasketches-cpp/python/include/py_serde.hpp +0 -113
- data/vendor/datasketches-cpp/python/jupyter/CPCSketch.ipynb +0 -345
- data/vendor/datasketches-cpp/python/jupyter/FrequentItemsSketch.ipynb +0 -354
- data/vendor/datasketches-cpp/python/jupyter/HLLSketch.ipynb +0 -346
- data/vendor/datasketches-cpp/python/jupyter/KLLSketch.ipynb +0 -463
- data/vendor/datasketches-cpp/python/jupyter/ThetaSketchNotebook.ipynb +0 -403
- data/vendor/datasketches-cpp/python/pybind11Path.cmd +0 -21
- data/vendor/datasketches-cpp/python/src/cpc_wrapper.cpp +0 -90
- data/vendor/datasketches-cpp/python/src/fi_wrapper.cpp +0 -128
- data/vendor/datasketches-cpp/python/src/hll_wrapper.cpp +0 -134
- data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +0 -210
- data/vendor/datasketches-cpp/python/src/ks_wrapper.cpp +0 -68
- data/vendor/datasketches-cpp/python/src/py_serde.cpp +0 -111
- data/vendor/datasketches-cpp/python/src/quantiles_wrapper.cpp +0 -204
- data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +0 -215
- data/vendor/datasketches-cpp/python/src/theta_wrapper.cpp +0 -172
- data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +0 -490
- data/vendor/datasketches-cpp/python/src/vo_wrapper.cpp +0 -173
- data/vendor/datasketches-cpp/python/tests/__init__.py +0 -16
- data/vendor/datasketches-cpp/python/tests/cpc_test.py +0 -64
- data/vendor/datasketches-cpp/python/tests/fi_test.py +0 -110
- data/vendor/datasketches-cpp/python/tests/hll_test.py +0 -130
- data/vendor/datasketches-cpp/python/tests/kll_test.py +0 -125
- data/vendor/datasketches-cpp/python/tests/quantiles_test.py +0 -126
- data/vendor/datasketches-cpp/python/tests/req_test.py +0 -126
- data/vendor/datasketches-cpp/python/tests/theta_test.py +0 -146
- data/vendor/datasketches-cpp/python/tests/vector_of_kll_test.py +0 -148
- data/vendor/datasketches-cpp/python/tests/vo_test.py +0 -125
- 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/sampling/test/binaries_from_java.txt +0 -67
- data/vendor/datasketches-cpp/sampling/test/varopt_sketch_long_sampling.sk +0 -0
- data/vendor/datasketches-cpp/sampling/test/varopt_sketch_string_exact.sk +0 -0
- data/vendor/datasketches-cpp/sampling/test/varopt_union_double_sampling.sk +0 -0
- data/vendor/datasketches-cpp/setup.py +0 -110
- data/vendor/datasketches-cpp/theta/test/theta_compact_empty_from_java.sk +0 -0
- data/vendor/datasketches-cpp/theta/test/theta_compact_estimation_from_java.sk +0 -0
- data/vendor/datasketches-cpp/theta/test/theta_compact_exact_from_java.sk +0 -0
- data/vendor/datasketches-cpp/theta/test/theta_compact_single_item_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/include/array_of_doubles_intersection.hpp +0 -52
- data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union.hpp +0 -81
- data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union_impl.hpp +0 -43
- data/vendor/datasketches-cpp/tuple/test/aod_1_compact_empty_from_java.sk +0 -1
- data/vendor/datasketches-cpp/tuple/test/aod_1_compact_estimation_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/test/aod_1_compact_non_empty_no_entries_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/test/aod_2_compact_exact_from_java.sk +0 -0
- data/vendor/datasketches-cpp/tuple/test/aod_3_compact_empty_from_java.sk +0 -1
@@ -26,6 +26,16 @@
|
|
26
26
|
|
27
27
|
namespace datasketches {
|
28
28
|
|
29
|
+
// forward declaration
|
30
|
+
template<typename A> class theta_union_alloc;
|
31
|
+
|
32
|
+
// alias with default allocator for convenience
|
33
|
+
using theta_union = theta_union_alloc<std::allocator<uint64_t>>;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Theta Union.
|
37
|
+
* Computes union of Theta sketches. There is no constructor. Use builder instead.
|
38
|
+
*/
|
29
39
|
template<typename Allocator = std::allocator<uint64_t>>
|
30
40
|
class theta_union_alloc {
|
31
41
|
public:
|
@@ -35,6 +45,7 @@ public:
|
|
35
45
|
using CompactSketch = compact_theta_sketch_alloc<Allocator>;
|
36
46
|
using resize_factor = theta_constants::resize_factor;
|
37
47
|
|
48
|
+
// there is no payload in Theta sketch entry
|
38
49
|
struct nop_policy {
|
39
50
|
void operator()(uint64_t internal_entry, uint64_t incoming_entry) const {
|
40
51
|
unused(internal_entry);
|
@@ -47,22 +58,20 @@ public:
|
|
47
58
|
class builder;
|
48
59
|
|
49
60
|
/**
|
50
|
-
*
|
61
|
+
* Update the union with a given sketch
|
51
62
|
* @param sketch to update the union with
|
52
63
|
*/
|
53
64
|
template<typename FwdSketch>
|
54
65
|
void update(FwdSketch&& sketch);
|
55
66
|
|
56
67
|
/**
|
57
|
-
*
|
58
|
-
* @param ordered optional flag to specify if ordered sketch should be produced
|
68
|
+
* Produces a copy of the current state of the union as a compact sketch.
|
69
|
+
* @param ordered optional flag to specify if an ordered sketch should be produced
|
59
70
|
* @return the result of the union
|
60
71
|
*/
|
61
72
|
CompactSketch get_result(bool ordered = true) const;
|
62
73
|
|
63
|
-
|
64
|
-
* Reset the union to the initial empty state
|
65
|
-
*/
|
74
|
+
/// Reset the union to the initial empty state
|
66
75
|
void reset();
|
67
76
|
|
68
77
|
private:
|
@@ -72,21 +81,19 @@ private:
|
|
72
81
|
theta_union_alloc(uint8_t lg_cur_size, uint8_t lg_nom_size, resize_factor rf, float p, uint64_t theta, uint64_t seed, const Allocator& allocator);
|
73
82
|
};
|
74
83
|
|
84
|
+
/// Theta union builder
|
75
85
|
template<typename A>
|
76
86
|
class theta_union_alloc<A>::builder: public theta_base_builder<builder, A> {
|
77
87
|
public:
|
78
88
|
builder(const A& allocator = A());
|
79
89
|
|
80
90
|
/**
|
81
|
-
*
|
91
|
+
* Create an instance of the union with predefined parameters.
|
82
92
|
* @return an instance of the union
|
83
93
|
*/
|
84
94
|
theta_union_alloc<A> build() const;
|
85
95
|
};
|
86
96
|
|
87
|
-
// alias with default allocator for convenience
|
88
|
-
using theta_union = theta_union_alloc<std::allocator<uint64_t>>;
|
89
|
-
|
90
97
|
} /* namespace datasketches */
|
91
98
|
|
92
99
|
#include "theta_union_impl.hpp"
|
@@ -41,8 +41,8 @@ void theta_union_base<EN, EK, P, S, CS, A>::update(SS&& sketch) {
|
|
41
41
|
if (sketch.is_empty()) return;
|
42
42
|
if (sketch.get_seed_hash() != compute_seed_hash(table_.seed_)) throw std::invalid_argument("seed hash mismatch");
|
43
43
|
table_.is_empty_ = false;
|
44
|
-
|
45
|
-
for (auto
|
44
|
+
union_theta_ = std::min(union_theta_, sketch.get_theta64());
|
45
|
+
for (auto&& entry: sketch) {
|
46
46
|
const uint64_t hash = EK()(entry);
|
47
47
|
if (hash < union_theta_ && hash < table_.theta_) {
|
48
48
|
auto result = table_.find(hash);
|
@@ -55,7 +55,7 @@ void theta_union_base<EN, EK, P, S, CS, A>::update(SS&& sketch) {
|
|
55
55
|
if (sketch.is_ordered()) break; // early stop
|
56
56
|
}
|
57
57
|
}
|
58
|
-
|
58
|
+
union_theta_ = std::min(union_theta_, table_.theta_);
|
59
59
|
}
|
60
60
|
|
61
61
|
template<typename EN, typename EK, typename P, typename S, typename CS, typename A>
|
@@ -65,16 +65,16 @@ CS theta_union_base<EN, EK, P, S, CS, A>::get_result(bool ordered) const {
|
|
65
65
|
entries.reserve(table_.num_entries_);
|
66
66
|
uint64_t theta = std::min(union_theta_, table_.theta_);
|
67
67
|
const uint32_t nominal_num = 1 << table_.lg_nom_size_;
|
68
|
-
if (union_theta_ >=
|
68
|
+
if (union_theta_ >= table_.theta_) {
|
69
69
|
std::copy_if(table_.begin(), table_.end(), std::back_inserter(entries), key_not_zero<EN, EK>());
|
70
70
|
} else {
|
71
71
|
std::copy_if(table_.begin(), table_.end(), std::back_inserter(entries), key_not_zero_less_than<uint64_t, EN, EK>(theta));
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
}
|
73
|
+
if (entries.size() > nominal_num) {
|
74
|
+
std::nth_element(entries.begin(), entries.begin() + nominal_num, entries.end(), comparator());
|
75
|
+
theta = EK()(entries[nominal_num]);
|
76
|
+
entries.erase(entries.begin() + nominal_num, entries.end());
|
77
|
+
entries.shrink_to_fit();
|
78
78
|
}
|
79
79
|
if (ordered) std::sort(entries.begin(), entries.end(), comparator());
|
80
80
|
return CS(table_.is_empty_, ordered, compute_seed_hash(table_.seed_), theta, std::move(entries));
|
@@ -28,9 +28,9 @@ state_(lg_cur_size, lg_nom_size, rf, p, theta, seed, nop_policy(), allocator)
|
|
28
28
|
{}
|
29
29
|
|
30
30
|
template<typename A>
|
31
|
-
template<typename
|
32
|
-
void theta_union_alloc<A>::update(
|
33
|
-
state_.update(std::forward<
|
31
|
+
template<typename FwdSketch>
|
32
|
+
void theta_union_alloc<A>::update(FwdSketch&& sketch) {
|
33
|
+
state_.update(std::forward<FwdSketch>(sketch));
|
34
34
|
}
|
35
35
|
|
36
36
|
template<typename A>
|
@@ -23,8 +23,8 @@
|
|
23
23
|
#include <vector>
|
24
24
|
#include <climits>
|
25
25
|
#include <cmath>
|
26
|
+
#include <iterator>
|
26
27
|
|
27
|
-
#include "common_defs.hpp"
|
28
28
|
#include "MurmurHash3.h"
|
29
29
|
#include "theta_comparators.hpp"
|
30
30
|
#include "theta_constants.hpp"
|
@@ -91,13 +91,14 @@ struct theta_update_sketch_base {
|
|
91
91
|
static void consolidate_non_empty(Entry* entries, size_t size, size_t num);
|
92
92
|
};
|
93
93
|
|
94
|
-
// builder
|
95
94
|
|
95
|
+
/// Theta base builder
|
96
96
|
template<typename Derived, typename Allocator>
|
97
97
|
class theta_base_builder {
|
98
98
|
public:
|
99
99
|
/**
|
100
100
|
* Creates and instance of the builder with default parameters.
|
101
|
+
* @param allocator instance of an Allocator to pass to created sketches
|
101
102
|
*/
|
102
103
|
theta_base_builder(const Allocator& allocator);
|
103
104
|
|
@@ -185,14 +186,21 @@ static inline uint64_t compute_hash(const void* data, size_t length, uint64_t se
|
|
185
186
|
// iterators
|
186
187
|
|
187
188
|
template<typename Entry, typename ExtractKey>
|
188
|
-
class theta_iterator
|
189
|
+
class theta_iterator {
|
189
190
|
public:
|
191
|
+
using iterator_category = std::input_iterator_tag;
|
192
|
+
using value_type = Entry;
|
193
|
+
using difference_type = std::ptrdiff_t;
|
194
|
+
using pointer = Entry*;
|
195
|
+
using reference = Entry&;
|
196
|
+
|
190
197
|
theta_iterator(Entry* entries, uint32_t size, uint32_t index);
|
191
198
|
theta_iterator& operator++();
|
192
199
|
theta_iterator operator++(int);
|
193
200
|
bool operator==(const theta_iterator& other) const;
|
194
201
|
bool operator!=(const theta_iterator& other) const;
|
195
|
-
|
202
|
+
reference operator*() const;
|
203
|
+
pointer operator->() const;
|
196
204
|
|
197
205
|
private:
|
198
206
|
Entry* entries_;
|
@@ -201,14 +209,21 @@ private:
|
|
201
209
|
};
|
202
210
|
|
203
211
|
template<typename Entry, typename ExtractKey>
|
204
|
-
class theta_const_iterator
|
212
|
+
class theta_const_iterator {
|
205
213
|
public:
|
214
|
+
using iterator_category = std::input_iterator_tag;
|
215
|
+
using value_type = const Entry;
|
216
|
+
using difference_type = std::ptrdiff_t;
|
217
|
+
using pointer = const Entry*;
|
218
|
+
using reference = const Entry&;
|
219
|
+
|
206
220
|
theta_const_iterator(const Entry* entries, uint32_t size, uint32_t index);
|
207
221
|
theta_const_iterator& operator++();
|
208
222
|
theta_const_iterator operator++(int);
|
209
223
|
bool operator==(const theta_const_iterator& other) const;
|
210
224
|
bool operator!=(const theta_const_iterator& other) const;
|
211
|
-
|
225
|
+
reference operator*() const;
|
226
|
+
pointer operator->() const;
|
212
227
|
|
213
228
|
private:
|
214
229
|
const Entry* entries_;
|
@@ -188,7 +188,7 @@ auto theta_update_sketch_base<EN, EK, A>::begin() const -> iterator {
|
|
188
188
|
|
189
189
|
template<typename EN, typename EK, typename A>
|
190
190
|
auto theta_update_sketch_base<EN, EK, A>::end() const -> iterator {
|
191
|
-
return
|
191
|
+
return entries_ + (1ULL << lg_cur_size_);
|
192
192
|
}
|
193
193
|
|
194
194
|
template<typename EN, typename EK, typename A>
|
@@ -382,10 +382,15 @@ bool theta_iterator<Entry, ExtractKey>::operator==(const theta_iterator& other)
|
|
382
382
|
}
|
383
383
|
|
384
384
|
template<typename Entry, typename ExtractKey>
|
385
|
-
auto theta_iterator<Entry, ExtractKey>::operator*() const ->
|
385
|
+
auto theta_iterator<Entry, ExtractKey>::operator*() const -> reference {
|
386
386
|
return entries_[index_];
|
387
387
|
}
|
388
388
|
|
389
|
+
template<typename Entry, typename ExtractKey>
|
390
|
+
auto theta_iterator<Entry, ExtractKey>::operator->() const -> pointer {
|
391
|
+
return entries_ + index_;
|
392
|
+
}
|
393
|
+
|
389
394
|
// const iterator
|
390
395
|
|
391
396
|
template<typename Entry, typename ExtractKey>
|
@@ -419,10 +424,15 @@ bool theta_const_iterator<Entry, ExtractKey>::operator==(const theta_const_itera
|
|
419
424
|
}
|
420
425
|
|
421
426
|
template<typename Entry, typename ExtractKey>
|
422
|
-
auto theta_const_iterator<Entry, ExtractKey>::operator*() const ->
|
427
|
+
auto theta_const_iterator<Entry, ExtractKey>::operator*() const -> reference {
|
423
428
|
return entries_[index_];
|
424
429
|
}
|
425
430
|
|
431
|
+
template<typename Entry, typename ExtractKey>
|
432
|
+
auto theta_const_iterator<Entry, ExtractKey>::operator->() const -> pointer {
|
433
|
+
return entries_ + index_;
|
434
|
+
}
|
435
|
+
|
426
436
|
} /* namespace datasketches */
|
427
437
|
|
428
438
|
#endif
|
@@ -20,7 +20,6 @@ add_executable(theta_test)
|
|
20
20
|
target_link_libraries(theta_test theta common_test_lib)
|
21
21
|
|
22
22
|
set_target_properties(theta_test PROPERTIES
|
23
|
-
CXX_STANDARD 11
|
24
23
|
CXX_STANDARD_REQUIRED YES
|
25
24
|
)
|
26
25
|
|
@@ -44,4 +43,19 @@ target_sources(theta_test
|
|
44
43
|
theta_a_not_b_test.cpp
|
45
44
|
theta_jaccard_similarity_test.cpp
|
46
45
|
theta_setop_test.cpp
|
46
|
+
bit_packing_test.cpp
|
47
47
|
)
|
48
|
+
|
49
|
+
if (SERDE_COMPAT)
|
50
|
+
target_sources(theta_test
|
51
|
+
PRIVATE
|
52
|
+
theta_sketch_deserialize_from_java_test.cpp
|
53
|
+
)
|
54
|
+
endif()
|
55
|
+
|
56
|
+
if (GENERATE)
|
57
|
+
target_sources(theta_test
|
58
|
+
PRIVATE
|
59
|
+
theta_sketch_serialize_for_java.cpp
|
60
|
+
)
|
61
|
+
endif()
|
@@ -0,0 +1,80 @@
|
|
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
|
+
#include <catch2/catch.hpp>
|
21
|
+
#include <bit_packing.hpp>
|
22
|
+
|
23
|
+
namespace datasketches {
|
24
|
+
|
25
|
+
// for every number of bits from 1 to 63
|
26
|
+
// generate pseudo-random data, pack, unpack and compare
|
27
|
+
|
28
|
+
// inverse golden ratio (0.618.. of max uint64_t)
|
29
|
+
static const uint64_t IGOLDEN64 = 0x9e3779b97f4a7c13ULL;
|
30
|
+
|
31
|
+
TEST_CASE("pack unpack bits") {
|
32
|
+
for (uint8_t bits = 1; bits <= 63; ++bits) {
|
33
|
+
const uint64_t mask = (1ULL << bits) - 1;
|
34
|
+
std::vector<uint64_t> input(8, 0);
|
35
|
+
const uint64_t igolden64 = IGOLDEN64;
|
36
|
+
uint64_t value = 0xaa55aa55aa55aa55ULL; // arbitrary starting value
|
37
|
+
for (int i = 0; i < 8; ++i) {
|
38
|
+
input[i] = value & mask;
|
39
|
+
value += igolden64;
|
40
|
+
}
|
41
|
+
std::vector<uint8_t> bytes(8 * sizeof(uint64_t), 0);
|
42
|
+
uint8_t offset = 0;
|
43
|
+
uint8_t* ptr = bytes.data();
|
44
|
+
for (int i = 0; i < 8; ++i) {
|
45
|
+
offset = pack_bits(input[i], bits, ptr, offset);
|
46
|
+
}
|
47
|
+
|
48
|
+
std::vector<uint64_t> output(8, 0);
|
49
|
+
offset = 0;
|
50
|
+
const uint8_t* cptr = bytes.data();
|
51
|
+
for (int i = 0; i < 8; ++i) {
|
52
|
+
offset = unpack_bits(output[i], bits, cptr, offset);
|
53
|
+
}
|
54
|
+
for (int i = 0; i < 8; ++i) {
|
55
|
+
REQUIRE((input[i] & mask) == output[i]);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
TEST_CASE("pack unpack blocks") {
|
61
|
+
for (uint8_t bits = 1; bits <= 63; ++bits) {
|
62
|
+
const uint64_t mask = (1ULL << bits) - 1;
|
63
|
+
std::vector<uint64_t> input(8, 0);
|
64
|
+
const uint64_t igolden64 = IGOLDEN64;
|
65
|
+
uint64_t value = 0xaa55aa55aa55aa55ULL; // arbitrary starting value
|
66
|
+
for (int i = 0; i < 8; ++i) {
|
67
|
+
input[i] = value & mask;
|
68
|
+
value += igolden64;
|
69
|
+
}
|
70
|
+
std::vector<uint8_t> bytes(8 * sizeof(uint64_t), 0);
|
71
|
+
pack_bits_block8(input.data(), bytes.data(), bits);
|
72
|
+
std::vector<uint64_t> output(8, 0);
|
73
|
+
unpack_bits_block8(output.data(), bytes.data(), bits);
|
74
|
+
for (int i = 0; i < 8; ++i) {
|
75
|
+
REQUIRE((input[i] & mask) == output[i]);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
} /* namespace datasketches */
|
@@ -0,0 +1,57 @@
|
|
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
|
+
#include <catch2/catch.hpp>
|
21
|
+
#include <fstream>
|
22
|
+
#include <theta_sketch.hpp>
|
23
|
+
|
24
|
+
namespace datasketches {
|
25
|
+
|
26
|
+
// assume the binary sketches for this test have been generated by datasketches-java code
|
27
|
+
// in the subdirectory called "java" in the root directory of this project
|
28
|
+
static std::string testBinaryInputPath = std::string(TEST_BINARY_INPUT_PATH) + "../../java/";
|
29
|
+
|
30
|
+
TEST_CASE("theta sketch", "[serde_compat]") {
|
31
|
+
const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
|
32
|
+
for (const unsigned n: n_arr) {
|
33
|
+
std::ifstream is;
|
34
|
+
is.exceptions(std::ios::failbit | std::ios::badbit);
|
35
|
+
is.open(testBinaryInputPath + "theta_n" + std::to_string(n) + "_java.sk", std::ios::binary);
|
36
|
+
const auto sketch = compact_theta_sketch::deserialize(is);
|
37
|
+
REQUIRE(sketch.is_empty() == (n == 0));
|
38
|
+
REQUIRE(sketch.is_estimation_mode() == (n > 1000));
|
39
|
+
REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.03));
|
40
|
+
for (const auto hash: sketch) {
|
41
|
+
REQUIRE(hash < sketch.get_theta64());
|
42
|
+
}
|
43
|
+
REQUIRE(sketch.is_ordered());
|
44
|
+
REQUIRE(std::is_sorted(sketch.begin(), sketch.end()));
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
TEST_CASE("theta sketch non-empty no entries", "[serde_compat]") {
|
49
|
+
std::ifstream is;
|
50
|
+
is.exceptions(std::ios::failbit | std::ios::badbit);
|
51
|
+
is.open(testBinaryInputPath + "theta_non_empty_no_entries_java.sk", std::ios::binary);
|
52
|
+
const auto sketch = compact_theta_sketch::deserialize(is);
|
53
|
+
REQUIRE_FALSE(sketch.is_empty());
|
54
|
+
REQUIRE(sketch.get_num_retained() == 0);
|
55
|
+
}
|
56
|
+
|
57
|
+
} /* namespace datasketches */
|
@@ -0,0 +1,61 @@
|
|
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
|
+
#include <catch2/catch.hpp>
|
21
|
+
#include <fstream>
|
22
|
+
#include <theta_sketch.hpp>
|
23
|
+
|
24
|
+
namespace datasketches {
|
25
|
+
|
26
|
+
TEST_CASE("theta sketch generate", "[serialize_for_java]") {
|
27
|
+
const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
|
28
|
+
for (const unsigned n: n_arr) {
|
29
|
+
auto sketch = update_theta_sketch::builder().build();
|
30
|
+
for (unsigned i = 0; i < n; ++i) sketch.update(i);
|
31
|
+
REQUIRE(sketch.is_empty() == (n == 0));
|
32
|
+
REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.03));
|
33
|
+
std::ofstream os("theta_n" + std::to_string(n) + "_cpp.sk", std::ios::binary);
|
34
|
+
sketch.compact().serialize(os);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
TEST_CASE("theta sketch generate compressed", "[serialize_for_java]") {
|
39
|
+
const unsigned n_arr[] = {10, 100, 1000, 10000, 100000, 1000000};
|
40
|
+
for (const unsigned n: n_arr) {
|
41
|
+
auto sketch = update_theta_sketch::builder().build();
|
42
|
+
for (unsigned i = 0; i < n; ++i) sketch.update(i);
|
43
|
+
REQUIRE_FALSE(sketch.is_empty());
|
44
|
+
REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.03));
|
45
|
+
std::ofstream os("theta_compressed_n" + std::to_string(n) + "_cpp.sk", std::ios::binary);
|
46
|
+
sketch.compact().serialize(os);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
TEST_CASE("theta sketch generate non-empty no entries", "[serialize_for_java]") {
|
51
|
+
auto sketch = update_theta_sketch::builder().set_p(0.01).build();
|
52
|
+
// here we rely on the fact that hash of 1 happens to be greater than 0.01 (when normalized)
|
53
|
+
// and therefore gets rejected
|
54
|
+
sketch.update(1);
|
55
|
+
REQUIRE_FALSE(sketch.is_empty());
|
56
|
+
REQUIRE(sketch.get_num_retained() == 0);
|
57
|
+
std::ofstream os("theta_non_empty_no_entries_cpp.sk", std::ios::binary);
|
58
|
+
sketch.compact().serialize(os);
|
59
|
+
}
|
60
|
+
|
61
|
+
} /* namespace datasketches */
|