proxygen
folly::detail::SlidingWindow< BucketT > Class Template Reference

#include <SlidingWindow.h>

Public Member Functions

 SlidingWindow (Function< BucketT(void)> fn, size_t numBuckets)
 
 SlidingWindow (SlidingWindow &&rhs)
 
std::vector< BucketT > get () const
 
void set (size_t idx, BucketT bucket)
 
BucketT front () const
 
void slide (size_t nBuckets)
 

Private Attributes

Function< BucketT(void)> fn_
 
std::vector< BucketT > buckets_
 
size_t curHead_
 

Detailed Description

template<typename BucketT>
class folly::detail::SlidingWindow< BucketT >

Definition at line 33 of file SlidingWindow.h.

Constructor & Destructor Documentation

template<typename BucketT>
folly::detail::SlidingWindow< BucketT >::SlidingWindow ( Function< BucketT(void)>  fn,
size_t  numBuckets 
)

Definition at line 27 of file SlidingWindow-defs.h.

References folly::detail::SlidingWindow< BucketT >::buckets_, folly::detail::SlidingWindow< BucketT >::fn_, and i.

30  : fn_(std::move(fn)), curHead_(0) {
31  buckets_.reserve(numBuckets);
32  for (size_t i = 0; i < numBuckets; ++i) {
33  buckets_.push_back(fn_());
34  }
35  std::reverse(buckets_.begin(), buckets_.end());
36 }
std::vector< BucketT > buckets_
Definition: SlidingWindow.h:53
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Function< BucketT(void)> fn_
Definition: SlidingWindow.h:52
template<typename BucketT>
folly::detail::SlidingWindow< BucketT >::SlidingWindow ( SlidingWindow< BucketT > &&  rhs)

Definition at line 39 of file SlidingWindow-defs.h.

40  : fn_(std::move(rhs.fn_)),
41  buckets_(std::move(rhs.buckets_)),
42  curHead_(rhs.curHead_) {}
std::vector< BucketT > buckets_
Definition: SlidingWindow.h:53
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Function< BucketT(void)> fn_
Definition: SlidingWindow.h:52
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649

Member Function Documentation

template<typename BucketT >
BucketT folly::detail::SlidingWindow< BucketT >::front ( ) const
template<typename BucketT >
std::vector< BucketT > folly::detail::SlidingWindow< BucketT >::get ( ) const

Definition at line 45 of file SlidingWindow-defs.h.

References folly::detail::SlidingWindow< BucketT >::buckets_, and folly::detail::SlidingWindow< BucketT >::curHead_.

Referenced by folly::detail::BufferedSlidingWindow< DigestT, ClockT >::get().

45  {
46  std::vector<BucketT> buckets;
47  buckets.reserve(buckets_.size());
48  buckets.insert(buckets.end(), buckets_.begin() + curHead_, buckets_.end());
49  buckets.insert(buckets.end(), buckets_.begin(), buckets_.begin() + curHead_);
50  return buckets;
51 }
std::vector< BucketT > buckets_
Definition: SlidingWindow.h:53
template<typename BucketT>
void folly::detail::SlidingWindow< BucketT >::set ( size_t  idx,
BucketT  bucket 
)

Definition at line 59 of file SlidingWindow-defs.h.

References folly::detail::SlidingWindow< BucketT >::buckets_, folly::detail::SlidingWindow< BucketT >::curHead_, and folly::gen::move.

Referenced by folly::detail::BufferedSlidingWindow< DigestT, ClockT >::onNewDigest().

59  {
60  if (idx < buckets_.size()) {
61  idx = (curHead_ + idx) % buckets_.size();
62  buckets_[idx] = std::move(bucket);
63  }
64 }
std::vector< BucketT > buckets_
Definition: SlidingWindow.h:53
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<typename BucketT >
void folly::detail::SlidingWindow< BucketT >::slide ( size_t  nBuckets)

Definition at line 67 of file SlidingWindow-defs.h.

References folly::detail::SlidingWindow< BucketT >::buckets_, folly::detail::SlidingWindow< BucketT >::curHead_, folly::detail::SlidingWindow< BucketT >::fn_, i, and min.

Referenced by folly::detail::BufferedSlidingWindow< DigestT, ClockT >::onNewDigest().

67  {
68  nBuckets = std::min(nBuckets, buckets_.size());
69  for (size_t i = 0; i < nBuckets; ++i) {
70  if (curHead_ == 0) {
71  curHead_ = buckets_.size() - 1;
72  } else {
73  curHead_--;
74  }
75  buckets_[curHead_] = fn_();
76  }
77 }
std::vector< BucketT > buckets_
Definition: SlidingWindow.h:53
Function< BucketT(void)> fn_
Definition: SlidingWindow.h:52
LogLevel min
Definition: LogLevel.cpp:30

Member Data Documentation

template<typename BucketT>
Function<BucketT(void)> folly::detail::SlidingWindow< BucketT >::fn_
private

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