datasketches-cpp
Loading...
Searching...
No Matches
tuple_intersection.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 TUPLE_INTERSECTION_HPP_
21#define TUPLE_INTERSECTION_HPP_
22
23#include "tuple_sketch.hpp"
24#include "theta_intersection_base.hpp"
25
26namespace datasketches {
27
28/*
29// for types with defined + operation
30template<typename Summary>
31struct example_tuple_intersection_policy {
32 void operator()(Summary& summary, const Summary& other) const {
33 summary += other;
34 }
35};
36*/
37
42template<
43 typename Summary,
44 typename Policy,
45 typename Allocator = std::allocator<Summary>
46>
48public:
49 using Entry = std::pair<uint64_t, Summary>;
50 using ExtractKey = pair_extract_key<uint64_t, Summary>;
53 using AllocEntry = typename std::allocator_traits<Allocator>::template rebind_alloc<Entry>;
54
55 // reformulate the external policy that operates on Summary
56 // in terms of operations on Entry
57 struct internal_policy {
58 internal_policy(const Policy& external_policy): external_policy_(external_policy) {}
59 void operator()(Entry& internal_entry, const Entry& incoming_entry) const {
60 external_policy_(internal_entry.second, incoming_entry.second);
61 }
62 void operator()(Entry& internal_entry, Entry&& incoming_entry) const {
63 external_policy_(internal_entry.second, std::move(incoming_entry.second));
64 }
65 const Policy& get_external_policy() const { return external_policy_; }
66 Policy external_policy_;
67 };
68
69 using State = theta_intersection_base<Entry, ExtractKey, internal_policy, Sketch, CompactSketch, AllocEntry>;
70
77 explicit tuple_intersection(uint64_t seed = DEFAULT_SEED, const Policy& policy = Policy(), const Allocator& allocator = Allocator());
78
85 template<typename FwdSketch>
86 void update(FwdSketch&& sketch);
87
95 CompactSketch get_result(bool ordered = true) const;
96
101 bool has_result() const;
102
103protected:
104 State state_;
105};
106
107} /* namespace datasketches */
108
109#include "tuple_intersection_impl.hpp"
110
111#endif
Compact Tuple sketch.
Definition tuple_sketch.hpp:416
Tuple intersection.
Definition tuple_intersection.hpp:47
CompactSketch get_result(bool ordered=true) const
Produces a copy of the current state of the intersection.
Definition tuple_intersection_impl.hpp:34
bool has_result() const
Returns true if the state of the intersection is defined (not infinite "universe").
Definition tuple_intersection_impl.hpp:39
void update(FwdSketch &&sketch)
Updates the intersection with a given sketch.
Base class for Tuple sketch.
Definition tuple_sketch.hpp:54
DataSketches namespace.
Definition binomial_bounds.hpp:38