Switch from vector to unordered_set

develop
lethosor 2021-04-05 23:28:42 -04:00
parent 1c3e60337c
commit 40c2b19083
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
1 changed files with 5 additions and 14 deletions

@ -46,6 +46,7 @@
#include "df/world.h" #include "df/world.h"
#include <map> #include <map>
#include <unordered_set>
#include <vector> #include <vector>
using namespace DFHack; using namespace DFHack;
@ -60,7 +61,7 @@ DFHACK_PLUGIN_IS_ENABLED(dwarfvet_enabled);
REQUIRE_GLOBAL(ui); REQUIRE_GLOBAL(ui);
REQUIRE_GLOBAL(world); REQUIRE_GLOBAL(world);
static vector<int32_t> tracked_units; static unordered_set<int32_t> tracked_units;
static int32_t howOften = 100; static int32_t howOften = 100;
struct hospital_spot { struct hospital_spot {
@ -357,12 +358,7 @@ void AnimalHospital::dischargePatient(Patient * patient, color_ostream &out) {
} }
// And the master list // And the master list
for (vector<int32_t>::iterator it = tracked_units.begin(); it != tracked_units.end(); it++) { tracked_units.erase(id);
if ((*it) == id) {
tracked_units.erase(it);
break;
}
}
return; return;
} }
@ -708,12 +704,7 @@ processUnits:
*/ */
// Now we need to find if this unit can be accepted at a hospital // Now we need to find if this unit can be accepted at a hospital
bool awareOfUnit = false; bool awareOfUnit = tracked_units.count(unit->id);
for (vector<int32_t>::iterator it = tracked_units.begin(); it != tracked_units.end(); it++) {
if ((*it) == unit->id) {
awareOfUnit = true;
}
}
// New unit for dwarfvet to be aware of! // New unit for dwarfvet to be aware of!
if (!awareOfUnit) { if (!awareOfUnit) {
// The master list handles all patients which are accepted // The master list handles all patients which are accepted
@ -722,7 +713,7 @@ processUnits:
for (auto animal_hospital : animal_hospital_zones) { for (auto animal_hospital : animal_hospital_zones) {
if (animal_hospital->acceptPatient(unit->id, out)) { if (animal_hospital->acceptPatient(unit->id, out)) {
out.print("Accepted patient %d at hospital %d\n", unit->id, animal_hospital->getID()); out.print("Accepted patient %d at hospital %d\n", unit->id, animal_hospital->getID());
tracked_units.push_back(unit->id); tracked_units.insert(unit->id);
break; break;
} }
} }