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
@@ -33,12 +33,14 @@ class HllSketchImplFactory;
|
|
33
33
|
template<typename A>
|
34
34
|
class CouponList : public HllSketchImpl<A> {
|
35
35
|
public:
|
36
|
+
using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
|
37
|
+
|
36
38
|
CouponList(uint8_t lgConfigK, target_hll_type tgtHllType, hll_mode mode, const A& allocator);
|
37
39
|
CouponList(const CouponList& that, target_hll_type tgtHllType);
|
38
40
|
|
39
41
|
static CouponList* newList(const void* bytes, size_t len, const A& allocator);
|
40
42
|
static CouponList* newList(std::istream& is, const A& allocator);
|
41
|
-
virtual
|
43
|
+
virtual vector_bytes serialize(bool compact, unsigned header_size_bytes) const;
|
42
44
|
virtual void serialize(std::ostream& os, bool compact) const;
|
43
45
|
|
44
46
|
virtual ~CouponList() = default;
|
@@ -51,6 +51,22 @@ Hll4Array<A>::Hll4Array(const Hll4Array<A>& that) :
|
|
51
51
|
}
|
52
52
|
}
|
53
53
|
|
54
|
+
template<typename A>
|
55
|
+
Hll4Array<A>::Hll4Array(const HllArray<A>& other) :
|
56
|
+
HllArray<A>(other.getLgConfigK(), target_hll_type::HLL_4, other.isStartFullSize(), other.getAllocator()),
|
57
|
+
auxHashMap_(nullptr)
|
58
|
+
{
|
59
|
+
const int numBytes = this->hll4ArrBytes(this->lgConfigK_);
|
60
|
+
this->hllByteArr_.resize(numBytes, 0);
|
61
|
+
this->oooFlag_ = other.isOutOfOrderFlag();
|
62
|
+
|
63
|
+
for (const auto coupon : other) { // all = false, so skip empty values
|
64
|
+
internalCouponUpdate(coupon); // updates KxQ registers
|
65
|
+
}
|
66
|
+
this->hipAccum_ = other.getHipAccum();
|
67
|
+
this->rebuild_kxq_curmin_ = false;
|
68
|
+
}
|
69
|
+
|
54
70
|
template<typename A>
|
55
71
|
Hll4Array<A>::~Hll4Array() {
|
56
72
|
// hllByteArr deleted in parent
|
@@ -114,10 +130,9 @@ uint8_t Hll4Array<A>::getSlot(uint32_t slotNo) const {
|
|
114
130
|
}
|
115
131
|
|
116
132
|
template<typename A>
|
117
|
-
uint8_t Hll4Array<A>::
|
118
|
-
const uint8_t value = getSlot(index);
|
133
|
+
uint8_t Hll4Array<A>::adjustRawValue(uint32_t slot, uint8_t value) const {
|
119
134
|
if (value != hll_constants::AUX_TOKEN) return value + this->curMin_;
|
120
|
-
return auxHashMap_->mustFindValueFor(
|
135
|
+
return auxHashMap_->mustFindValueFor(slot);
|
121
136
|
}
|
122
137
|
|
123
138
|
template<typename A>
|
@@ -210,7 +225,7 @@ void Hll4Array<A>::internalHll4Update(uint32_t slotNo, uint8_t newVal) {
|
|
210
225
|
|
211
226
|
// we just increased a pair value, so it might be time to change curMin
|
212
227
|
if (actualOldValue == this->curMin_) { // 908
|
213
|
-
this->
|
228
|
+
--(this->numAtCurMin_);
|
214
229
|
while (this->numAtCurMin_ == 0) {
|
215
230
|
shiftToBiggerCurMin(); // increases curMin by 1, builds a new aux table
|
216
231
|
// shifts values in 4-bit table and recounts curMin
|
@@ -328,13 +343,6 @@ typename HllArray<A>::const_iterator Hll4Array<A>::end() const {
|
|
328
343
|
this->tgtHllType_, auxHashMap_, this->curMin_, false);
|
329
344
|
}
|
330
345
|
|
331
|
-
template<typename A>
|
332
|
-
void Hll4Array<A>::mergeHll(const HllArray<A>& src) {
|
333
|
-
for (const auto coupon: src) {
|
334
|
-
internalCouponUpdate(coupon);
|
335
|
-
}
|
336
|
-
}
|
337
|
-
|
338
346
|
}
|
339
347
|
|
340
348
|
#endif // _HLL4ARRAY_INTERNAL_HPP_
|
@@ -25,14 +25,12 @@
|
|
25
25
|
|
26
26
|
namespace datasketches {
|
27
27
|
|
28
|
-
template<typename A>
|
29
|
-
class Hll4Iterator;
|
30
|
-
|
31
28
|
template<typename A>
|
32
29
|
class Hll4Array final : public HllArray<A> {
|
33
30
|
public:
|
34
31
|
explicit Hll4Array(uint8_t lgConfigK, bool startFullSize, const A& allocator);
|
35
32
|
explicit Hll4Array(const Hll4Array<A>& that);
|
33
|
+
explicit Hll4Array(const HllArray<A>& that);
|
36
34
|
|
37
35
|
virtual ~Hll4Array();
|
38
36
|
virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const;
|
@@ -41,13 +39,12 @@ class Hll4Array final : public HllArray<A> {
|
|
41
39
|
|
42
40
|
inline uint8_t getSlot(uint32_t slotNo) const;
|
43
41
|
inline void putSlot(uint32_t slotNo, uint8_t value);
|
44
|
-
inline uint8_t
|
42
|
+
inline uint8_t adjustRawValue(uint32_t index, uint8_t value) const;
|
45
43
|
|
46
44
|
virtual uint32_t getUpdatableSerializationBytes() const;
|
47
45
|
virtual uint32_t getHllByteArrBytes() const;
|
48
46
|
|
49
47
|
virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon) final;
|
50
|
-
void mergeHll(const HllArray<A>& src);
|
51
48
|
|
52
49
|
virtual AuxHashMap<A>* getAuxHashMap() const;
|
53
50
|
// does *not* delete old map if overwriting
|
@@ -34,6 +34,25 @@ HllArray<A>(lgConfigK, target_hll_type::HLL_6, startFullSize, allocator)
|
|
34
34
|
this->hllByteArr_.resize(numBytes, 0);
|
35
35
|
}
|
36
36
|
|
37
|
+
template<typename A>
|
38
|
+
Hll6Array<A>::Hll6Array(const HllArray<A>& other) :
|
39
|
+
HllArray<A>(other.getLgConfigK(), target_hll_type::HLL_6, other.isStartFullSize(), other.getAllocator())
|
40
|
+
{
|
41
|
+
const int numBytes = this->hll6ArrBytes(this->lgConfigK_);
|
42
|
+
this->hllByteArr_.resize(numBytes, 0);
|
43
|
+
this->oooFlag_ = other.isOutOfOrderFlag();
|
44
|
+
uint32_t num_zeros = 1 << this->lgConfigK_;
|
45
|
+
|
46
|
+
for (const auto coupon : other) { // all = false, so skip empty values
|
47
|
+
num_zeros--;
|
48
|
+
internalCouponUpdate(coupon); // updates KxQ registers
|
49
|
+
}
|
50
|
+
|
51
|
+
this->numAtCurMin_ = num_zeros;
|
52
|
+
this->hipAccum_ = other.getHipAccum();
|
53
|
+
this->rebuild_kxq_curmin_ = false;
|
54
|
+
}
|
55
|
+
|
37
56
|
template<typename A>
|
38
57
|
std::function<void(HllSketchImpl<A>*)> Hll6Array<A>::get_deleter() const {
|
39
58
|
return [](HllSketchImpl<A>* ptr) {
|
@@ -101,13 +120,6 @@ void Hll6Array<A>::internalCouponUpdate(uint32_t coupon) {
|
|
101
120
|
}
|
102
121
|
}
|
103
122
|
|
104
|
-
template<typename A>
|
105
|
-
void Hll6Array<A>::mergeHll(const HllArray<A>& src) {
|
106
|
-
for (const auto coupon: src) {
|
107
|
-
internalCouponUpdate(coupon);
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
123
|
}
|
112
124
|
|
113
125
|
#endif // _HLL6ARRAY_INTERNAL_HPP_
|
@@ -31,6 +31,7 @@ template<typename A>
|
|
31
31
|
class Hll6Array final : public HllArray<A> {
|
32
32
|
public:
|
33
33
|
Hll6Array(uint8_t lgConfigK, bool startFullSize, const A& allocator);
|
34
|
+
explicit Hll6Array(const HllArray<A>& that);
|
34
35
|
|
35
36
|
virtual ~Hll6Array() = default;
|
36
37
|
virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const;
|
@@ -41,7 +42,6 @@ class Hll6Array final : public HllArray<A> {
|
|
41
42
|
inline void putSlot(uint32_t slotNo, uint8_t value);
|
42
43
|
|
43
44
|
virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon) final;
|
44
|
-
void mergeHll(const HllArray<A>& src);
|
45
45
|
|
46
46
|
virtual uint32_t getHllByteArrBytes() const;
|
47
47
|
|
@@ -32,6 +32,25 @@ HllArray<A>(lgConfigK, target_hll_type::HLL_8, startFullSize, allocator)
|
|
32
32
|
this->hllByteArr_.resize(numBytes, 0);
|
33
33
|
}
|
34
34
|
|
35
|
+
template<typename A>
|
36
|
+
Hll8Array<A>::Hll8Array(const HllArray<A>& other):
|
37
|
+
HllArray<A>(other.getLgConfigK(), target_hll_type::HLL_8, other.isStartFullSize(), other.getAllocator())
|
38
|
+
{
|
39
|
+
const int numBytes = this->hll8ArrBytes(this->lgConfigK_);
|
40
|
+
this->hllByteArr_.resize(numBytes, 0);
|
41
|
+
this->oooFlag_ = other.isOutOfOrderFlag();
|
42
|
+
uint32_t num_zeros = 1 << this->lgConfigK_;
|
43
|
+
|
44
|
+
for (const auto coupon : other) { // all = false, so skip empty values
|
45
|
+
num_zeros--;
|
46
|
+
internalCouponUpdate(coupon); // updates KxQ registers
|
47
|
+
}
|
48
|
+
|
49
|
+
this->numAtCurMin_ = num_zeros;
|
50
|
+
this->hipAccum_ = other.getHipAccum();
|
51
|
+
this->rebuild_kxq_curmin_ = false;
|
52
|
+
}
|
53
|
+
|
35
54
|
template<typename A>
|
36
55
|
std::function<void(HllSketchImpl<A>*)> Hll8Array<A>::get_deleter() const {
|
37
56
|
return [](HllSketchImpl<A>* ptr) {
|
@@ -77,13 +96,11 @@ void Hll8Array<A>::internalCouponUpdate(uint32_t coupon) {
|
|
77
96
|
const uint32_t slotNo = HllUtil<A>::getLow26(coupon) & configKmask;
|
78
97
|
const uint8_t newVal = HllUtil<A>::getValue(coupon);
|
79
98
|
|
80
|
-
const uint8_t curVal =
|
99
|
+
const uint8_t curVal = this->hllByteArr_[slotNo];
|
81
100
|
if (newVal > curVal) {
|
82
|
-
|
101
|
+
this->hllByteArr_[slotNo] = newVal;
|
83
102
|
this->hipAndKxQIncrementalUpdate(curVal, newVal);
|
84
|
-
|
85
|
-
this->numAtCurMin_--; // interpret numAtCurMin as num zeros
|
86
|
-
}
|
103
|
+
this->numAtCurMin_ -= curVal == 0; // interpret numAtCurMin as num zeros
|
87
104
|
}
|
88
105
|
}
|
89
106
|
|
@@ -97,49 +114,88 @@ void Hll8Array<A>::mergeList(const CouponList<A>& src) {
|
|
97
114
|
template<typename A>
|
98
115
|
void Hll8Array<A>::mergeHll(const HllArray<A>& src) {
|
99
116
|
// at this point src_k >= dst_k
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
const uint8_t old_v = this->hllByteArr_[j];
|
108
|
-
if (new_v > old_v) {
|
109
|
-
this->hllByteArr_[j] = new_v;
|
110
|
-
this->hipAndKxQIncrementalUpdate(old_v, new_v);
|
111
|
-
if (old_v == 0) {
|
112
|
-
this->numAtCurMin_--;
|
113
|
-
}
|
117
|
+
// we can optimize further when the k values are equal
|
118
|
+
if (this->getLgConfigK() == src.getLgConfigK()) {
|
119
|
+
if (src.getTgtHllType() == target_hll_type::HLL_8) {
|
120
|
+
uint32_t i = 0;
|
121
|
+
for (const auto value: src.getHllArray()) {
|
122
|
+
this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
|
123
|
+
++i;
|
114
124
|
}
|
115
|
-
}
|
116
|
-
|
117
|
-
|
118
|
-
const uint8_t
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
125
|
+
} else if (src.getTgtHllType() == target_hll_type::HLL_6) {
|
126
|
+
const uint32_t src_k = 1 << src.getLgConfigK();
|
127
|
+
uint32_t i = 0;
|
128
|
+
const uint8_t* ptr = src.getHllArray().data();
|
129
|
+
while (i < src_k) {
|
130
|
+
uint8_t value = *ptr & 0x3f;
|
131
|
+
this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
|
132
|
+
++i;
|
133
|
+
value = *ptr++ >> 6;
|
134
|
+
value |= (*ptr & 0x0f) << 2;
|
135
|
+
this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
|
136
|
+
++i;
|
137
|
+
value = *ptr++ >> 4;
|
138
|
+
value |= (*ptr & 3) << 4;
|
139
|
+
this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
|
140
|
+
++i;
|
141
|
+
value = *ptr++ >> 2;
|
142
|
+
this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
|
143
|
+
++i;
|
144
|
+
}
|
145
|
+
} else { // HLL_4
|
146
|
+
const auto& src4 = static_cast<const Hll4Array<A>&>(src);
|
147
|
+
uint32_t i = 0;
|
148
|
+
for (const auto byte: src.getHllArray()) {
|
149
|
+
this->hllByteArr_[i] = std::max(this->hllByteArr_[i], src4.adjustRawValue(i, byte & hll_constants::loNibbleMask));
|
150
|
+
++i;
|
151
|
+
this->hllByteArr_[i] = std::max(this->hllByteArr_[i], src4.adjustRawValue(i, byte >> 4));
|
152
|
+
++i;
|
127
153
|
}
|
128
154
|
}
|
129
|
-
} else {
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
155
|
+
} else {
|
156
|
+
// src_k > dst_k
|
157
|
+
const uint32_t dst_mask = (1 << this->getLgConfigK()) - 1;
|
158
|
+
// special treatment below to optimize performance
|
159
|
+
if (src.getTgtHllType() == target_hll_type::HLL_8) {
|
160
|
+
uint32_t i = 0;
|
161
|
+
for (const auto value: src.getHllArray()) {
|
162
|
+
processValue(i++, dst_mask, value);
|
163
|
+
}
|
164
|
+
} else if (src.getTgtHllType() == target_hll_type::HLL_6) {
|
165
|
+
const uint32_t src_k = 1 << src.getLgConfigK();
|
166
|
+
uint32_t i = 0;
|
167
|
+
const uint8_t* ptr = src.getHllArray().data();
|
168
|
+
while (i < src_k) {
|
169
|
+
uint8_t value = *ptr & 0x3f;
|
170
|
+
processValue(i++, dst_mask, value);
|
171
|
+
value = *ptr++ >> 6;
|
172
|
+
value |= (*ptr & 0x0f) << 2;
|
173
|
+
processValue(i++, dst_mask, value);
|
174
|
+
value = *ptr++ >> 4;
|
175
|
+
value |= (*ptr & 3) << 4;
|
176
|
+
processValue(i++, dst_mask, value);
|
177
|
+
value = *ptr++ >> 2;
|
178
|
+
processValue(i++, dst_mask, value);
|
179
|
+
}
|
180
|
+
} else { // HLL_4
|
181
|
+
const auto& src4 = static_cast<const Hll4Array<A>&>(src);
|
182
|
+
uint32_t i = 0;
|
183
|
+
for (const auto byte: src.getHllArray()) {
|
184
|
+
processValue(i, dst_mask, src4.adjustRawValue(i, byte & hll_constants::loNibbleMask));
|
185
|
+
++i;
|
186
|
+
processValue(i, dst_mask, src4.adjustRawValue(i, byte >> 4));
|
187
|
+
++i;
|
140
188
|
}
|
141
189
|
}
|
142
190
|
}
|
191
|
+
this->setRebuildKxqCurminFlag(true);
|
192
|
+
}
|
193
|
+
|
194
|
+
|
195
|
+
template<typename A>
|
196
|
+
void Hll8Array<A>::processValue(uint32_t slot, uint32_t mask, uint8_t new_val) {
|
197
|
+
const size_t index = slot & mask;
|
198
|
+
this->hllByteArr_[index] = std::max(this->hllByteArr_[index], new_val);
|
143
199
|
}
|
144
200
|
|
145
201
|
}
|
@@ -31,6 +31,7 @@ template<typename A>
|
|
31
31
|
class Hll8Array final : public HllArray<A> {
|
32
32
|
public:
|
33
33
|
Hll8Array(uint8_t lgConfigK, bool startFullSize, const A& allocator);
|
34
|
+
explicit Hll8Array(const HllArray<A>& that);
|
34
35
|
|
35
36
|
virtual ~Hll8Array() = default;
|
36
37
|
virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const;
|
@@ -48,6 +49,7 @@ class Hll8Array final : public HllArray<A> {
|
|
48
49
|
|
49
50
|
private:
|
50
51
|
inline void internalCouponUpdate(uint32_t coupon);
|
52
|
+
inline void processValue(uint32_t slot, uint32_t mask, uint8_t new_val);
|
51
53
|
};
|
52
54
|
|
53
55
|
}
|
@@ -43,20 +43,44 @@ kxq1_(0.0),
|
|
43
43
|
hllByteArr_(allocator),
|
44
44
|
curMin_(0),
|
45
45
|
numAtCurMin_(1 << lgConfigK),
|
46
|
-
oooFlag_(false)
|
46
|
+
oooFlag_(false),
|
47
|
+
rebuild_kxq_curmin_(false)
|
48
|
+
{}
|
49
|
+
|
50
|
+
template<typename A>
|
51
|
+
HllArray<A>::HllArray(const HllArray& other, target_hll_type tgtHllType) :
|
52
|
+
HllSketchImpl<A>(other.getLgConfigK(), tgtHllType, hll_mode::HLL, other.isStartFullSize()),
|
53
|
+
// remaining fields are initialized to empty sketch defaults
|
54
|
+
// and left to subclass constructor to populate
|
55
|
+
hipAccum_(0.0),
|
56
|
+
kxq0_(1 << other.getLgConfigK()),
|
57
|
+
kxq1_(0.0),
|
58
|
+
hllByteArr_(other.getAllocator()),
|
59
|
+
curMin_(0),
|
60
|
+
numAtCurMin_(1 << other.getLgConfigK()),
|
61
|
+
oooFlag_(false),
|
62
|
+
rebuild_kxq_curmin_(false)
|
47
63
|
{}
|
48
64
|
|
49
65
|
template<typename A>
|
50
66
|
HllArray<A>* HllArray<A>::copyAs(target_hll_type tgtHllType) const {
|
51
|
-
|
67
|
+
// we may need to recompute KxQ and curMin data for a union gadget,
|
68
|
+
// so only use a direct copy if we have a valid sketch
|
69
|
+
if (tgtHllType == this->getTgtHllType() && !this->isRebuildKxqCurminFlag()) {
|
52
70
|
return static_cast<HllArray*>(copy());
|
53
71
|
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
72
|
+
|
73
|
+
// the factory methods replay the coupons and will always rebuild
|
74
|
+
// the sketch in a consistent way
|
75
|
+
switch (tgtHllType) {
|
76
|
+
case target_hll_type::HLL_4:
|
77
|
+
return HllSketchImplFactory<A>::convertToHll4(*this);
|
78
|
+
case target_hll_type::HLL_6:
|
79
|
+
return HllSketchImplFactory<A>::convertToHll6(*this);
|
80
|
+
case target_hll_type::HLL_8:
|
81
|
+
return HllSketchImplFactory<A>::convertToHll8(*this);
|
82
|
+
default:
|
83
|
+
throw std::invalid_argument("Invalid target HLL type");
|
60
84
|
}
|
61
85
|
}
|
62
86
|
|
@@ -192,9 +216,9 @@ HllArray<A>* HllArray<A>::newHll(std::istream& is, const A& allocator) {
|
|
192
216
|
}
|
193
217
|
|
194
218
|
template<typename A>
|
195
|
-
|
219
|
+
auto HllArray<A>::serialize(bool compact, unsigned header_size_bytes) const -> vector_bytes {
|
196
220
|
const size_t sketchSizeBytes = (compact ? getCompactSerializationBytes() : getUpdatableSerializationBytes()) + header_size_bytes;
|
197
|
-
|
221
|
+
vector_bytes byteArr(sketchSizeBytes, 0, getAllocator());
|
198
222
|
uint8_t* bytes = byteArr.data() + header_size_bytes;
|
199
223
|
AuxHashMap<A>* auxHashMap = getAuxHashMap();
|
200
224
|
|
@@ -299,7 +323,7 @@ double HllArray<A>::getEstimate() const {
|
|
299
323
|
if (oooFlag_) {
|
300
324
|
return getCompositeEstimate();
|
301
325
|
}
|
302
|
-
return
|
326
|
+
return hipAccum_;
|
303
327
|
}
|
304
328
|
|
305
329
|
// HLL UPPER AND LOWER BOUNDS
|
@@ -322,54 +346,20 @@ double HllArray<A>::getLowerBound(uint8_t numStdDev) const {
|
|
322
346
|
HllUtil<A>::checkNumStdDev(numStdDev);
|
323
347
|
const uint32_t configK = 1 << this->lgConfigK_;
|
324
348
|
const double numNonZeros = ((curMin_ == 0) ? (configK - numAtCurMin_) : configK);
|
325
|
-
|
326
|
-
|
327
|
-
double rseFactor;
|
328
|
-
if (oooFlag_) {
|
329
|
-
estimate = getCompositeEstimate();
|
330
|
-
rseFactor = hll_constants::HLL_NON_HIP_RSE_FACTOR;
|
331
|
-
} else {
|
332
|
-
estimate = hipAccum_;
|
333
|
-
rseFactor = hll_constants::HLL_HIP_RSE_FACTOR;
|
334
|
-
}
|
335
|
-
|
336
|
-
double relErr;
|
337
|
-
if (this->lgConfigK_ > 12) {
|
338
|
-
relErr = (numStdDev * rseFactor) / sqrt(configK);
|
339
|
-
} else {
|
340
|
-
relErr = HllUtil<A>::getRelErr(false, oooFlag_, this->lgConfigK_, numStdDev);
|
341
|
-
}
|
342
|
-
return fmax(estimate / (1.0 + relErr), numNonZeros);
|
349
|
+
const double relErr = HllUtil<A>::getRelErr(false, this->oooFlag_, this->lgConfigK_, numStdDev);
|
350
|
+
return fmax(getEstimate() / (1.0 + relErr), numNonZeros);
|
343
351
|
}
|
344
352
|
|
345
353
|
template<typename A>
|
346
354
|
double HllArray<A>::getUpperBound(uint8_t numStdDev) const {
|
347
355
|
HllUtil<A>::checkNumStdDev(numStdDev);
|
348
|
-
const
|
349
|
-
|
350
|
-
double estimate;
|
351
|
-
double rseFactor;
|
352
|
-
if (oooFlag_) {
|
353
|
-
estimate = getCompositeEstimate();
|
354
|
-
rseFactor = hll_constants::HLL_NON_HIP_RSE_FACTOR;
|
355
|
-
} else {
|
356
|
-
estimate = hipAccum_;
|
357
|
-
rseFactor = hll_constants::HLL_HIP_RSE_FACTOR;
|
358
|
-
}
|
359
|
-
|
360
|
-
double relErr;
|
361
|
-
if (this->lgConfigK_ > 12) {
|
362
|
-
relErr = (-1.0) * (numStdDev * rseFactor) / sqrt(configK);
|
363
|
-
} else {
|
364
|
-
relErr = HllUtil<A>::getRelErr(true, oooFlag_, this->lgConfigK_, numStdDev);
|
365
|
-
}
|
366
|
-
return estimate / (1.0 + relErr);
|
356
|
+
const double relErr = HllUtil<A>::getRelErr(true, this->oooFlag_, this->lgConfigK_, numStdDev);
|
357
|
+
return getEstimate() / (1.0 + relErr);
|
367
358
|
}
|
368
359
|
|
369
360
|
/**
|
370
361
|
* This is the (non-HIP) estimator.
|
371
362
|
* It is called "composite" because multiple estimators are pasted together.
|
372
|
-
* @param absHllArr an instance of the AbstractHllArray class.
|
373
363
|
* @return the composite estimate
|
374
364
|
*/
|
375
365
|
// Original C: again-two-registers.c hhb_get_composite_estimate L1489
|
@@ -468,16 +458,6 @@ void HllArray<A>::putNumAtCurMin(uint32_t numAtCurMin) {
|
|
468
458
|
numAtCurMin_ = numAtCurMin;
|
469
459
|
}
|
470
460
|
|
471
|
-
template<typename A>
|
472
|
-
void HllArray<A>::decNumAtCurMin() {
|
473
|
-
--numAtCurMin_;
|
474
|
-
}
|
475
|
-
|
476
|
-
template<typename A>
|
477
|
-
void HllArray<A>::addToHipAccum(double delta) {
|
478
|
-
hipAccum_ += delta;
|
479
|
-
}
|
480
|
-
|
481
461
|
template<typename A>
|
482
462
|
bool HllArray<A>::isCompact() const {
|
483
463
|
return false;
|
@@ -486,7 +466,7 @@ bool HllArray<A>::isCompact() const {
|
|
486
466
|
template<typename A>
|
487
467
|
bool HllArray<A>::isEmpty() const {
|
488
468
|
const uint32_t configK = 1 << this->lgConfigK_;
|
489
|
-
return (
|
469
|
+
return (curMin_ == 0) && (numAtCurMin_ == configK);
|
490
470
|
}
|
491
471
|
|
492
472
|
template<typename A>
|
@@ -556,6 +536,11 @@ AuxHashMap<A>* HllArray<A>::getAuxHashMap() const {
|
|
556
536
|
return nullptr;
|
557
537
|
}
|
558
538
|
|
539
|
+
template<typename A>
|
540
|
+
auto HllArray<A>::getHllArray() const -> const vector_bytes& {
|
541
|
+
return hllByteArr_;
|
542
|
+
}
|
543
|
+
|
559
544
|
template<typename A>
|
560
545
|
void HllArray<A>::hipAndKxQIncrementalUpdate(uint8_t oldValue, uint8_t newValue) {
|
561
546
|
const uint32_t configK = 1 << this->getLgConfigK();
|
@@ -601,6 +586,52 @@ double HllArray<A>::getHllRawEstimate() const {
|
|
601
586
|
return hyperEst;
|
602
587
|
}
|
603
588
|
|
589
|
+
template<typename A>
|
590
|
+
void HllArray<A>::setRebuildKxqCurminFlag(bool rebuild) {
|
591
|
+
rebuild_kxq_curmin_ = rebuild;
|
592
|
+
}
|
593
|
+
|
594
|
+
template<typename A>
|
595
|
+
bool HllArray<A>::isRebuildKxqCurminFlag() const {
|
596
|
+
return rebuild_kxq_curmin_;
|
597
|
+
}
|
598
|
+
|
599
|
+
template<typename A>
|
600
|
+
void HllArray<A>::check_rebuild_kxq_cur_min() {
|
601
|
+
if (!rebuild_kxq_curmin_) { return; }
|
602
|
+
|
603
|
+
uint8_t cur_min = 64;
|
604
|
+
uint32_t num_at_cur_min = 0;
|
605
|
+
double kxq0 = 1 << this->lgConfigK_;
|
606
|
+
double kxq1 = 0;
|
607
|
+
|
608
|
+
auto it = this->begin(true); // want all points to adjust cur_min
|
609
|
+
const auto end = this->end();
|
610
|
+
while (it != end) {
|
611
|
+
uint8_t v = HllUtil<A>::getValue(*it);
|
612
|
+
if (v > 0) {
|
613
|
+
if (v < 32) { kxq0 += INVERSE_POWERS_OF_2[v] - 1.0; }
|
614
|
+
else { kxq1 += INVERSE_POWERS_OF_2[v] - 1.0; }
|
615
|
+
}
|
616
|
+
if (v > cur_min) { ++it; continue; }
|
617
|
+
if (v < cur_min) {
|
618
|
+
cur_min = v;
|
619
|
+
num_at_cur_min = 1;
|
620
|
+
} else {
|
621
|
+
++num_at_cur_min;
|
622
|
+
}
|
623
|
+
++it;
|
624
|
+
}
|
625
|
+
|
626
|
+
kxq0_ = kxq0;
|
627
|
+
kxq1_ = kxq1;
|
628
|
+
curMin_ = cur_min;
|
629
|
+
numAtCurMin_ = num_at_cur_min;
|
630
|
+
rebuild_kxq_curmin_ = false;
|
631
|
+
// HipAccum is not affected
|
632
|
+
|
633
|
+
}
|
634
|
+
|
604
635
|
template<typename A>
|
605
636
|
typename HllArray<A>::const_iterator HllArray<A>::begin(bool all) const {
|
606
637
|
return const_iterator(hllByteArr_.data(), 1 << this->lgConfigK_, 0, this->tgtHllType_, nullptr, 0, all);
|
@@ -637,12 +668,14 @@ bool HllArray<A>::const_iterator::operator!=(const const_iterator& other) const
|
|
637
668
|
}
|
638
669
|
|
639
670
|
template<typename A>
|
640
|
-
|
671
|
+
auto HllArray<A>::const_iterator::operator*() const -> reference {
|
641
672
|
return HllUtil<A>::pair(index_, value_);
|
642
673
|
}
|
643
674
|
|
644
675
|
template<typename A>
|
645
676
|
uint8_t HllArray<A>::const_iterator::get_value(const uint8_t* array, uint32_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset) {
|
677
|
+
// TODO: we should be able to improve efficiency here by reading multiple bytes at a time
|
678
|
+
// for HLL4 and HLL6
|
646
679
|
if (hll_type == target_hll_type::HLL_4) {
|
647
680
|
uint8_t value = array[index >> 1];
|
648
681
|
if ((index & 1) > 0) { // odd
|
@@ -31,12 +31,15 @@ class AuxHashMap;
|
|
31
31
|
template<typename A>
|
32
32
|
class HllArray : public HllSketchImpl<A> {
|
33
33
|
public:
|
34
|
+
using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
|
35
|
+
|
34
36
|
HllArray(uint8_t lgConfigK, target_hll_type tgtHllType, bool startFullSize, const A& allocator);
|
37
|
+
explicit HllArray(const HllArray& other, target_hll_type tgtHllType);
|
35
38
|
|
36
39
|
static HllArray* newHll(const void* bytes, size_t len, const A& allocator);
|
37
40
|
static HllArray* newHll(std::istream& is, const A& allocator);
|
38
41
|
|
39
|
-
virtual
|
42
|
+
virtual vector_bytes serialize(bool compact, unsigned header_size_bytes) const;
|
40
43
|
virtual void serialize(std::ostream& os, bool compact) const;
|
41
44
|
|
42
45
|
virtual ~HllArray() = default;
|
@@ -52,10 +55,6 @@ class HllArray : public HllSketchImpl<A> {
|
|
52
55
|
virtual double getLowerBound(uint8_t numStdDev) const;
|
53
56
|
virtual double getUpperBound(uint8_t numStdDev) const;
|
54
57
|
|
55
|
-
inline void addToHipAccum(double delta);
|
56
|
-
|
57
|
-
inline void decNumAtCurMin();
|
58
|
-
|
59
58
|
inline uint8_t getCurMin() const;
|
60
59
|
inline uint32_t getNumAtCurMin() const;
|
61
60
|
inline double getHipAccum() const;
|
@@ -90,12 +89,18 @@ class HllArray : public HllSketchImpl<A> {
|
|
90
89
|
|
91
90
|
virtual AuxHashMap<A>* getAuxHashMap() const;
|
92
91
|
|
92
|
+
void setRebuildKxqCurminFlag(bool rebuild);
|
93
|
+
bool isRebuildKxqCurminFlag() const;
|
94
|
+
void check_rebuild_kxq_cur_min();
|
95
|
+
|
93
96
|
class const_iterator;
|
94
97
|
virtual const_iterator begin(bool all = false) const;
|
95
98
|
virtual const_iterator end() const;
|
96
99
|
|
97
100
|
virtual A getAllocator() const;
|
98
101
|
|
102
|
+
const vector_bytes& getHllArray() const;
|
103
|
+
|
99
104
|
protected:
|
100
105
|
void hipAndKxQIncrementalUpdate(uint8_t oldValue, uint8_t newValue);
|
101
106
|
double getHllBitMapEstimate() const;
|
@@ -104,21 +109,28 @@ class HllArray : public HllSketchImpl<A> {
|
|
104
109
|
double hipAccum_;
|
105
110
|
double kxq0_;
|
106
111
|
double kxq1_;
|
107
|
-
|
112
|
+
vector_bytes hllByteArr_; //init by sub-classes
|
108
113
|
uint8_t curMin_; //always zero for Hll6 and Hll8, only tracked by Hll4Array
|
109
114
|
uint32_t numAtCurMin_; //interpreted as num zeros when curMin == 0
|
110
115
|
bool oooFlag_; //Out-Of-Order Flag
|
116
|
+
bool rebuild_kxq_curmin_; // flag to recompute
|
111
117
|
|
112
118
|
friend class HllSketchImplFactory<A>;
|
113
119
|
};
|
114
120
|
|
115
121
|
template<typename A>
|
116
|
-
class HllArray<A>::const_iterator
|
122
|
+
class HllArray<A>::const_iterator {
|
117
123
|
public:
|
124
|
+
using iterator_category = std::input_iterator_tag;
|
125
|
+
using value_type = uint32_t;
|
126
|
+
using difference_type = void;
|
127
|
+
using pointer = uint32_t*;
|
128
|
+
using reference = uint32_t;
|
129
|
+
|
118
130
|
const_iterator(const uint8_t* array, uint32_t array_slze, uint32_t index, target_hll_type hll_type, const AuxHashMap<A>* exceptions, uint8_t offset, bool all);
|
119
131
|
const_iterator& operator++();
|
120
132
|
bool operator!=(const const_iterator& other) const;
|
121
|
-
|
133
|
+
reference operator*() const;
|
122
134
|
private:
|
123
135
|
const uint8_t* array_;
|
124
136
|
uint32_t array_size_;
|