|
@@ -1,25 +1,38 @@
|
|
|
#include "lastseen.h"
|
|
|
|
|
|
-LastSeen::LastSeen(int max_nondups) {
|
|
|
- this->max = max_nondups;
|
|
|
- this->tracker = new int[max_nondups];
|
|
|
- for (int i = 0; i < max_nondups; i++) {
|
|
|
- this->tracker[i] = -1;
|
|
|
- }
|
|
|
+LastSeen::LastSeen(int max) {
|
|
|
+ this->max = max;
|
|
|
+
|
|
|
+ tracker.reserve(max);
|
|
|
+ while ((int)tracker.size() < max)
|
|
|
+ tracker.insert(tracker.begin(), -1);
|
|
|
}
|
|
|
|
|
|
-LastSeen::~LastSeen() { delete this->tracker; }
|
|
|
+/*
|
|
|
+int LastSeen::bestsize(int max_items) {
|
|
|
+ int best = max_items / 2;
|
|
|
+ return best;
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
+int LastSeen::getmax(void) {
|
|
|
+ return this->max;
|
|
|
+}
|
|
|
+
|
|
|
+LastSeen::~LastSeen() { };
|
|
|
|
|
|
bool LastSeen::seen_before(int this_one) {
|
|
|
- int i;
|
|
|
- for (i = 0; i < this->max; i++) {
|
|
|
- if (this->tracker[i] == this_one)
|
|
|
+ for (auto it = this->tracker.begin(); it != this->tracker.end(); ++it ) {
|
|
|
+ if (*it == this_one)
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
// Ok, it hasn't been seen before.
|
|
|
- for (i = 0; i < this->max - 1; i++) {
|
|
|
- this->tracker[i] = this->tracker[i + 1];
|
|
|
- };
|
|
|
- this->tracker[i] = this_one;
|
|
|
+ this->tracker.erase(this->tracker.begin());
|
|
|
+ this->tracker.push_back(this_one);
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+int LastSeen::best_guess(int max) {
|
|
|
+ return max / 2;
|
|
|
+}
|