datasketches-cpp
theta_union.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 THETA_UNION_HPP_
21 #define THETA_UNION_HPP_
22 
23 #include "serde.hpp"
24 #include "theta_sketch.hpp"
25 #include "theta_union_base.hpp"
26 
27 namespace datasketches {
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 
39 template<typename Allocator = std::allocator<uint64_t>>
41 public:
42  using Entry = uint64_t;
43  using ExtractKey = trivial_extract_key;
46  using resize_factor = theta_constants::resize_factor;
47 
48  // there is no payload in Theta sketch entry
49  struct nop_policy {
50  void operator()(uint64_t internal_entry, uint64_t incoming_entry) const {
51  unused(internal_entry);
52  unused(incoming_entry);
53  }
54  };
55  using State = theta_union_base<Entry, ExtractKey, nop_policy, Sketch, CompactSketch, Allocator>;
56 
57  // No constructor here. Use builder instead.
58  class builder;
59 
64  template<typename FwdSketch>
65  void update(FwdSketch&& sketch);
66 
72  CompactSketch get_result(bool ordered = true) const;
73 
75  void reset();
76 
77 private:
78  State state_;
79 
80  // for builder
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);
82 };
83 
85 template<typename A>
86 class theta_union_alloc<A>::builder: public theta_base_builder<builder, A> {
87 public:
88  builder(const A& allocator = A());
89 
94  theta_union_alloc<A> build() const;
95 };
96 
97 } /* namespace datasketches */
98 
99 #include "theta_union_impl.hpp"
100 
101 #endif
Compact Theta sketch.
Definition: theta_sketch.hpp:359
Theta base builder.
Definition: theta_update_sketch_base.hpp:97
Base class for the Theta Sketch, a generalization of the Kth Minimum Value (KMV) sketch.
Definition: theta_sketch.hpp:127
Theta union builder.
Definition: theta_union.hpp:86
Theta Union.
Definition: theta_union.hpp:40
CompactSketch get_result(bool ordered=true) const
Produces a copy of the current state of the union as a compact sketch.
Definition: theta_union_impl.hpp:37
void update(FwdSketch &&sketch)
Update the union with a given sketch.
Definition: theta_union_impl.hpp:32
void reset()
Reset the union to the initial empty state.
Definition: theta_union_impl.hpp:42
datasketches::resize_factor resize_factor
hash table resize factor
Definition: theta_constants.hpp:31
DataSketches namespace.
Definition: binomial_bounds.hpp:38