lastseen.cpp 715 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "lastseen.h"
  2. LastSeen::LastSeen(int max) {
  3. this->max = max;
  4. tracker.reserve(max);
  5. while ((int)tracker.size() < max)
  6. tracker.insert(tracker.begin(), -1);
  7. }
  8. /*
  9. int LastSeen::bestsize(int max_items) {
  10. int best = max_items / 2;
  11. return best;
  12. }
  13. */
  14. int LastSeen::getmax(void) {
  15. return this->max;
  16. }
  17. LastSeen::~LastSeen() { };
  18. bool LastSeen::seen_before(int this_one) {
  19. for (auto it = this->tracker.begin(); it != this->tracker.end(); ++it ) {
  20. if (*it == this_one)
  21. return true;
  22. }
  23. // Ok, it hasn't been seen before.
  24. this->tracker.erase(this->tracker.begin());
  25. this->tracker.push_back(this_one);
  26. return false;
  27. }
  28. int LastSeen::best_guess(int max) {
  29. return max / 2;
  30. }