FadingCounter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_FADINGCOUNTER_H
10 #define SQUID_SRC_FADINGCOUNTER_H
11 
12 #include <vector>
13 
16 {
17 public:
18  FadingCounter();
19 
21  void configure(double horizonSeconds);
22 
23  void clear();
24 
25  int count(int howMany);
26  int remembered() const { return total; }
27 
29  double horizon;
30 
31 private:
32  const int precision;
33  double delta;
34 
35  double lastTime;
36  std::vector<int> counters;
37  int total;
38 };
39 
40 #endif /* SQUID_SRC_FADINGCOUNTER_H */
41 
int total
number of remembered events (possibly stale)
Definition: FadingCounter.h:37
void configure(double horizonSeconds)
0=remember nothing; -1=forget nothing; new value triggers clear()
std::vector< int > counters
events per delta (possibly stale)
Definition: FadingCounter.h:36
void clear()
forgets all events
const int precision
#counting slots, controls measur. accuracy
Definition: FadingCounter.h:32
double lastTime
time of the last update
Definition: FadingCounter.h:35
double delta
sub-interval duration = horizon/precision
Definition: FadingCounter.h:33
double horizon
read-only memory horizon in seconds; older events are forgotten
Definition: FadingCounter.h:29
Counts events, forgetting old ones. Useful for "3 errors/minute" limits.
Definition: FadingCounter.h:15
int count(int howMany)
count fresh, return #events remembered

 

Introduction

Documentation

Support

Miscellaneous