DecayCounter: remove unnecessary delta member

We can just add/sub to val directly (especially now that decay can be called on
a const DecayCounter).

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
This commit is contained in:
Patrick Donnelly 2018-06-08 15:02:17 -07:00
parent bc7cb57985
commit 50c573910b
No known key found for this signature in database
GPG Key ID: 3A2A7E25BEA8AADB
2 changed files with 13 additions and 14 deletions

View File

@ -19,16 +19,16 @@
void DecayCounter::encode(bufferlist& bl) const
{
ENCODE_START(4, 4, bl);
decay(rate);
ENCODE_START(5, 4, bl);
encode(val, bl);
encode(delta, bl);
encode(vel, bl);
ENCODE_FINISH(bl);
}
void DecayCounter::decode(bufferlist::const_iterator &p)
{
DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, p);
DECODE_START_LEGACY_COMPAT_LEN(5, 4, 4, p);
if (struct_v < 2) {
double half_life = 0.0;
decode(half_life, p);
@ -38,7 +38,11 @@ void DecayCounter::decode(bufferlist::const_iterator &p)
decode(k, p);
}
decode(val, p);
decode(delta, p);
if (struct_v < 5) {
double delta;
decode(delta, p);
val += delta;
}
decode(vel, p);
last_decay = clock::now();
DECODE_FINISH(p);
@ -48,7 +52,6 @@ void DecayCounter::dump(Formatter *f) const
{
decay(rate);
f->dump_float("value", val);
f->dump_float("delta", delta);
f->dump_float("velocity", vel);
}
@ -56,7 +59,6 @@ void DecayCounter::generate_test_instances(std::list<DecayCounter*>& ls)
{
DecayCounter *counter = new DecayCounter();
counter->val = 3.0;
counter->delta = 2.0;
counter->vel = 1.0;
ls.push_back(counter);
counter = new DecayCounter();
@ -72,7 +74,7 @@ void DecayCounter::decay(const DecayRate &rate) const
return; /* no need to decay for small differences */
// calculate new value
double newval = (val+delta) * exp(el * rate.k);
double newval = val * exp(el * rate.k);
if (newval < .01) {
newval = 0.0;
}
@ -82,7 +84,6 @@ void DecayCounter::decay(const DecayRate &rate) const
vel *= exp(el * rate.k);
val = newval;
delta = 0;
last_decay = now;
}
}

View File

@ -68,7 +68,7 @@ public:
double get() const {
decay(rate);
return val+delta;
return val;
}
double get_last() const {
@ -89,8 +89,8 @@ public:
double hit(double v = 1.0) {
decay(rate);
delta += v;
return val+delta;
val += v;
return val;
}
void adjust(double a) {
@ -102,7 +102,6 @@ public:
void scale(double f) {
val *= f;
delta *= f;
vel *= f;
}
@ -112,7 +111,7 @@ public:
void reset() {
last_decay = clock::now();
val = delta = 0;
val = vel = 0;
}
protected:
@ -120,7 +119,6 @@ protected:
private:
mutable double val = 0.0; // value
mutable double delta = 0.0; // delta since last decay
mutable double vel = 0.0; // recent velocity
mutable time last_decay = clock::zero(); // time of last decay
DecayRate rate;