1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2005 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
20 #include "helperfuncs.h"
22 #include <ext/hash_map>
28 #define nspace __gnu_cxx
33 /******************************************************
35 * The hash functions of InspIRCd are the centrepoint
36 * of the entire system. If these functions are
37 * inefficient or wasteful, the whole program suffers
38 * as a result. A lot of C programmers in the ircd
39 * scene spend a lot of time debating (arguing) about
40 * the best way to write hash functions to hash irc
41 * nicknames, channels etc.
42 * We are lucky as C++ developers as hash_map does
43 * a lot of this for us. It does intellegent memory
44 * requests, bucketing, search functions, insertion
45 * and deletion etc. All we have to do is write some
46 * overloaded comparison and hash value operators which
47 * cause it to act in an irc-like way. The features we
48 * add to the standard hash_map are:
50 * Case insensitivity: The hash_map will be case
53 * Scandanavian Comparisons: The characters [, ], \ will
54 * be considered the lowercase of {, } and |.
56 * This file also contains hashing methods for hashing
57 * in_addr structs, we use this if we want to cache IP
60 ******************************************************/
64 size_t nspace::hash<in_addr>::operator()(const struct in_addr &a) const
67 memcpy(&q,&a,sizeof(size_t));
71 size_t nspace::hash<string>::operator()(const string &s) const
74 static struct hash<const char *> strhash;
75 strlcpy(a,s.c_str(),MAXBUF);
80 bool StrHashComp::operator()(const string& s1, const string& s2) const
82 char a[MAXBUF],b[MAXBUF];
83 strlcpy(a,s1.c_str(),MAXBUF);
84 strlcpy(b,s2.c_str(),MAXBUF);
87 return (strcasecmp(a,b) == 0);
90 bool InAddr_HashComp::operator()(const in_addr &s1, const in_addr &s2) const
95 memcpy(&q,&s1,sizeof(size_t));
96 memcpy(&p,&s2,sizeof(size_t));