mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Commands: Remove temporary set with custom comparator from .debug objectcount command
This commit is contained in:
@@ -1716,37 +1716,40 @@ public:
|
||||
class CreatureCountWorker
|
||||
{
|
||||
public:
|
||||
CreatureCountWorker() { }
|
||||
|
||||
void Visit(std::unordered_map<ObjectGuid, Creature*>& creatureMap)
|
||||
void Visit(std::unordered_map<ObjectGuid, Creature*> const& creatureMap)
|
||||
{
|
||||
for (auto const& p : creatureMap)
|
||||
{
|
||||
uint32& count = creatureIds[p.second->GetEntry()];
|
||||
++count;
|
||||
}
|
||||
for (auto const& [_, creature] : creatureMap)
|
||||
++creatureCountsById[creature->GetEntry()];
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Visit(std::unordered_map<ObjectGuid, T*>&) { }
|
||||
static void Visit(std::unordered_map<ObjectGuid, T*> const&) { }
|
||||
|
||||
std::vector<std::pair<uint32, uint32>> GetTopCreatureCount(uint32 count)
|
||||
std::vector<std::pair<uint32, uint32>> GetTopCreatureCount(std::size_t count) const
|
||||
{
|
||||
auto comp = [](std::pair<uint32, uint32> const& a, std::pair<uint32, uint32> const& b)
|
||||
{
|
||||
return a.second > b.second;
|
||||
};
|
||||
std::set<std::pair<uint32, uint32>, decltype(comp)> set(creatureIds.begin(), creatureIds.end(), comp);
|
||||
count = std::min(count, creatureCountsById.size());
|
||||
std::vector<std::pair<uint32, uint32>> result;
|
||||
if (!count)
|
||||
return result;
|
||||
|
||||
count = std::min(count, uint32(set.size()));
|
||||
std::vector<std::pair<uint32, uint32>> result(count);
|
||||
std::copy_n(set.begin(), count, result.begin());
|
||||
result.reserve(count + 1);
|
||||
|
||||
for (auto const& [creatureId, creatureCount] : creatureCountsById)
|
||||
{
|
||||
if (result.size() >= count && result.back().second > creatureCount)
|
||||
continue;
|
||||
|
||||
auto where = std::ranges::lower_bound(result, creatureCount, std::ranges::greater(), Trinity::TupleElement<1>);
|
||||
result.emplace(where, creatureId, creatureCount);
|
||||
if (result.size() > count)
|
||||
result.pop_back();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<uint32, uint32> creatureIds;
|
||||
std::unordered_map<uint32, uint32> creatureCountsById;
|
||||
};
|
||||
|
||||
static void HandleDebugObjectCountMap(ChatHandler* handler, Map* map)
|
||||
@@ -1763,8 +1766,8 @@ public:
|
||||
|
||||
handler->PSendSysMessage("Top Creatures count:");
|
||||
|
||||
for (auto&& p : worker.GetTopCreatureCount(5))
|
||||
handler->PSendSysMessage("Entry: %u Count: %u", p.first, p.second);
|
||||
for (auto const& [creatureId, count] : worker.GetTopCreatureCount(5))
|
||||
handler->PSendSysMessage("Entry: %u Count: %u", creatureId, count);
|
||||
}
|
||||
|
||||
static bool HandleDebugBecomePersonalClone(ChatHandler* handler)
|
||||
|
||||
Reference in New Issue
Block a user