16#ifndef TOOLBOX_NET_RATELIMIT_HPP
17#define TOOLBOX_NET_RATELIMIT_HPP
21#include <boost/container/small_vector.hpp>
30 template <
typename intervalT = Seconds>
31 constexpr RateLimit(std::size_t limit, intervalT interval) noexcept
33 , interval_{std::chrono::duration_cast<Decis>(interval)}
35 assert(interval_.count());
47 constexpr auto limit() const noexcept {
return limit_; }
48 constexpr auto interval() const noexcept {
return interval_; }
62 template <
typename intervalT = Seconds>
64 : buckets_(
std::chrono::duration_cast<
Decis>(interval).count())
66 assert(buckets_.size());
78 std::
size_t count() const noexcept {
return count_; }
81 void add(
MonoTime time, std::size_t count = 1) noexcept;
84 std::
size_t& at(
std::time_t t) noexcept {
return buckets_[t % buckets_.size()]; }
87 boost::container::small_vector<std::size_t, 10> buckets_;
91inline namespace util {
93struct TypeTraits<net::RateLimit> {
ostream & operator<<(ostream &os, const pair< T, U > &p)