Marine Library  1.0
C++ library for Linux Networking Development
Public Member Functions | List of all members
CWideFreqControl Struct Reference

Rate limiting for any frequency, including ones less than 1Hz. More...

#include <freq_control.hh>

Public Member Functions

bool get ()
 Get 1 token. More...
 
 CWideFreqControl (double freq=0)
 Initialize this object. More...
 
void init (double freq)
 Initialize this object. More...
 

Detailed Description

Rate limiting for any frequency, including ones less than 1Hz.

For any given frequency F:

Although CWideFreqControl is more powerful than CFreqControl, it has a simpler interface. After initialization, you can only get 1 token a time, and don't need to generate any more, because it has been done in get. And there is no way to check or overdraw tokens, because that might indicate a bad design of logic oftentimes.
CWideFreqControl has a fixed bucket size of (F + 1).
All these considerations make CWideFreqControl simple and efficient enough for real world projects even with float-point operations.

Constructor & Destructor Documentation

CWideFreqControl::CWideFreqControl ( double  freq = 0)
inlineexplicit

Initialize this object.

Parameters
freqA non-negative real number denoting frequency
Note
You can init this object again to change frequency.

Member Function Documentation

bool CWideFreqControl::get ( )
inline

Get 1 token.

Returns
  • true: Succeeded. One token is removed from bucket;
  • false: Failed. No token is removed.
void CWideFreqControl::init ( double  freq)
inline

Initialize this object.

Parameters
freqA non-negative real number denoting frequency
Note
You can init this object again to change frequency.

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