datasketches-cpp
Loading...
Searching...
No Matches
cpc_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 CPC_UNION_HPP_
21#define CPC_UNION_HPP_
22
23#include <string>
24
25#include "cpc_sketch.hpp"
26#include "common_defs.hpp"
27
28namespace datasketches {
29
32
39template<typename A>
41public:
42 using vector_bytes = std::vector<uint8_t, typename std::allocator_traits<A>::template rebind_alloc<uint8_t>>;
43 using vector_u64 = std::vector<uint64_t, typename std::allocator_traits<A>::template rebind_alloc<uint64_t>>;
44
51 explicit cpc_union_alloc(uint8_t lg_k = cpc_constants::DEFAULT_LG_K, uint64_t seed = DEFAULT_SEED, const A& allocator = A());
52
58
63 cpc_union_alloc(cpc_union_alloc<A>&& other) noexcept;
64
66
73
80
85 void update(const cpc_sketch_alloc<A>& sketch);
86
91 void update(cpc_sketch_alloc<A>&& sketch);
92
98
99private:
100 using AllocU8 = typename std::allocator_traits<A>::template rebind_alloc<uint8_t>;
101 using AllocU64 = typename std::allocator_traits<A>::template rebind_alloc<uint64_t>;
102 using AllocCpc = typename std::allocator_traits<A>::template rebind_alloc<cpc_sketch_alloc<A>>;
103
104 uint8_t lg_k;
105 uint64_t seed;
106 cpc_sketch_alloc<A>* accumulator;
107 vector_u64 bit_matrix;
108
109 template<typename S> void internal_update(S&& sketch); // to support both rvalue and lvalue
110
111 cpc_sketch_alloc<A> get_result_from_accumulator() const;
112 cpc_sketch_alloc<A> get_result_from_bit_matrix() const;
113
114 void switch_to_bit_matrix();
115 void walk_table_updating_sketch(const u32_table<A>& table);
116 void or_table_into_matrix(const u32_table<A>& table);
117 void or_window_into_matrix(const vector_bytes& sliding_window, uint8_t offset, uint8_t src_lg_k);
118 void or_matrix_into_matrix(const vector_u64& src_matrix, uint8_t src_lg_k);
119 void reduce_k(uint8_t new_lg_k);
120};
121
122} /* namespace datasketches */
123
124#include "cpc_union_impl.hpp"
125
126#endif
High performance C++ implementation of Compressed Probabilistic Counting (CPC) Sketch.
Definition cpc_sketch.hpp:64
High performance C++ implementation of Compressed Probabilistic Counting (CPC) Union.
Definition cpc_union.hpp:40
void update(const cpc_sketch_alloc< A > &sketch)
This method is to update the union with a given sketch (lvalue)
Definition cpc_union_impl.hpp:93
cpc_sketch_alloc< A > get_result() const
This method produces a copy of the current state of the union as a sketch.
Definition cpc_union_impl.hpp:174
cpc_union_alloc< A > & operator=(const cpc_union_alloc< A > &other)
Copy assignment.
Definition cpc_union_impl.hpp:74
const uint8_t DEFAULT_LG_K
default log2 of K
Definition cpc_common.hpp:36
DataSketches namespace.
Definition binomial_bounds.hpp:38