summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-11-05 22:17:47 -0500
committerAdam <Adam@anope.org>2012-11-06 11:02:12 -0500
commit53b2bdfe5e157a9e5ca5d08873edebcd04511ae1 (patch)
treef94c8603ffe475405ea668c629eddd7c8ba0891e /include
parent27ab6a686cb271ea8eae7a243906af5bebeb83d7 (diff)
Use std::tr1::unordered_map for a few of the larger maps
Diffstat (limited to 'include')
-rw-r--r--include/account.h4
-rw-r--r--include/anope.h26
-rw-r--r--include/bots.h6
-rw-r--r--include/channels.h3
-rw-r--r--include/commands.h2
-rw-r--r--include/extensible.h2
-rw-r--r--include/hashcomp.h6
-rw-r--r--include/regchannel.h2
-rw-r--r--include/serialize.h2
-rw-r--r--include/service.h14
-rw-r--r--include/sockets.h8
-rw-r--r--include/users.h5
12 files changed, 55 insertions, 25 deletions
diff --git a/include/account.h b/include/account.h
index 7b98525e4..8ed1f06a4 100644
--- a/include/account.h
+++ b/include/account.h
@@ -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;
diff --git a/include/anope.h b/include/anope.h
index 421f688ef..b6033b15c 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -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.
diff --git a/include/bots.h b/include/bots.h
index 19f921dbb..888e8d217 100644
--- a/include/bots.h
+++ b/include/bots.h
@@ -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
*/
diff --git a/include/channels.h b/include/channels.h
index 2c2fbb66d..da65c1a9c 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -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
diff --git a/include/commands.h b/include/commands.h
index 08fb85d41..333d6882a 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -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;
diff --git a/include/extensible.h b/include/extensible.h
index 162a2cf6f..6db4cf112 100644
--- a/include/extensible.h
+++ b/include/extensible.h
@@ -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:
diff --git a/include/hashcomp.h b/include/hashcomp.h
index f3621a52f..9f9be9793 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -16,6 +16,12 @@
#include <string>
#include <locale>
+#ifndef _WIN32
+#include <tr1/unordered_map>
+#else
+#include <unordered_map>
+#endif
+
#include "services.h"
namespace Anope
diff --git a/include/regchannel.h b/include/regchannel.h
index 12ef308b4..a692dda4a 100644
--- a/include/regchannel.h
+++ b/include/regchannel.h
@@ -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;
diff --git a/include/serialize.h b/include/serialize.h
index 407540999..53bd096de 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -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;
diff --git a/include/service.h b/include/service.h
index 98e2d82aa..95c650076 100644
--- a/include/service.h
+++ b/include/service.h
@@ -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);
diff --git a/include/sockets.h b/include/sockets.h
index 7074522e0..6fa6c4075 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -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
diff --git a/include/users.h b/include/users.h
index 8757778b3..17f3fac9f 100644
--- a/include/users.h
+++ b/include/users.h
@@ -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>
{