datasketches-cpp
Loading...
Searching...
No Matches
HllSketchImpl.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 _HLLSKETCHIMPL_HPP_
21#define _HLLSKETCHIMPL_HPP_
22
23#include "HllUtil.hpp"
24#include "hll.hpp" // for TgtHllType
25
26#include <memory>
27
28namespace datasketches {
29
30template<typename A>
32 public:
33 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
34
35 HllSketchImpl(uint8_t lgConfigK, target_hll_type tgtHllType, hll_mode mode, bool startFullSize);
36 virtual ~HllSketchImpl();
37
38 virtual void serialize(std::ostream& os, bool compact) const = 0;
39 virtual vector_bytes serialize(bool compact, unsigned header_size_bytes) const = 0;
40
41 virtual HllSketchImpl* copy() const = 0;
42 virtual HllSketchImpl* copyAs(target_hll_type tgtHllType) const = 0;
43 HllSketchImpl<A>* reset();
44
45 virtual std::function<void(HllSketchImpl<A>*)> get_deleter() const = 0;
46
47 virtual HllSketchImpl* couponUpdate(uint32_t coupon) = 0;
48
49 hll_mode getCurMode() const;
50
51 virtual double getEstimate() const = 0;
52 virtual double getCompositeEstimate() const = 0;
53 virtual double getUpperBound(uint8_t numStdDev) const = 0;
54 virtual double getLowerBound(uint8_t numStdDev) const = 0;
55
56 inline uint8_t getLgConfigK() const;
57
58 virtual uint32_t getMemDataStart() const = 0;
59
60 virtual uint8_t getPreInts() const = 0;
61
62 target_hll_type getTgtHllType() const;
63
64 virtual uint32_t getUpdatableSerializationBytes() const = 0;
65 virtual uint32_t getCompactSerializationBytes() const = 0;
66
67 virtual bool isCompact() const = 0;
68 virtual bool isEmpty() const = 0;
69 virtual bool isOutOfOrderFlag() const = 0;
70 virtual void putOutOfOrderFlag(bool oooFlag) = 0;
71 virtual A getAllocator() const = 0;
72 bool isStartFullSize() const;
73
74 protected:
75 static target_hll_type extractTgtHllType(uint8_t modeByte);
76 static hll_mode extractCurMode(uint8_t modeByte);
77 uint8_t makeFlagsByte(bool compact) const;
78 uint8_t makeModeByte() const;
79
80 const uint8_t lgConfigK_;
81 const target_hll_type tgtHllType_;
82 const hll_mode mode_;
83 const bool startFullSize_;
84};
85
86}
87
88#endif // _HLLSKETCHIMPL_HPP_
This is a high performance implementation of Phillipe Flajolet's HLL sketch but with significantly im...
Definition HllSketchImpl.hpp:31
DataSketches namespace.
Definition binomial_bounds.hpp:38
target_hll_type
Specifies the target type of HLL sketch to be created.
Definition hll.hpp:72