Thrill  0.1
hyperloglog.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/api/hyperloglog.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2017 Moritz Kiefer <[email protected]>
7  * Copyright (C) 2017 Tino Fuhrmann <[email protected]>
8  *
9  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
10  ******************************************************************************/
11 
12 #pragma once
13 #ifndef THRILL_API_HYPERLOGLOG_HEADER
14 #define THRILL_API_HYPERLOGLOG_HEADER
15 
17 #include <thrill/api/dia.hpp>
19 
20 namespace thrill {
21 namespace api {
22 
23 /*!
24  * \ingroup api_layer
25  */
26 template <size_t p, typename ValueType>
27 class HyperLogLogNode final
28  : public ActionResultNode<core::HyperLogLogRegisters<p> >
29 {
30  static constexpr bool debug = false;
31 
33  using Super::context_;
34 
35 public:
36  template <typename ParentDIA>
37  HyperLogLogNode(const ParentDIA& parent, const char* label)
38  : Super(parent.ctx(), label, { parent.id() }, { parent.node() }) {
39  // Hook PreOp(s)
40  auto pre_op_fn = [this](const ValueType& input) {
41  registers_.insert(input);
42  };
43 
44  auto lop_chain = parent.stack().push(pre_op_fn).fold();
45  parent.node()->AddChild(this, lop_chain);
46  }
47 
48  //! Executes the sum operation.
49  void Execute() final {
50  // process the reduce
52  }
53 
54  //! Returns result of global sum.
56  { return registers_; }
57 
58 private:
60 };
61 
62 template <typename ValueType, typename Stack>
63 template <size_t p>
65  assert(IsValid());
66 
67  auto node = tlx::make_counting<HyperLogLogNode<p, ValueType> >(
68  *this, "HyperLogLog");
69  node->RunScope();
70  auto registers = node->result();
71  return registers.result();
72 }
73 
74 } // namespace api
75 } // namespace thrill
76 
77 #endif // !THRILL_API_HYPERLOGLOG_HEADER
78 
79 /******************************************************************************/
HyperLogLogNode(const ParentDIA &parent, const char *label)
Definition: hyperloglog.hpp:37
net::FlowControlChannel & net
Definition: context.hpp:446
double HyperLogLog() const
Compute the approximate number of distinct elements in the DIA.
Definition: hyperloglog.hpp:64
const core::HyperLogLogRegisters< p > & result() const final
Returns result of global sum.
Definition: hyperloglog.hpp:55
const char * label() const
return label() of DIANode subclass as stored by StatsNode
Definition: dia_base.hpp:218
T TLX_ATTRIBUTE_WARN_UNUSED_RESULT AllReduce(const T &value, const BinarySumOp &sum_op=BinarySumOp())
Reduces a value of a serializable type T over all workers given a certain reduce function.
core::HyperLogLogRegisters< p > registers_
Definition: hyperloglog.hpp:59
static constexpr bool debug
Definition: hyperloglog.hpp:30
void Execute() final
Executes the sum operation.
Definition: hyperloglog.hpp:49
Context & context_
associated Context
Definition: dia_base.hpp:293