proxygen
folly::gen::detail::GroupByAdjacent< Selector >::Generator< Value, Source, ValueDecayed, Key, KeyDecayed > Class Template Reference

#include <Base-inl.h>

Inheritance diagram for folly::gen::detail::GroupByAdjacent< Selector >::Generator< Value, Source, ValueDecayed, Key, KeyDecayed >:
folly::gen::GenImpl< Group< KeyDecayed, ValueDecayed > &&, Generator< Value, Source, ValueDecayed, Key, KeyDecayed > > folly::gen::FBounded< Self >

Public Types

typedef Group< KeyDecayed, ValueDecayed > GroupType
 
- Public Types inherited from folly::gen::GenImpl< Group< KeyDecayed, ValueDecayed > &&, Generator< Value, Source, ValueDecayed, Key, KeyDecayed > >
typedef Group< KeyDecayed, ValueDecayed > && ValueType
 
typedef std::decay< Group< KeyDecayed, ValueDecayed > && >::type StorageType
 

Public Member Functions

 Generator (Source source, Selector selector)
 
template<class Handler >
bool apply (Handler &&handler) const
 
- Public Member Functions inherited from folly::gen::GenImpl< Group< KeyDecayed, ValueDecayed > &&, Generator< Value, Source, ValueDecayed, Key, KeyDecayed > >
bool apply (Handler &&handler) const
 
void foreach (Body &&body) const
 
- Public Member Functions inherited from folly::gen::FBounded< Self >
const Self & self () const
 
Self & self ()
 

Static Public Attributes

static constexpr bool infinite = Source::infinite
 
- Static Public Attributes inherited from folly::gen::GenImpl< Group< KeyDecayed, ValueDecayed > &&, Generator< Value, Source, ValueDecayed, Key, KeyDecayed > >
static constexpr bool infinite
 

Private Attributes

Source source_
 
Selector selector_
 

Additional Inherited Members

- Protected Member Functions inherited from folly::gen::GenImpl< Group< KeyDecayed, ValueDecayed > &&, Generator< Value, Source, ValueDecayed, Key, KeyDecayed > >
 GenImpl ()=default
 
 GenImpl (GenImpl &&)=default
 
 GenImpl (const GenImpl &)=default
 
GenImploperator= (GenImpl &&)=default
 
GenImploperator= (const GenImpl &)=default
 

Detailed Description

template<class Selector>
template<class Value, class Source, class ValueDecayed = typename std::decay<Value>::type, class Key = invoke_result_t<Selector, Value>, class KeyDecayed = typename std::decay<Key>::type>
class folly::gen::detail::GroupByAdjacent< Selector >::Generator< Value, Source, ValueDecayed, Key, KeyDecayed >

Definition at line 1236 of file Base-inl.h.

Member Typedef Documentation

template<class Selector >
template<class Value , class Source , class ValueDecayed = typename std::decay<Value>::type, class Key = invoke_result_t<Selector, Value>, class KeyDecayed = typename std::decay<Key>::type>
typedef Group<KeyDecayed, ValueDecayed> folly::gen::detail::GroupByAdjacent< Selector >::Generator< Value, Source, ValueDecayed, Key, KeyDecayed >::GroupType

Definition at line 1247 of file Base-inl.h.

Constructor & Destructor Documentation

template<class Selector >
template<class Value , class Source , class ValueDecayed = typename std::decay<Value>::type, class Key = invoke_result_t<Selector, Value>, class KeyDecayed = typename std::decay<Key>::type>
folly::gen::detail::GroupByAdjacent< Selector >::Generator< Value, Source, ValueDecayed, Key, KeyDecayed >::Generator ( Source  source,
Selector  selector 
)
inline

Definition at line 1244 of file Base-inl.h.

1245  : source_(std::move(source)), selector_(std::move(selector)) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Function Documentation

template<class Selector >
template<class Value , class Source , class ValueDecayed = typename std::decay<Value>::type, class Key = invoke_result_t<Selector, Value>, class KeyDecayed = typename std::decay<Key>::type>
template<class Handler >
bool folly::gen::detail::GroupByAdjacent< Selector >::Generator< Value, Source, ValueDecayed, Key, KeyDecayed >::apply ( Handler &&  handler) const
inline

Definition at line 1250 of file Base-inl.h.

References folly::Optional< Value >::emplace(), group, handler(), folly::Optional< Value >::hasValue(), folly::gen::move, folly::none, value, folly::Optional< Value >::value(), testing::Value(), and values().

1250  {
1251  Optional<KeyDecayed> key = none;
1252  typename GroupType::VectorType values;
1253 
1254  bool result = source_.apply([&](Value value) mutable {
1255  KeyDecayed newKey = selector_(value);
1256 
1257  // start the first group
1258  if (!key.hasValue()) {
1259  key.emplace(newKey);
1260  }
1261 
1262  if (key == newKey) {
1263  // grow the current group
1264  values.push_back(value);
1265  } else {
1266  // flush the current group
1267  GroupType group(key.value(), std::move(values));
1268  if (!handler(std::move(group))) {
1269  return false;
1270  }
1271 
1272  // start a new group
1273  key.emplace(newKey);
1274  values.clear();
1275  values.push_back(value);
1276  }
1277  return true;
1278  });
1279 
1280  if (!result) {
1281  return false;
1282  }
1283 
1284  if (!key.hasValue()) {
1285  return true;
1286  }
1287 
1288  // flush the final group
1289  GroupType group(key.value(), std::move(values));
1290  return handler(std::move(group));
1291  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::vector< Value > VectorType
Definition: Base-inl.h:52
Group< KeyDecayed, ValueDecayed > GroupType
Definition: Base-inl.h:1247
void handler(int, siginfo_t *, void *)
bool Value(const T &value, M matcher)
Value & emplace(Args &&...args)
Definition: Optional.h:231
Optional< NamedGroup > group
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
constexpr None none
Definition: Optional.h:87
std::vector< int > values(1'000)

Member Data Documentation

template<class Selector >
template<class Value , class Source , class ValueDecayed = typename std::decay<Value>::type, class Key = invoke_result_t<Selector, Value>, class KeyDecayed = typename std::decay<Key>::type>
constexpr bool folly::gen::detail::GroupByAdjacent< Selector >::Generator< Value, Source, ValueDecayed, Key, KeyDecayed >::infinite = Source::infinite
static

Definition at line 1293 of file Base-inl.h.

template<class Selector >
template<class Value , class Source , class ValueDecayed = typename std::decay<Value>::type, class Key = invoke_result_t<Selector, Value>, class KeyDecayed = typename std::decay<Key>::type>
Selector folly::gen::detail::GroupByAdjacent< Selector >::Generator< Value, Source, ValueDecayed, Key, KeyDecayed >::selector_
private

Definition at line 1241 of file Base-inl.h.

template<class Selector >
template<class Value , class Source , class ValueDecayed = typename std::decay<Value>::type, class Key = invoke_result_t<Selector, Value>, class KeyDecayed = typename std::decay<Key>::type>
Source folly::gen::detail::GroupByAdjacent< Selector >::Generator< Value, Source, ValueDecayed, Key, KeyDecayed >::source_
private

Definition at line 1240 of file Base-inl.h.


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