Lines Matching defs:counter

53  * Implements an n bit saturating counter and provides methods to
63 * Constructor for the counter. The explicit keyword is used to make
64 * sure the user does not assign a number to the counter thinking it
65 * will be used as a counter value when it is in fact used as the number
68 * @param bits How many bits the counter will have.
69 * @param initial_val Starting value for the counter.
73 counter(initial_val)
76 "Number of bits exceeds counter size");
78 "Saturating counter's Initial value exceeds max value.");
84 counter(other.counter)
102 counter = other.counter;
112 counter = other.counter;
130 std::swap(counter, other.counter);
137 if (counter < maxVal) {
138 ++counter;
156 if (counter > 0) {
157 --counter;
175 this->counter >>= shift;
183 this->counter <<= shift;
184 if (this->counter > maxVal) {
185 this->counter = maxVal;
194 if (maxVal - this->counter >= value) {
195 this->counter += value;
197 this->counter = maxVal;
206 if (this->counter > value) {
207 this->counter -= value;
209 this->counter = 0;
215 * Read the counter's value.
217 operator uint8_t() const { return counter; }
219 /** Reset the counter to its initial value. */
220 void reset() { counter = initialVal; }
223 * Calculate saturation percentile of the current counter's value
229 double calcSaturation() const { return (double) counter / maxVal; }
232 * Whether the counter has achieved its maximum value or not.
234 * @return True if the counter saturated.
236 bool isSaturated() const { return counter == maxVal; }
239 * Saturate the counter.
241 * @return The value added to the counter to reach saturation.
245 const uint8_t diff = maxVal - counter;
246 counter = maxVal;
253 uint8_t counter;