datasketches 0.1.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/LICENSE +40 -3
- data/NOTICE +1 -1
- 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 +10 -0
- data/vendor/datasketches-cpp/LICENSE +40 -3
- data/vendor/datasketches-cpp/NOTICE +1 -1
- data/vendor/datasketches-cpp/README.md +4 -4
- data/vendor/datasketches-cpp/common/include/MurmurHash3.h +18 -7
- data/vendor/datasketches-cpp/common/include/binomial_bounds.hpp +8 -8
- data/vendor/datasketches-cpp/common/include/bounds_binomial_proportions.hpp +12 -15
- data/vendor/datasketches-cpp/common/include/common_defs.hpp +26 -0
- data/vendor/datasketches-cpp/common/include/conditional_forward.hpp +20 -8
- data/vendor/datasketches-cpp/common/include/count_zeros.hpp +2 -2
- data/vendor/datasketches-cpp/common/include/memory_operations.hpp +12 -0
- data/vendor/datasketches-cpp/common/include/serde.hpp +7 -7
- 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 +13 -3
- data/vendor/datasketches-cpp/cpc/include/cpc_compressor.hpp +20 -20
- data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +116 -105
- data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +22 -6
- data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +140 -101
- data/vendor/datasketches-cpp/cpc/include/cpc_union.hpp +2 -2
- data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +20 -20
- data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +10 -16
- data/vendor/datasketches-cpp/cpc/include/icon_estimator.hpp +6 -6
- data/vendor/datasketches-cpp/cpc/include/u32_table.hpp +10 -10
- data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +21 -21
- data/vendor/datasketches-cpp/cpc/test/CMakeLists.txt +1 -0
- data/vendor/datasketches-cpp/cpc/test/compression_test.cpp +10 -10
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_allocation_test.cpp +237 -0
- data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +25 -0
- data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +1 -1
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +15 -10
- data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +102 -105
- 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 +141 -125
- 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 +5 -5
- data/vendor/datasketches-cpp/hll/CMakeLists.txt +3 -0
- data/vendor/datasketches-cpp/hll/include/AuxHashMap-internal.hpp +81 -109
- data/vendor/datasketches-cpp/hll/include/AuxHashMap.hpp +25 -24
- data/vendor/datasketches-cpp/hll/include/CompositeInterpolationXTable-internal.hpp +15 -15
- data/vendor/datasketches-cpp/hll/include/CompositeInterpolationXTable.hpp +5 -5
- data/vendor/datasketches-cpp/hll/include/CouponHashSet-internal.hpp +89 -105
- data/vendor/datasketches-cpp/hll/include/CouponHashSet.hpp +13 -13
- data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +130 -165
- data/vendor/datasketches-cpp/hll/include/CouponList.hpp +21 -22
- data/vendor/datasketches-cpp/hll/include/CubicInterpolation-internal.hpp +2 -4
- data/vendor/datasketches-cpp/hll/include/CubicInterpolation.hpp +2 -2
- data/vendor/datasketches-cpp/hll/include/HarmonicNumbers-internal.hpp +1 -1
- data/vendor/datasketches-cpp/hll/include/HarmonicNumbers.hpp +2 -2
- data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +88 -83
- data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +9 -9
- data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +34 -45
- data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +7 -8
- data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +41 -52
- data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +7 -8
- data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +220 -251
- data/vendor/datasketches-cpp/hll/include/HllArray.hpp +42 -42
- data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +36 -38
- data/vendor/datasketches-cpp/hll/include/HllSketchImpl-internal.hpp +22 -22
- data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +15 -14
- data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +47 -44
- data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +62 -87
- data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +121 -128
- data/vendor/datasketches-cpp/hll/include/RelativeErrorTables.hpp +1 -1
- data/vendor/datasketches-cpp/hll/include/coupon_iterator-internal.hpp +9 -9
- data/vendor/datasketches-cpp/hll/include/coupon_iterator.hpp +5 -5
- data/vendor/datasketches-cpp/hll/include/hll.hpp +25 -53
- data/vendor/datasketches-cpp/hll/test/AuxHashMapTest.cpp +8 -8
- data/vendor/datasketches-cpp/hll/test/CouponHashSetTest.cpp +36 -36
- data/vendor/datasketches-cpp/hll/test/CouponListTest.cpp +28 -28
- data/vendor/datasketches-cpp/hll/test/CrossCountingTest.cpp +2 -2
- data/vendor/datasketches-cpp/hll/test/HllArrayTest.cpp +37 -37
- data/vendor/datasketches-cpp/hll/test/HllSketchTest.cpp +57 -61
- data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +10 -14
- data/vendor/datasketches-cpp/hll/test/IsomorphicTest.cpp +3 -3
- data/vendor/datasketches-cpp/hll/test/ToFromByteArrayTest.cpp +4 -4
- data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +5 -4
- data/vendor/datasketches-cpp/kll/include/kll_helper_impl.hpp +6 -6
- data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator.hpp +14 -6
- data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator_impl.hpp +40 -25
- data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +50 -6
- data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +164 -136
- data/vendor/datasketches-cpp/kll/include/kolmogorov_smirnov.hpp +67 -0
- data/vendor/datasketches-cpp/kll/include/kolmogorov_smirnov_impl.hpp +78 -0
- data/vendor/datasketches-cpp/kll/test/CMakeLists.txt +1 -0
- data/vendor/datasketches-cpp/kll/test/kll_sketch_custom_type_test.cpp +11 -10
- data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +178 -88
- data/vendor/datasketches-cpp/kll/test/kolmogorov_smirnov_test.cpp +111 -0
- data/vendor/datasketches-cpp/pyproject.toml +4 -2
- data/vendor/datasketches-cpp/python/CMakeLists.txt +12 -6
- data/vendor/datasketches-cpp/python/README.md +52 -49
- data/vendor/datasketches-cpp/python/pybind11Path.cmd +3 -0
- data/vendor/datasketches-cpp/python/src/cpc_wrapper.cpp +1 -1
- data/vendor/datasketches-cpp/python/src/datasketches.cpp +2 -0
- data/vendor/datasketches-cpp/python/src/hll_wrapper.cpp +4 -6
- data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +4 -2
- data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +246 -0
- data/vendor/datasketches-cpp/python/src/theta_wrapper.cpp +38 -28
- data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +11 -5
- data/vendor/datasketches-cpp/python/src/vo_wrapper.cpp +2 -2
- data/vendor/datasketches-cpp/python/tests/hll_test.py +1 -2
- data/vendor/datasketches-cpp/python/tests/kll_test.py +5 -5
- 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/python/tests/vector_of_kll_test.py +4 -4
- data/vendor/datasketches-cpp/python/tests/vo_test.py +3 -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} +18 -8
- data/vendor/datasketches-cpp/req/include/req_compactor.hpp +137 -0
- data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +488 -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 +19 -13
- data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +130 -127
- data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +5 -5
- data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +41 -49
- 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_sketch_test.cpp +6 -6
- data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +13 -44
- data/vendor/datasketches-cpp/setup.py +11 -6
- data/vendor/datasketches-cpp/theta/CMakeLists.txt +30 -3
- data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_sampled_sets.hpp +3 -2
- data/vendor/datasketches-cpp/{tuple → theta}/include/bounds_on_ratios_in_theta_sketched_sets.hpp +1 -1
- data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser.hpp +67 -0
- data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser_impl.hpp +70 -0
- 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 +11 -4
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_helpers.hpp +0 -0
- data/vendor/datasketches-cpp/theta/include/theta_intersection.hpp +26 -28
- 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} +24 -36
- 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 +163 -256
- data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +250 -651
- 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 +6 -1
- data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +13 -69
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base.hpp +10 -21
- data/vendor/datasketches-cpp/{tuple → theta}/include/theta_update_sketch_base_impl.hpp +44 -30
- data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +1 -0
- data/vendor/datasketches-cpp/theta/test/theta_a_not_b_test.cpp +23 -1
- data/vendor/datasketches-cpp/theta/test/theta_intersection_test.cpp +21 -1
- data/vendor/datasketches-cpp/{tuple → theta}/test/theta_jaccard_similarity_test.cpp +60 -5
- data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +74 -235
- data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +22 -2
- data/vendor/datasketches-cpp/tuple/CMakeLists.txt +3 -35
- data/vendor/datasketches-cpp/tuple/include/array_of_doubles_sketch_impl.hpp +47 -60
- 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 +57 -70
- data/vendor/datasketches-cpp/tuple/test/CMakeLists.txt +1 -6
- data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +1 -1
- data/vendor/datasketches-cpp/tuple/test/tuple_a_not_b_test.cpp +18 -21
- data/vendor/datasketches-cpp/tuple/test/tuple_intersection_test.cpp +13 -16
- data/vendor/datasketches-cpp/tuple/test/tuple_jaccard_similarity_test.cpp +7 -6
- data/vendor/datasketches-cpp/tuple/test/tuple_sketch_allocation_test.cpp +3 -3
- data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +20 -20
- data/vendor/datasketches-cpp/tuple/test/tuple_union_test.cpp +13 -16
- metadata +51 -36
- 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
@@ -28,11 +28,11 @@
|
|
28
28
|
namespace datasketches {
|
29
29
|
|
30
30
|
template<typename A>
|
31
|
-
static
|
31
|
+
static int32_t find(const uint32_t* array, uint8_t lgArrInts, uint32_t coupon);
|
32
32
|
|
33
33
|
template<typename A>
|
34
|
-
CouponHashSet<A>::CouponHashSet(
|
35
|
-
: CouponList<A>(lgConfigK, tgtHllType, hll_mode::SET)
|
34
|
+
CouponHashSet<A>::CouponHashSet(uint8_t lgConfigK, target_hll_type tgtHllType, const A& allocator)
|
35
|
+
: CouponList<A>(lgConfigK, tgtHllType, hll_mode::SET, allocator)
|
36
36
|
{
|
37
37
|
if (lgConfigK <= 7) {
|
38
38
|
throw std::invalid_argument("CouponHashSet must be initialized with lgConfigK > 7. Found: "
|
@@ -40,154 +40,140 @@ CouponHashSet<A>::CouponHashSet(const int lgConfigK, const target_hll_type tgtHl
|
|
40
40
|
}
|
41
41
|
}
|
42
42
|
|
43
|
-
template<typename A>
|
44
|
-
CouponHashSet<A>::CouponHashSet(const CouponHashSet<A>& that)
|
45
|
-
: CouponList<A>(that) {}
|
46
|
-
|
47
43
|
template<typename A>
|
48
44
|
CouponHashSet<A>::CouponHashSet(const CouponHashSet<A>& that, const target_hll_type tgtHllType)
|
49
45
|
: CouponList<A>(that, tgtHllType) {}
|
50
46
|
|
51
|
-
template<typename A>
|
52
|
-
CouponHashSet<A>::~CouponHashSet() {}
|
53
|
-
|
54
47
|
template<typename A>
|
55
48
|
std::function<void(HllSketchImpl<A>*)> CouponHashSet<A>::get_deleter() const {
|
56
49
|
return [](HllSketchImpl<A>* ptr) {
|
57
50
|
CouponHashSet<A>* chs = static_cast<CouponHashSet<A>*>(ptr);
|
51
|
+
ChsAlloc chsa(chs->getAllocator());
|
58
52
|
chs->~CouponHashSet();
|
59
|
-
|
53
|
+
chsa.deallocate(chs, 1);
|
60
54
|
};
|
61
55
|
}
|
62
56
|
|
63
57
|
template<typename A>
|
64
|
-
CouponHashSet<A>* CouponHashSet<A>::newSet(const void* bytes, size_t len) {
|
65
|
-
if (len <
|
58
|
+
CouponHashSet<A>* CouponHashSet<A>::newSet(const void* bytes, size_t len, const A& allocator) {
|
59
|
+
if (len < hll_constants::HASH_SET_INT_ARR_START) { // hard-coded
|
66
60
|
throw std::out_of_range("Input data length insufficient to hold CouponHashSet");
|
67
61
|
}
|
68
62
|
|
69
63
|
const uint8_t* data = static_cast<const uint8_t*>(bytes);
|
70
|
-
if (data[
|
64
|
+
if (data[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::HASH_SET_PREINTS) {
|
71
65
|
throw std::invalid_argument("Incorrect number of preInts in input stream");
|
72
66
|
}
|
73
|
-
if (data[
|
67
|
+
if (data[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
|
74
68
|
throw std::invalid_argument("Wrong ser ver in input stream");
|
75
69
|
}
|
76
|
-
if (data[
|
70
|
+
if (data[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
|
77
71
|
throw std::invalid_argument("Input stream is not an HLL sketch");
|
78
72
|
}
|
79
73
|
|
80
|
-
const hll_mode mode = HllSketchImpl<A>::extractCurMode(data[
|
74
|
+
const hll_mode mode = HllSketchImpl<A>::extractCurMode(data[hll_constants::MODE_BYTE]);
|
81
75
|
if (mode != SET) {
|
82
|
-
throw std::invalid_argument("Calling set
|
76
|
+
throw std::invalid_argument("Calling set constructor with non-set mode data");
|
83
77
|
}
|
84
78
|
|
85
|
-
const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[
|
79
|
+
const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(data[hll_constants::MODE_BYTE]);
|
86
80
|
|
87
|
-
const
|
81
|
+
const uint8_t lgK = data[hll_constants::LG_K_BYTE];
|
88
82
|
if (lgK <= 7) {
|
89
83
|
throw std::invalid_argument("Attempt to deserialize invalid CouponHashSet with lgConfigK <= 7. Found: "
|
90
84
|
+ std::to_string(lgK));
|
91
85
|
}
|
92
|
-
|
93
|
-
const bool compactFlag = ((data[
|
86
|
+
uint8_t lgArrInts = data[hll_constants::LG_ARR_BYTE];
|
87
|
+
const bool compactFlag = ((data[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
|
94
88
|
|
95
|
-
|
96
|
-
std::memcpy(&couponCount, data +
|
97
|
-
if (lgArrInts <
|
98
|
-
lgArrInts = HllUtil
|
89
|
+
uint32_t couponCount;
|
90
|
+
std::memcpy(&couponCount, data + hll_constants::HASH_SET_COUNT_INT, sizeof(couponCount));
|
91
|
+
if (lgArrInts < hll_constants::LG_INIT_SET_SIZE) {
|
92
|
+
lgArrInts = HllUtil<>::computeLgArrInts(SET, couponCount, lgK);
|
99
93
|
}
|
100
94
|
// Don't set couponCount in sketch here;
|
101
95
|
// we'll set later if updatable, and increment with updates if compact
|
102
|
-
const
|
103
|
-
const size_t expectedLength =
|
96
|
+
const uint32_t couponsInArray = (compactFlag ? couponCount : (1 << lgArrInts));
|
97
|
+
const size_t expectedLength = hll_constants::HASH_SET_INT_ARR_START + (couponsInArray * sizeof(uint32_t));
|
104
98
|
if (len < expectedLength) {
|
105
99
|
throw std::out_of_range("Byte array too short for sketch. Expected " + std::to_string(expectedLength)
|
106
100
|
+ ", found: " + std::to_string(len));
|
107
101
|
}
|
108
102
|
|
109
|
-
|
103
|
+
ChsAlloc chsa(allocator);
|
104
|
+
CouponHashSet<A>* sketch = new (chsa.allocate(1)) CouponHashSet<A>(lgK, tgtHllType, allocator);
|
110
105
|
|
111
106
|
if (compactFlag) {
|
112
|
-
const uint8_t* curPos = data +
|
113
|
-
|
114
|
-
for (
|
107
|
+
const uint8_t* curPos = data + hll_constants::HASH_SET_INT_ARR_START;
|
108
|
+
uint32_t coupon;
|
109
|
+
for (uint32_t i = 0; i < couponCount; ++i, curPos += sizeof(coupon)) {
|
115
110
|
std::memcpy(&coupon, curPos, sizeof(coupon));
|
116
111
|
sketch->couponUpdate(coupon);
|
117
112
|
}
|
118
113
|
} else {
|
119
|
-
|
120
|
-
|
121
|
-
sketch->lgCouponArrInts = lgArrInts;
|
122
|
-
typedef typename std::allocator_traits<A>::template rebind_alloc<int> intAlloc;
|
123
|
-
sketch->couponIntArr = intAlloc().allocate(1 << lgArrInts);
|
124
|
-
sketch->couponCount = couponCount;
|
114
|
+
sketch->coupons_.resize(1ULL << lgArrInts);
|
115
|
+
sketch->couponCount_ = couponCount;
|
125
116
|
// only need to read valid coupons, unlike in stream case
|
126
|
-
std::memcpy(sketch->
|
127
|
-
data +
|
128
|
-
couponCount * sizeof(
|
129
|
-
intAlloc().deallocate(oldArr, oldArrLen);
|
117
|
+
std::memcpy(sketch->coupons_.data(),
|
118
|
+
data + hll_constants::HASH_SET_INT_ARR_START,
|
119
|
+
couponCount * sizeof(uint32_t));
|
130
120
|
}
|
131
121
|
|
132
122
|
return sketch;
|
133
123
|
}
|
134
124
|
|
135
125
|
template<typename A>
|
136
|
-
CouponHashSet<A>* CouponHashSet<A>::newSet(std::istream& is) {
|
126
|
+
CouponHashSet<A>* CouponHashSet<A>::newSet(std::istream& is, const A& allocator) {
|
137
127
|
uint8_t listHeader[8];
|
138
|
-
|
128
|
+
read(is, listHeader, 8 * sizeof(uint8_t));
|
139
129
|
|
140
|
-
if (listHeader[
|
130
|
+
if (listHeader[hll_constants::PREAMBLE_INTS_BYTE] != hll_constants::HASH_SET_PREINTS) {
|
141
131
|
throw std::invalid_argument("Incorrect number of preInts in input stream");
|
142
132
|
}
|
143
|
-
if (listHeader[
|
133
|
+
if (listHeader[hll_constants::SER_VER_BYTE] != hll_constants::SER_VER) {
|
144
134
|
throw std::invalid_argument("Wrong ser ver in input stream");
|
145
135
|
}
|
146
|
-
if (listHeader[
|
136
|
+
if (listHeader[hll_constants::FAMILY_BYTE] != hll_constants::FAMILY_ID) {
|
147
137
|
throw std::invalid_argument("Input stream is not an HLL sketch");
|
148
138
|
}
|
149
139
|
|
150
|
-
hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[
|
140
|
+
hll_mode mode = HllSketchImpl<A>::extractCurMode(listHeader[hll_constants::MODE_BYTE]);
|
151
141
|
if (mode != SET) {
|
152
|
-
throw std::invalid_argument("Calling set
|
142
|
+
throw std::invalid_argument("Calling set constructor with non-set mode data");
|
153
143
|
}
|
154
144
|
|
155
|
-
target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[
|
145
|
+
const target_hll_type tgtHllType = HllSketchImpl<A>::extractTgtHllType(listHeader[hll_constants::MODE_BYTE]);
|
156
146
|
|
157
|
-
const
|
147
|
+
const uint8_t lgK = listHeader[hll_constants::LG_K_BYTE];
|
158
148
|
if (lgK <= 7) {
|
159
149
|
throw std::invalid_argument("Attempt to deserialize invalid CouponHashSet with lgConfigK <= 7. Found: "
|
160
150
|
+ std::to_string(lgK));
|
161
151
|
}
|
162
|
-
|
163
|
-
const bool compactFlag = ((listHeader[
|
152
|
+
uint8_t lgArrInts = listHeader[hll_constants::LG_ARR_BYTE];
|
153
|
+
const bool compactFlag = ((listHeader[hll_constants::FLAGS_BYTE] & hll_constants::COMPACT_FLAG_MASK) ? true : false);
|
164
154
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
lgArrInts = HllUtil<A>::computeLgArrInts(SET, couponCount, lgK);
|
155
|
+
const auto couponCount = read<uint32_t>(is);
|
156
|
+
if (lgArrInts < hll_constants::LG_INIT_SET_SIZE) {
|
157
|
+
lgArrInts = HllUtil<>::computeLgArrInts(SET, couponCount, lgK);
|
169
158
|
}
|
170
159
|
|
171
|
-
|
160
|
+
ChsAlloc chsa(allocator);
|
161
|
+
CouponHashSet<A>* sketch = new (chsa.allocate(1)) CouponHashSet<A>(lgK, tgtHllType, allocator);
|
172
162
|
typedef std::unique_ptr<CouponHashSet<A>, std::function<void(HllSketchImpl<A>*)>> coupon_hash_set_ptr;
|
173
163
|
coupon_hash_set_ptr ptr(sketch, sketch->get_deleter());
|
174
164
|
|
175
165
|
// Don't set couponCount here;
|
176
166
|
// we'll set later if updatable, and increment with updates if compact
|
177
167
|
if (compactFlag) {
|
178
|
-
for (
|
179
|
-
|
180
|
-
is.read((char*)&coupon, sizeof(coupon));
|
168
|
+
for (uint32_t i = 0; i < couponCount; ++i) {
|
169
|
+
const auto coupon = read<uint32_t>(is);
|
181
170
|
sketch->couponUpdate(coupon);
|
182
171
|
}
|
183
172
|
} else {
|
184
|
-
|
185
|
-
|
186
|
-
sketch->lgCouponArrInts = lgArrInts;
|
187
|
-
sketch->couponIntArr = intAlloc().allocate(1 << lgArrInts);
|
188
|
-
sketch->couponCount = couponCount;
|
173
|
+
sketch->coupons_.resize(1ULL << lgArrInts);
|
174
|
+
sketch->couponCount_ = couponCount;
|
189
175
|
// for stream processing, read entire list so read pointer ends up set correctly
|
190
|
-
is.
|
176
|
+
read(is, sketch->coupons_.data(), sketch->coupons_.size() * sizeof(uint32_t));
|
191
177
|
}
|
192
178
|
|
193
179
|
if (!is.good())
|
@@ -198,22 +184,25 @@ CouponHashSet<A>* CouponHashSet<A>::newSet(std::istream& is) {
|
|
198
184
|
|
199
185
|
template<typename A>
|
200
186
|
CouponHashSet<A>* CouponHashSet<A>::copy() const {
|
201
|
-
|
187
|
+
ChsAlloc chsa(this->coupons_.get_allocator());
|
188
|
+
return new (chsa.allocate(1)) CouponHashSet<A>(*this);
|
202
189
|
}
|
203
190
|
|
204
191
|
template<typename A>
|
205
|
-
CouponHashSet<A>* CouponHashSet<A>::copyAs(
|
206
|
-
|
192
|
+
CouponHashSet<A>* CouponHashSet<A>::copyAs(target_hll_type tgtHllType) const {
|
193
|
+
ChsAlloc chsa(this->coupons_.get_allocator());
|
194
|
+
return new (chsa.allocate(1)) CouponHashSet<A>(*this, tgtHllType);
|
207
195
|
}
|
208
196
|
|
209
197
|
template<typename A>
|
210
|
-
HllSketchImpl<A>* CouponHashSet<A>::couponUpdate(
|
211
|
-
const
|
198
|
+
HllSketchImpl<A>* CouponHashSet<A>::couponUpdate(uint32_t coupon) {
|
199
|
+
const uint8_t lgCouponArrInts = count_trailing_zeros_in_u32(static_cast<uint32_t>(this->coupons_.size()));
|
200
|
+
const int32_t index = find<A>(this->coupons_.data(), lgCouponArrInts, coupon);
|
212
201
|
if (index >= 0) {
|
213
202
|
return this; // found duplicate, ignore
|
214
203
|
}
|
215
|
-
this->
|
216
|
-
++this->
|
204
|
+
this->coupons_[~index] = coupon; // found empty
|
205
|
+
++this->couponCount_;
|
217
206
|
if (checkGrowOrPromote()) {
|
218
207
|
return this->promoteHeapListOrSetToHll(*this);
|
219
208
|
}
|
@@ -221,66 +210,61 @@ HllSketchImpl<A>* CouponHashSet<A>::couponUpdate(int coupon) {
|
|
221
210
|
}
|
222
211
|
|
223
212
|
template<typename A>
|
224
|
-
|
225
|
-
return
|
213
|
+
uint32_t CouponHashSet<A>::getMemDataStart() const {
|
214
|
+
return hll_constants::HASH_SET_INT_ARR_START;
|
226
215
|
}
|
227
216
|
|
228
217
|
template<typename A>
|
229
|
-
|
230
|
-
return
|
218
|
+
uint8_t CouponHashSet<A>::getPreInts() const {
|
219
|
+
return hll_constants::HASH_SET_PREINTS;
|
231
220
|
}
|
232
221
|
|
233
222
|
template<typename A>
|
234
223
|
bool CouponHashSet<A>::checkGrowOrPromote() {
|
235
|
-
if ((
|
236
|
-
|
224
|
+
if (static_cast<size_t>(hll_constants::RESIZE_DENOM * this->couponCount_) > (hll_constants::RESIZE_NUMER * this->coupons_.size())) {
|
225
|
+
const uint8_t lgCouponArrInts = count_trailing_zeros_in_u32(static_cast<uint32_t>(this->coupons_.size()));
|
226
|
+
if (lgCouponArrInts == (this->lgConfigK_ - 3)) { // at max size
|
237
227
|
return true; // promote to HLL
|
238
228
|
}
|
239
|
-
|
240
|
-
growHashSet(this->lgCouponArrInts, tgtLgCoupArrSize);
|
229
|
+
growHashSet(lgCouponArrInts + 1);
|
241
230
|
}
|
242
231
|
return false;
|
243
232
|
}
|
244
233
|
|
245
234
|
template<typename A>
|
246
|
-
void CouponHashSet<A>::growHashSet(
|
247
|
-
const
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
if (fetched != HllUtil<A>::EMPTY) {
|
256
|
-
const int idx = find<A>(tgtCouponIntArr, tgtLgCoupArrSize, fetched); // search TGT array
|
235
|
+
void CouponHashSet<A>::growHashSet(uint8_t tgtLgCoupArrSize) {
|
236
|
+
const uint32_t tgtLen = 1 << tgtLgCoupArrSize;
|
237
|
+
vector_int coupons_new(tgtLen, 0, this->coupons_.get_allocator());
|
238
|
+
|
239
|
+
const uint32_t srcLen = static_cast<uint32_t>(this->coupons_.size());
|
240
|
+
for (uint32_t i = 0; i < srcLen; ++i) { // scan existing array for non-zero values
|
241
|
+
const uint32_t fetched = this->coupons_[i];
|
242
|
+
if (fetched != hll_constants::EMPTY) {
|
243
|
+
const int32_t idx = find<A>(coupons_new.data(), tgtLgCoupArrSize, fetched); // search TGT array
|
257
244
|
if (idx < 0) { // found EMPTY
|
258
|
-
|
245
|
+
coupons_new[~idx] = fetched; // insert
|
259
246
|
continue;
|
260
247
|
}
|
261
248
|
throw std::runtime_error("Error: Found duplicate coupon");
|
262
249
|
}
|
263
250
|
}
|
264
|
-
|
265
|
-
intAlloc().deallocate(this->couponIntArr, 1 << this->lgCouponArrInts);
|
266
|
-
this->couponIntArr = tgtCouponIntArr;
|
267
|
-
this->lgCouponArrInts = tgtLgCoupArrSize;
|
251
|
+
this->coupons_ = std::move(coupons_new);
|
268
252
|
}
|
269
253
|
|
270
254
|
template<typename A>
|
271
|
-
static
|
272
|
-
const
|
273
|
-
|
274
|
-
const
|
255
|
+
static int32_t find(const uint32_t* array, uint8_t lgArrInts, uint32_t coupon) {
|
256
|
+
const uint32_t arrMask = (1 << lgArrInts) - 1;
|
257
|
+
uint32_t probe = coupon & arrMask;
|
258
|
+
const uint32_t loopIndex = probe;
|
275
259
|
do {
|
276
|
-
const
|
277
|
-
if (couponAtIdx ==
|
260
|
+
const uint32_t couponAtIdx = array[probe];
|
261
|
+
if (couponAtIdx == hll_constants::EMPTY) {
|
278
262
|
return ~probe; //empty
|
279
263
|
}
|
280
264
|
else if (coupon == couponAtIdx) {
|
281
265
|
return probe; //duplicate
|
282
266
|
}
|
283
|
-
const
|
267
|
+
const uint32_t stride = ((coupon & hll_constants::KEY_MASK_26) >> lgArrInts) | 1;
|
284
268
|
probe = (probe + stride) & arrMask;
|
285
269
|
} while (probe != loopIndex);
|
286
270
|
throw std::invalid_argument("Key not found and no empty slots!");
|
@@ -24,34 +24,34 @@
|
|
24
24
|
|
25
25
|
namespace datasketches {
|
26
26
|
|
27
|
-
template<typename A
|
27
|
+
template<typename A>
|
28
28
|
class CouponHashSet : public CouponList<A> {
|
29
29
|
public:
|
30
|
-
static CouponHashSet* newSet(const void* bytes, size_t len);
|
31
|
-
static CouponHashSet* newSet(std::istream& is);
|
32
|
-
|
33
|
-
|
34
|
-
explicit CouponHashSet(const CouponHashSet& that);
|
30
|
+
static CouponHashSet* newSet(const void* bytes, size_t len, const A& allocator);
|
31
|
+
static CouponHashSet* newSet(std::istream& is, const A& allocator);
|
32
|
+
CouponHashSet(uint8_t lgConfigK, target_hll_type tgtHllType, const A& allocator);
|
33
|
+
CouponHashSet(const CouponHashSet& that, target_hll_type tgtHllType);
|
35
34
|
|
36
|
-
virtual ~CouponHashSet();
|
35
|
+
virtual ~CouponHashSet() = default;
|
37
36
|
virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const;
|
38
37
|
|
39
38
|
protected:
|
40
|
-
|
39
|
+
using vector_int = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
|
40
|
+
|
41
41
|
virtual CouponHashSet* copy() const;
|
42
42
|
virtual CouponHashSet* copyAs(target_hll_type tgtHllType) const;
|
43
43
|
|
44
|
-
virtual HllSketchImpl<A>* couponUpdate(
|
44
|
+
virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon);
|
45
45
|
|
46
|
-
virtual
|
47
|
-
virtual
|
46
|
+
virtual uint32_t getMemDataStart() const;
|
47
|
+
virtual uint8_t getPreInts() const;
|
48
48
|
|
49
49
|
friend class HllSketchImplFactory<A>;
|
50
50
|
|
51
51
|
private:
|
52
|
-
|
52
|
+
using ChsAlloc = typename std::allocator_traits<A>::template rebind_alloc<CouponHashSet<A>>;
|
53
53
|
bool checkGrowOrPromote();
|
54
|
-
void growHashSet(
|
54
|
+
void growHashSet(uint8_t tgtLgCoupArrSize);
|
55
55
|
};
|
56
56
|
|
57
57
|
}
|