datasketches-cpp
Loading...
Searching...
No Matches
CouponList.hpp
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#ifndef _COUPONLIST_HPP_
21#define _COUPONLIST_HPP_
22
23#include "HllSketchImpl.hpp"
24#include "coupon_iterator.hpp"
25
26#include <iostream>
27
28namespace datasketches {
29
30template<typename A>
31class HllSketchImplFactory;
32
33template<typename A>
34class CouponList : public HllSketchImpl<A> {
35 public:
36 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
37
38 CouponList(uint8_t lgConfigK, target_hll_type tgtHllType, hll_mode mode, const A& allocator);
39 CouponList(const CouponList& that, target_hll_type tgtHllType);
40
41 static CouponList* newList(const void* bytes, size_t len, const A& allocator);
42 static CouponList* newList(std::istream& is, const A& allocator);
43 virtual vector_bytes serialize(bool compact, unsigned header_size_bytes) const;
44 virtual void serialize(std::ostream& os, bool compact) const;
45
46 virtual ~CouponList() = default;
47 virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const;
48
49 virtual CouponList* copy() const;
50 virtual CouponList* copyAs(target_hll_type tgtHllType) const;
51
52 virtual HllSketchImpl<A>* couponUpdate(uint32_t coupon);
53
54 virtual double getEstimate() const;
55 virtual double getCompositeEstimate() const;
56 virtual double getUpperBound(uint8_t numStdDev) const;
57 virtual double getLowerBound(uint8_t numStdDev) const;
58
59 virtual bool isEmpty() const;
60 virtual uint32_t getCouponCount() const;
61
62 coupon_iterator<A> begin(bool all = false) const;
63 coupon_iterator<A> end() const;
64
65 protected:
66 using ClAlloc = typename std::allocator_traits<A>::template rebind_alloc<CouponList<A>>;
67
68 using vector_int = std::vector<uint32_t, typename std::allocator_traits<A>::template rebind_alloc<uint32_t>>;
69
70 HllSketchImpl<A>* promoteHeapListToSet(CouponList& list);
71 HllSketchImpl<A>* promoteHeapListOrSetToHll(CouponList& src);
72
73 virtual uint32_t getUpdatableSerializationBytes() const;
74 virtual uint32_t getCompactSerializationBytes() const;
75 virtual uint32_t getMemDataStart() const;
76 virtual uint8_t getPreInts() const;
77 virtual bool isCompact() const;
78 virtual bool isOutOfOrderFlag() const;
79 virtual void putOutOfOrderFlag(bool oooFlag);
80
81 virtual A getAllocator() const;
82
83 uint32_t couponCount_;
84 bool oooFlag_;
85 vector_int coupons_;
86
87 friend class HllSketchImplFactory<A>;
88};
89
90}
91
92#endif /* _COUPONLIST_HPP_ */
DataSketches namespace.
Definition binomial_bounds.hpp:38
target_hll_type
Specifies the target type of HLL sketch to be created.
Definition hll.hpp:72