1
0
mirror of https://github.com/anope/anope.git synced 2026-07-06 20:43:12 +02:00

Use std::tr1::unordered_map for a few of the larger maps

This commit is contained in:
Adam
2012-11-05 22:17:47 -05:00
parent 27ab6a686c
commit 53b2bdfe5e
41 changed files with 182 additions and 65 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ class CommandBSBotList : public Command
list.addColumn("Nick").addColumn("Mask");
for (Anope::insensitive_map<BotInfo *>::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
{
BotInfo *bi = it->second;
+1 -1
View File
@@ -95,7 +95,7 @@ class CommandCSAKick : public Command
{
/* Match against all currently online users with equal or
* higher access. - Viper */
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
User *u2 = it->second;
+1 -1
View File
@@ -21,7 +21,7 @@ enum TypeInfo
struct SeenInfo;
static SeenInfo *FindInfo(const Anope::string &nick);
typedef Anope::insensitive_map<SeenInfo *> database_map;
typedef Anope::hash_map<SeenInfo *> database_map;
database_map database;
struct SeenInfo : Serializable
+1 -1
View File
@@ -171,7 +171,7 @@ class NSGhost : public Module
~NSGhost()
{
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
it->second->Shrink("ns_ghost_info");
}
+1 -1
View File
@@ -163,7 +163,7 @@ class CommandOSAKill : public Command
x->UID = XLineManager::GenerateUID();
unsigned int affected = 0;
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (akills->Check(it->second, x))
++affected;
float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
+6 -1
View File
@@ -153,9 +153,14 @@ class CommandOSUserList : public Command
}
else
{
/* Historically this has been ordered, so... */
Anope::map<User *> ordered_map;
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
ordered_map[it->first] = it->second;
source.Reply(_("Users list:"));
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (Anope::map<User *>::const_iterator it = ordered_map.begin(); it != ordered_map.end(); ++it)
{
User *u2 = it->second;
+1 -1
View File
@@ -121,7 +121,7 @@ class OSLogin : public Module
~OSLogin()
{
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
it->second->Shrink("os_login_password_correct");
}
+1 -1
View File
@@ -41,7 +41,7 @@ class CommandOSNOOP : public Command
Anope::string reason = "NOOP command used by " + source.GetNick();
/* Kill all the IRCops of the server */
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end();)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
{
User *u2 = it->second;
++it;
+1 -1
View File
@@ -27,7 +27,7 @@ struct Exception : Serializable
class SessionService : public Service
{
public:
typedef std::map<cidr, Session *> SessionMap;
typedef std::tr1::unordered_map<cidr, Session *, cidr::hash> SessionMap;
typedef std::vector<Exception *> ExceptionVector;
SessionService(Module *m) : Service(m, "SessionService", "session") { }
+48 -2
View File
@@ -12,6 +12,7 @@
/*************************************************************************/
#include "module.h"
#include "os_session.h"
struct Stats : Serializable
{
@@ -155,12 +156,52 @@ class CommandOSStats : public Command
return;
}
template<typename T> void GetHashStats(const T& map, size_t& entries, size_t& buckets, size_t& max_chain)
{
entries = map.size(), buckets = map.bucket_count(), max_chain = 0;
for (size_t i = 0; i < buckets; ++i)
if (map.bucket_size(i) > max_chain)
max_chain = map.bucket_size(i);
}
void DoStatsHash(CommandSource &source)
{
size_t entries, buckets, max_chain;
GetHashStats(UserListByNick, entries, buckets, max_chain);
source.Reply(_("Users (nick): %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
if (!UserListByUID.empty())
{
GetHashStats(UserListByUID, entries, buckets, max_chain);
source.Reply(_("Users (uid): %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
}
GetHashStats(ChannelList, entries, buckets, max_chain);
source.Reply(_("Channels: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
GetHashStats(*RegisteredChannelList, entries, buckets, max_chain);
source.Reply(_("Registered channels: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
GetHashStats(*NickAliasList, entries, buckets, max_chain);
source.Reply(_("Registered nicknames: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
GetHashStats(*NickCoreList, entries, buckets, max_chain);
source.Reply(_("Registered nick groups: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
if (session_service)
{
GetHashStats(session_service->GetSessions(), entries, buckets, max_chain);
source.Reply(_("Sessions: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain);
}
}
public:
CommandOSStats(Module *creator) : Command(creator, "operserv/stats", 0, 1),
akills("XLineManager", "xlinemanager/sgline"), snlines("XLineManager", "xlinemanager/snline"), sqlines("XLineManager", "xlinemanager/sqline")
{
this->SetDesc(_("Show status of Services and network"));
this->SetSyntax(_("[AKILL | ALL | RESET | UPLINK]"));
this->SetSyntax(_("[AKILL | ALL | HASH | RESET | UPLINK]"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
@@ -179,7 +220,10 @@ class CommandOSStats : public Command
if (extra.equals_ci("ALL") || extra.equals_ci("UPLINK"))
this->DoStatsUplink(source);
if (!extra.empty() && !extra.equals_ci("ALL") && !extra.equals_ci("AKILL") && !extra.equals_ci("UPLINK"))
if (extra.equals_ci("ALL") || extra.equals_ci("HASH"))
this->DoStatsHash(source);
if (!extra.empty() && !extra.equals_ci("ALL") && !extra.equals_ci("AKILL") && !extra.equals_ci("UPLINK") && !extra.equals_ci("HASH"))
source.Reply(_("Unknown STATS option \002%s\002."), extra.c_str());
}
@@ -200,6 +244,8 @@ class CommandOSStats : public Command
"The \002UPLINK\002 option displays information about the current\n"
"server Anope uses as an uplink to the network.\n"
" \n"
"The \002HASH\002 option displays information about the hash maps.\n"
" \n"
"The \002ALL\002 displays the user and uptime statistics, and\n"
"everything you'd see with the \002UPLINK\002 option."));
return true;
+4 -4
View File
@@ -357,7 +357,7 @@ class CommandOSSNLine : public CommandOSSXLineBase
x->UID = XLineManager::GenerateUID();
unsigned int affected = 0;
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (this->xlm()->Check(it->second, x))
++affected;
float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
@@ -386,7 +386,7 @@ class CommandOSSNLine : public CommandOSSXLineBase
Anope::string rreason = "G-Lined: " + reason;
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
User *user = it->second;
++it;
@@ -560,7 +560,7 @@ class CommandOSSQLine : public CommandOSSXLineBase
x->UID = XLineManager::GenerateUID();
unsigned int affected = 0;
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (this->xlm()->Check(it->second, x))
++affected;
float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
@@ -607,7 +607,7 @@ class CommandOSSQLine : public CommandOSSXLineBase
}
else
{
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
User *user = it->second;
++it;
+1 -1
View File
@@ -731,7 +731,7 @@ class DBPlain : public Module
//FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, na));
}
for (Anope::insensitive_map<BotInfo *>::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
{
BotInfo *bi = it->second;
+1 -1
View File
@@ -198,7 +198,7 @@ class BahamutIRCdProto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (x->manager->Check(it->second, x))
this->SendAkill(it->second, x);
return;
+1 -1
View File
@@ -127,7 +127,7 @@ class HybridProto : public IRCDProto
* No user (this akill was just added), and contains nick and/or realname.
* Find users that match and ban them.
*/
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (x->manager->Check(it->second, x))
this->SendAkill(it->second, x);
+1 -1
View File
@@ -151,7 +151,7 @@ class InspIRCdTS6Proto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (x->manager->Check(it->second, x))
this->SendAkill(it->second, x);
return;
+1 -1
View File
@@ -116,7 +116,7 @@ class InspIRCdProto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (x->manager->Check(it->second, x))
this->SendAkill(it->second, x);
return;
+1 -1
View File
@@ -534,7 +534,7 @@ class ProtoInspIRCd : public Module
void OnServerSync(Server *s) anope_override
{
if (nickserv)
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
User *u = it->second;
if (u->server == s && !u->IsIdentified())
+1 -1
View File
@@ -630,7 +630,7 @@ class ProtoInspIRCd : public Module
void OnServerSync(Server *s) anope_override
{
if (nickserv)
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
User *u = it->second;
if (u->server == s && !u->IsIdentified())
+2 -2
View File
@@ -107,7 +107,7 @@ class PlexusProto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (x->manager->Check(it->second, x))
this->SendAkill(it->second, x);
return;
@@ -757,7 +757,7 @@ class ProtoPlexus : public Module
void OnServerSync(Server *s) anope_override
{
if (nickserv)
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
User *u = it->second;
if (u->server == s && !u->IsIdentified())
+2 -2
View File
@@ -97,7 +97,7 @@ class RatboxProto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (x->manager->Check(it->second, x))
this->SendAkill(it->second, x);
return;
@@ -631,7 +631,7 @@ class ProtoRatbox : public Module
void OnServerSync(Server *s) anope_override
{
if (nickserv)
for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
User *u = it->second;
if (u->server == s && !u->IsIdentified())
+1 -1
View File
@@ -88,7 +88,7 @@ class UnrealIRCdProto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (x->manager->Check(it->second, x))
this->SendAkill(it->second, x);
return;