Delete the oldest node to reduce churn

This commit is contained in:
DTTerastar 2021-04-02 15:16:30 -04:00
parent b05f831f9a
commit c06480e631
2 changed files with 14 additions and 3 deletions

View File

@ -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;

View File

@ -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);