]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/hashcomp.cpp
1122c3867598eb1b16d9d13ae27578730473c52a
[user/henk/code/inspircd.git] / src / hashcomp.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2005 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <string>
18 #include "inspircd.h"
19 #include "hashcomp.h"
20 #include "helperfuncs.h"
21 #ifdef GCC3
22 #include <ext/hash_map>
23 #else
24 #include <hash_map>
25 #endif
26
27 #ifdef GCC3
28 #define nspace __gnu_cxx
29 #else
30 #define nspace std
31 #endif
32
33 using namespace std;
34
35 #ifdef GCC34
36 size_t hash<in_addr>::operator()(const struct in_addr &a) const
37 #else
38 size_t nspace::hash<in_addr>::operator()(const struct in_addr &a) const
39 #endif
40 {
41         size_t q;
42         memcpy(&q,&a,sizeof(size_t));
43         return q;
44 }
45
46 #ifdef GCC34
47 size_t hash<string>::operator()(const string &s) const
48 #else
49 size_t nspace::hash<string>::operator()(const string &s) const
50 #endif
51 {
52         char a[MAXBUF];
53         static struct hash<const char *> strhash;
54         strlcpy(a,s.c_str(),MAXBUF);
55         strlower(a);
56         return strhash(a);
57 }
58
59 bool StrHashComp::operator()(const string& s1, const string& s2) const
60 {
61         char a[MAXBUF],b[MAXBUF];
62         strlcpy(a,s1.c_str(),MAXBUF);
63         strlcpy(b,s2.c_str(),MAXBUF);
64         strlower(a);
65         strlower(b);
66         return (strcasecmp(a,b) == 0);
67 }
68
69 bool InAddr_HashComp::operator()(const in_addr &s1, const in_addr &s2) const
70 {
71         size_t q;
72         size_t p;
73
74         memcpy(&q,&s1,sizeof(size_t));
75         memcpy(&p,&s2,sizeof(size_t));
76
77         return (q == p);
78 }
79