1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 19:14:47 +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
+2 -2
View File
@@ -20,8 +20,8 @@
#include "memo.h"
#include "base.h"
typedef Anope::insensitive_map<NickAlias *> nickalias_map;
typedef Anope::insensitive_map<NickCore *> nickcore_map;
typedef Anope::hash_map<NickAlias *> nickalias_map;
typedef Anope::hash_map<NickCore *> nickcore_map;
extern CoreExport serialize_checker<nickalias_map> NickAliasList;
extern CoreExport serialize_checker<nickcore_map> NickCoreList;
+21 -5
View File
@@ -15,9 +15,6 @@
namespace Anope
{
template<typename T> class map : public std::map<string, T> { };
template<typename T> class insensitive_map : public std::map<string, T, ci::less> { };
/**
* A wrapper string class around all the other string classes, this class will
* allow us to only require one type of string everywhere that can be converted
@@ -232,7 +229,7 @@ namespace Anope
/**
* Get the string in lowercase.
*/
inline string lower()
inline string lower() const
{
Anope::string new_string = *this;
for (size_type i = 0; i < new_string.length(); ++i)
@@ -243,7 +240,7 @@ namespace Anope
/**
* Get the string in uppercase.
*/
inline string upper()
inline string upper() const
{
Anope::string new_string = *this;
for (size_type i = 0; i < new_string.length(); ++i)
@@ -286,6 +283,25 @@ namespace Anope
inline const string operator+(const char *_str, const string &str) { string tmp(_str); tmp += str; return tmp; }
inline const string operator+(const std::string &_str, const string &str) { string tmp(_str); tmp += str; return tmp; }
struct hash
{
inline size_t operator()(const string &s) const
{
return std::tr1::hash<std::string>()(s.lower().str());
}
};
struct compare
{
inline bool operator()(const string &s1, const string &s2) const
{
return s1.equals_ci(s2);
}
};
template<typename T> class map : public std::map<string, T, ci::less> { };
template<typename T> class hash_map : public std::tr1::unordered_map<string, T, hash, compare> { };
static const char *const compiled = __TIME__ " " __DATE__;
/** The current system time, which is pretty close to being accurate.
+2 -4
View File
@@ -14,11 +14,9 @@
#include "commands.h"
typedef Anope::insensitive_map<BotInfo *> botinfo_map;
typedef Anope::map<BotInfo *> botinfouid_map;
typedef Anope::map<BotInfo *> botinfo_map;
extern CoreExport serialize_checker<botinfo_map> BotListByNick;
extern CoreExport serialize_checker<botinfouid_map> BotListByUID;
extern CoreExport serialize_checker<botinfo_map> BotListByNick, BotListByUID;
/** Flags settable on a bot
*/
+2 -1
View File
@@ -14,7 +14,8 @@
#include "modes.h"
#include "serialize.h"
typedef Anope::insensitive_map<Channel *> channel_map;
typedef Anope::hash_map<Channel *> channel_map;
extern CoreExport channel_map ChannelList;
struct UserContainer : public Extensible
+1 -1
View File
@@ -30,7 +30,7 @@ const Anope::string CommandFlagStrings[] = {
struct CommandInfo
{
typedef Anope::insensitive_map<CommandInfo> map;
typedef Anope::map<CommandInfo> map;
Anope::string name;
Anope::string permission;
+1 -1
View File
@@ -25,7 +25,7 @@ template<typename T> struct CoreExport ExtensibleItemClass : T, ExtensibleItem
class CoreExport Extensible
{
private:
typedef Anope::map<ExtensibleItem *> extensible_map;
typedef std::map<Anope::string, ExtensibleItem *> extensible_map;
extensible_map extension_items;
public:
+6
View File
@@ -16,6 +16,12 @@
#include <string>
#include <locale>
#ifndef _WIN32
#include <tr1/unordered_map>
#else
#include <unordered_map>
#endif
#include "services.h"
namespace Anope
+1 -1
View File
@@ -18,7 +18,7 @@
#include "serialize.h"
#include "bots.h"
typedef Anope::insensitive_map<ChannelInfo *> registered_channel_map;
typedef Anope::hash_map<ChannelInfo *> registered_channel_map;
extern CoreExport serialize_checker<registered_channel_map> RegisteredChannelList;
+1 -1
View File
@@ -109,7 +109,7 @@ class CoreExport SerializeType
typedef Serializable* (*unserialize_func)(Serializable *obj, Serialize::Data &);
static std::vector<Anope::string> type_order;
static Anope::map<SerializeType *> types;
static std::map<Anope::string, SerializeType *> types;
Anope::string name;
unserialize_func unserialize;
+7 -7
View File
@@ -17,14 +17,14 @@
class CoreExport Service : public virtual Base
{
static Anope::map<Anope::map<Service *> > services;
static std::map<Anope::string, std::map<Anope::string, Service *> > services;
public:
static Service *FindService(const Anope::string &t, const Anope::string &n)
{
Anope::map<Anope::map<Service *> >::iterator it = services.find(t);
std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = services.find(t);
if (it != services.end())
{
Anope::map<Service *>::iterator it2 = it->second.find(n);
std::map<Anope::string, Service *>::iterator it2 = it->second.find(n);
if (it2 != it->second.end())
return it2->second;
}
@@ -35,9 +35,9 @@ class CoreExport Service : public virtual Base
static std::vector<Anope::string> GetServiceKeys(const Anope::string &t)
{
std::vector<Anope::string> keys;
Anope::map<Anope::map<Service *> >::iterator it = services.find(t);
std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = services.find(t);
if (it != services.end())
for (Anope::map<Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
for (std::map<Anope::string, Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
keys.push_back(it2->first);
return keys;
}
@@ -58,7 +58,7 @@ class CoreExport Service : public virtual Base
void Register()
{
Anope::map<Service *> &smap = services[this->type];
std::map<Anope::string, Service *> &smap = services[this->type];
if (smap.find(this->name) != smap.end())
throw ModuleException("Service " + this->type + " with name " + this->name + " already exists");
smap[this->name] = this;
@@ -66,7 +66,7 @@ class CoreExport Service : public virtual Base
void Unregister()
{
Anope::map<Service *> &smap = services[this->type];
std::map<Anope::string, Service *> &smap = services[this->type];
smap.erase(this->name);
if (smap.empty())
services.erase(this->type);
+8
View File
@@ -90,7 +90,15 @@ class CoreExport cidr
cidr(const Anope::string &ip, unsigned char len);
Anope::string mask() const;
bool match(sockaddrs &other);
bool operator<(const cidr &other) const;
bool operator==(const cidr &other) const;
bool operator!=(const cidr &other) const;
struct hash
{
size_t operator()(const cidr &s) const;
};
};
class SocketException : public CoreException
+3 -2
View File
@@ -15,8 +15,9 @@
#include "commands.h"
#include "account.h"
extern CoreExport Anope::insensitive_map<User *> UserListByNick;
extern CoreExport Anope::map<User *> UserListByUID;
typedef Anope::hash_map<User *> user_map;
extern CoreExport user_map UserListByNick, UserListByUID;
class CoreExport ChannelStatus : public Flags<ChannelModeName, CMODE_END * 2>
{
+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;
+1 -1
View File
@@ -6,7 +6,7 @@
#include "access.h"
#include "bots.h"
Anope::map<Anope::map<Service *> > Service::services;
std::map<Anope::string, std::map<Anope::string, Service *> > Service::services;
void RegisterTypes()
{
+1 -2
View File
@@ -18,8 +18,7 @@
#include "extern.h"
#include "serialize.h"
serialize_checker<botinfo_map> BotListByNick("BotInfo");
serialize_checker<botinfouid_map> BotListByUID("BotInfo");
serialize_checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo");
BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", ts6_uid_retrieve()), Flags<BotFlag, BI_END>(BotFlagString), Serializable("BotInfo"), botmodes(bmodes)
{
+1 -1
View File
@@ -27,7 +27,7 @@ BotInfo* findbot(const Anope::string &nick)
BotInfo *bi = NULL;
if (isdigit(nick[0]) && ircdproto->RequiresID)
{
botinfouid_map::iterator it = BotListByUID->find(nick);
botinfo_map::iterator it = BotListByUID->find(nick);
if (it != BotListByUID->end())
bi = it->second;
}
+1 -1
View File
@@ -118,7 +118,7 @@ UplinkSocket::~UplinkSocket()
{
FOREACH_MOD(I_OnServerDisconnect, OnServerDisconnect());
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)
{
User *u = it->second;
+2 -2
View File
@@ -16,7 +16,7 @@
#include "modules.h"
std::vector<Anope::string> SerializeType::type_order;
Anope::map<SerializeType *> SerializeType::types;
std::map<Anope::string, SerializeType *> SerializeType::types;
std::list<Serializable *> *Serializable::serializable_items;
stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), _max(0)
@@ -204,7 +204,7 @@ Module* SerializeType::GetOwner() const
SerializeType *SerializeType::Find(const Anope::string &name)
{
Anope::map<SerializeType *>::iterator it = types.find(name);
std::map<Anope::string, SerializeType *>::iterator it = types.find(name);
if (it != types.end())
return it->second;
return NULL;
+2 -2
View File
@@ -91,7 +91,7 @@ Server::Server(Server *uplink, const Anope::string &name, unsigned hops, const A
}
/* We make the bots go online */
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 *u = it->second;
@@ -130,7 +130,7 @@ Server::~Server()
if (Capab.count("NOQUIT") > 0 || Capab.count("QS") > 0)
{
for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();)
{
User *u = it->second;
++it;
+38
View File
@@ -295,6 +295,44 @@ bool cidr::operator<(const cidr &other) const
}
}
bool cidr::operator==(const cidr &other) const
{
return !(*this < other) && !(other < *this);
}
bool cidr::operator!=(const cidr &other) const
{
return !(*this == other);
}
size_t cidr::hash::operator()(const cidr &s) const
{
switch (s.addr.sa.sa_family)
{
case AF_INET:
{
unsigned int m = 0xFFFFFFFFU >> (32 - s.cidr_len);
return s.addr.sa4.sin_addr.s_addr & m;
}
case AF_INET6:
{
size_t h = 0;
for (int i = 0; i < s.cidr_len / 8; ++i)
h ^= (s.addr.sa6.sin6_addr.s6_addr[i] << ((i * 8) % sizeof(size_t)));
int remaining = s.cidr_len % 8;
unsigned char m = 0xFF << (8 - remaining);
h ^= s.addr.sa6.sin6_addr.s6_addr[s.cidr_len / 8] & m;
return h;
}
default:
throw CoreException("Unknown AFTYPE for cidr");
}
}
/** Receive something from the buffer
* @param s The socket
* @param buf The buf to read to
+3 -4
View File
@@ -22,8 +22,7 @@
#include "opertype.h"
#include "extern.h"
Anope::insensitive_map<User *> UserListByNick;
Anope::map<User *> UserListByUID;
user_map UserListByNick, UserListByUID;
int32_t opcnt = 0;
uint32_t usercnt = 0, maxusercnt = 0;
@@ -856,13 +855,13 @@ User *finduser(const Anope::string &nick)
{
if (isdigit(nick[0]) && ircdproto->RequiresID)
{
Anope::map<User *>::iterator it = UserListByUID.find(nick);
user_map::iterator it = UserListByUID.find(nick);
if (it != UserListByUID.end())
return it->second;
}
else
{
Anope::insensitive_map<User *>::iterator it = UserListByNick.find(nick);
user_map::iterator it = UserListByNick.find(nick);
if (it != UserListByNick.end())
return it->second;
}