lastseen.cpp 578 B

12345678910111213141516171819202122232425
  1. #include "lastseen.h"
  2. LastSeen::LastSeen(int max_nondups) {
  3. this->max = max_nondups;
  4. this->tracker = new int[max_nondups];
  5. for (int i = 0; i < max_nondups; i++) {
  6. this->tracker[i] = -1;
  7. }
  8. }
  9. LastSeen::~LastSeen() { delete this->tracker; }
  10. bool LastSeen::seen_before(int this_one) {
  11. int i;
  12. for (i = 0; i < this->max; i++) {
  13. if (this->tracker[i] == this_one)
  14. return true;
  15. }
  16. // Ok, it hasn't been seen before.
  17. for (i = 0; i < this->max - 1; i++) {
  18. this->tracker[i] = this->tracker[i + 1];
  19. };
  20. this->tracker[i] = this_one;
  21. return false;
  22. }