]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/hashcomp.cpp
(Untested) added hashcomp.cpp, seperates out the stl hash_map stuff
[user/henk/code/inspircd.git] / src / hashcomp.cpp
1 #include <string>
2 #include "inspircd.h"
3 #include "hashcomp.h"
4 #include "helperfuncs.h"
5 #ifdef GCC3
6 #include <ext/hash_map>
7 #else
8 #include <hash_map>
9 #endif
10
11 #ifdef GCC3
12 #define nspace __gnu_cxx
13 #else
14 #define nspace std
15 #endif
16
17 using namespace std;
18
19 size_t nspace::hash<in_addr>::operator()(const struct in_addr &a) const
20 {
21         size_t q;
22         memcpy(&q,&a,sizeof(size_t));
23         return q;
24 }
25
26 size_t nspace::hash<string>::operator()(const string &s) const
27 {
28         char a[MAXBUF];
29         static struct hash<const char *> strhash;
30         strlcpy(a,s.c_str(),MAXBUF);
31         strlower(a);
32         return strhash(a);
33 }
34
35 bool StrHashComp::operator()(const string& s1, const string& s2) const
36 {
37         char a[MAXBUF],b[MAXBUF];
38         strlcpy(a,s1.c_str(),MAXBUF);
39         strlcpy(b,s2.c_str(),MAXBUF);
40         strlower(a);
41         strlower(b);
42         return (strcasecmp(a,b) == 0);
43 }
44
45 bool InAddr_HashComp::operator()(const in_addr &s1, const in_addr &s2) const
46 {
47         size_t q;
48         size_t p;
49
50         memcpy(&q,&s1,sizeof(size_t));
51         memcpy(&p,&s2,sizeof(size_t));
52
53         return (q == p);
54 }
55