aboutsummaryrefslogtreecommitdiff
path: root/src/hash.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/hash.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/hash.cpp b/src/hash.cpp
index b4aac77..14be208 100644
--- a/src/hash.cpp
+++ b/src/hash.cpp
@@ -1 +1,81 @@
1#include "hash.h" 1#include "hash.h"
2
3template<>
4uint32_t __calcHashCode<const char *>( const char * k )
5{
6 if (k == NULL)
7 {
8 return 0;
9 }
10
11 unsigned long int nPos = 0;
12 for( const char *s = k; *s; s++ )
13 {
14 nPos = *s + (nPos << 6) + (nPos << 16) - nPos;
15 }
16
17 return nPos;
18}
19
20template<> bool __cmpHashKeys<const char *>( const char *a, const char *b )
21{
22 if( a == b )
23 return true;
24
25 for(; *a != *b; a++, b++ )
26 if( *a == '\0' && *b == '\0' )
27 return true;
28
29 return false;
30}
31
32template<>
33uint32_t __calcHashCode<char *>( char *k )
34{
35 return __calcHashCode<const char *>((const char *)k );
36}
37
38template<> bool __cmpHashKeys<char *>( char *a, char *b )
39{
40 return __cmpHashKeys<const char *>((const char *)a, (const char *)b );
41}
42
43template<> uint32_t __calcHashCode<const std::string>( const std::string k )
44{
45 std::string::size_type j, sz = k.size();
46 const char *s = k.c_str();
47
48 unsigned long int nPos = 0;
49 for( j = 0; j < sz; j++, s++ )
50 {
51 nPos = *s + (nPos << 6) + (nPos << 16) - nPos;
52 }
53
54 return nPos;
55}
56
57template<> bool __cmpHashKeys<const std::string>( const std::string a, const std::string b )
58{
59 return a == b;
60}
61
62template<> uint32_t __calcHashCode<std::string>( std::string k )
63{
64 return __calcHashCode<const std::string>( k );
65}
66
67template<> bool __cmpHashKeys<std::string>( std::string a, std::string b )
68{
69 return __cmpHashKeys<const std::string>( a, b );
70}
71
72template<> uint32_t __calcHashCode<Hashable &>( Hashable &k )
73{
74 return k.getHashCode();
75}
76
77template<> bool __cmpHashKeys<Hashable &>( Hashable &a, Hashable &b )
78{
79 return a.compareForHash( b );
80}
81