OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AggMode Class Reference

#include <AggMode.h>

Classes

struct  ByCount
 

Public Types

using Value = int64_t
 
using Count = uint64_t
 
using Map = robin_hood::unordered_map< Value, Count >
 

Public Member Functions

void add (Value const value)
 
void reduce (AggMode &&rhs)
 
std::optional< Valuemode () const
 

Private Member Functions

void reduceMap (Map const &map)
 

Private Attributes

Map map_
 
std::mutex mutex_
 

Detailed Description

Definition at line 30 of file AggMode.h.

Member Typedef Documentation

using AggMode::Count = uint64_t

Definition at line 33 of file AggMode.h.

using AggMode::Map = robin_hood::unordered_map<Value, Count>

Definition at line 34 of file AggMode.h.

using AggMode::Value = int64_t

Definition at line 32 of file AggMode.h.

Member Function Documentation

void AggMode::add ( Value const  value)
inline

Definition at line 40 of file AggMode.h.

References map_, and mutex_.

Referenced by agg_mode_func().

40  {
41  std::lock_guard<std::mutex> lock(mutex_);
42  auto const [itr, emplaced] = map_.emplace(value, 1u);
43  if (!emplaced) {
44  ++itr->second;
45  }
46  }
Map map_
Definition: AggMode.h:71
std::mutex mutex_
Definition: AggMode.h:72

+ Here is the caller graph for this function:

std::optional<Value> AggMode::mode ( ) const
inline

Definition at line 56 of file AggMode.h.

References map_.

56  {
57  // In case of ties, any max element may be chosen.
58  auto const itr = std::max_element(map_.begin(), map_.end(), ByCount{});
59  return itr == map_.end() ? std::nullopt : std::make_optional(itr->first);
60  }
Map map_
Definition: AggMode.h:71
void AggMode::reduce ( AggMode &&  rhs)
inline

Definition at line 47 of file AggMode.h.

References map_, mutex_, and reduceMap().

Referenced by mode_jit_rt().

47  {
48  std::lock_guard<std::mutex> lock(mutex_);
49  if (map_.size() < rhs.map_.size()) { // Loop over the smaller map
50  rhs.reduceMap(map_);
51  map_ = std::move(rhs.map_);
52  } else {
53  reduceMap(rhs.map_);
54  }
55  }
void reduceMap(Map const &map)
Definition: AggMode.h:63
Map map_
Definition: AggMode.h:71
std::mutex mutex_
Definition: AggMode.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AggMode::reduceMap ( Map const &  map)
inlineprivate

Definition at line 63 of file AggMode.h.

References map_.

Referenced by reduce().

63  {
64  for (Map::value_type const& pair : map) {
65  auto const [itr, emplaced] = map_.emplace(pair);
66  if (!emplaced) {
67  itr->second += pair.second;
68  }
69  }
70  }
Map map_
Definition: AggMode.h:71

+ Here is the caller graph for this function:

Member Data Documentation

Map AggMode::map_
private

Definition at line 71 of file AggMode.h.

Referenced by add(), mode(), reduce(), and reduceMap().

std::mutex AggMode::mutex_
private

Definition at line 72 of file AggMode.h.

Referenced by add(), and reduce().


The documentation for this class was generated from the following file: