Delete the oldest node to reduce churn
This commit is contained in:
parent
b05f831f9a
commit
c06480e631
|
@ -25,7 +25,7 @@ public:
|
||||||
void setDistance(float distFl);
|
void setDistance(float distFl);
|
||||||
|
|
||||||
NimBLEAddress getAddress() { return address; }
|
NimBLEAddress getAddress() { return address; }
|
||||||
void setAddress(NimBLEAddress newAddr) { address = newAddr; }
|
long getLastSeen() { return lastSeenMicros; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool hasValue = false, enroll = false, reported = false;
|
bool hasValue = false, enroll = false, reported = false;
|
||||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -12,8 +12,19 @@ BleFingerprint *getFingerprintInternal(BLEAdvertisedDevice *advertisedDevice)
|
||||||
|
|
||||||
if (fingerprints.size() >= MAX_MAC_ADDRESSES)
|
if (fingerprints.size() >= MAX_MAC_ADDRESSES)
|
||||||
{
|
{
|
||||||
delete fingerprints.back();
|
long oldestTime = LONG_MAX;
|
||||||
fingerprints.pop_back();
|
BleFingerprint *oldest;
|
||||||
|
for (auto it = fingerprints.begin(); it != fingerprints.end(); ++it)
|
||||||
|
{
|
||||||
|
long time = (*it)->getLastSeen();
|
||||||
|
if (time < oldestTime)
|
||||||
|
{
|
||||||
|
oldestTime = time;
|
||||||
|
oldest = (*it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fingerprints.remove(oldest);
|
||||||
|
delete oldest;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto created = new BleFingerprint(advertisedDevice);
|
auto created = new BleFingerprint(advertisedDevice);
|
||||||
|
|
Loading…
Reference in New Issue