diff options
Diffstat (limited to 'src/old/hashfunctionstring.cpp')
-rw-r--r-- | src/old/hashfunctionstring.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/old/hashfunctionstring.cpp b/src/old/hashfunctionstring.cpp new file mode 100644 index 0000000..bd14643 --- /dev/null +++ b/src/old/hashfunctionstring.cpp | |||
@@ -0,0 +1,51 @@ | |||
1 | #include "hashfunctionstring.h" | ||
2 | #ifndef NULL | ||
3 | #define NULL ((void *) 0) | ||
4 | #endif | ||
5 | |||
6 | HashFunctionString::HashFunctionString() | ||
7 | { | ||
8 | } | ||
9 | |||
10 | HashFunctionString::~HashFunctionString() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | unsigned long int HashFunctionString::hash( const void *id ) | ||
15 | { | ||
16 | if (id == NULL) | ||
17 | { | ||
18 | return 0; | ||
19 | } | ||
20 | |||
21 | unsigned long int nPos = 0; | ||
22 | for( const char *s = (const char *)id; *s; s++ ) | ||
23 | { | ||
24 | nPos = *s + (nPos << 6) + (nPos << 16) - nPos; | ||
25 | } | ||
26 | return nPos; | ||
27 | } | ||
28 | |||
29 | bool HashFunctionString::cmpIDs( const void *id1, const void *id2 ) | ||
30 | { | ||
31 | if (id1 == NULL || id2 == NULL) | ||
32 | { | ||
33 | return false; | ||
34 | } | ||
35 | if (id1 == id2) | ||
36 | { | ||
37 | return true; | ||
38 | } | ||
39 | |||
40 | const char *str1 = (const char *)id1; | ||
41 | const char *str2 = (const char *)id2; | ||
42 | |||
43 | int j; | ||
44 | for( j = 0; str1[j] != '\0' && str2[j] != '\0'; j++ ) | ||
45 | { | ||
46 | if( str1[j] != str2[j] ) | ||
47 | return false; | ||
48 | } | ||
49 | return (str1[j]==str2[j]); | ||
50 | } | ||
51 | |||