diff options
Diffstat (limited to '')
| -rw-r--r-- | src/hash.cpp | 2 | ||||
| -rw-r--r-- | src/tests/hash.cpp | 19 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/hash.cpp b/src/hash.cpp index a32fa2a..d477aff 100644 --- a/src/hash.cpp +++ b/src/hash.cpp | |||
| @@ -44,7 +44,7 @@ template<> bool __cmpHashKeys<const char *>( const char *a, const char *b ) | |||
| 44 | if( a == b ) | 44 | if( a == b ) |
| 45 | return true; | 45 | return true; |
| 46 | 46 | ||
| 47 | for(; *a != *b; a++, b++ ) | 47 | for(; *a == *b; a++, b++ ) |
| 48 | if( *a == '\0' && *b == '\0' ) | 48 | if( *a == '\0' && *b == '\0' ) |
| 49 | return true; | 49 | return true; |
| 50 | 50 | ||
diff --git a/src/tests/hash.cpp b/src/tests/hash.cpp index 58e0112..2fc6968 100644 --- a/src/tests/hash.cpp +++ b/src/tests/hash.cpp | |||
| @@ -58,24 +58,28 @@ int main() | |||
| 58 | NULL | 58 | NULL |
| 59 | }; | 59 | }; |
| 60 | 60 | ||
| 61 | Hash<std::string, int> sTest; | 61 | Hash<const char *, int> sTest; |
| 62 | 62 | ||
| 63 | printf("Inserting\n-------------------\n\n"); | 63 | printf("Inserting\n-------------------\n\n"); |
| 64 | for( int j = 0; j < 33; j++ ) | 64 | for( int j = 0; j < 33; j++ ) |
| 65 | { | 65 | { |
| 66 | sTest[names[j]] = j; | 66 | sTest[names[j]] = j; |
| 67 | } | 67 | } |
| 68 | |||
| 69 | printf("Test1: %d, Test2: %d\n", sTest.has("Lemon of Troy"), sTest.has(std::string("Lemon of Troy").c_str() ) ); | ||
| 70 | |||
| 71 | sTest.has(std::string("Lemon of Troy").c_str() ); | ||
| 68 | 72 | ||
| 69 | printf("Getting\n-------------------\n\n"); | 73 | printf("Getting\n-------------------\n\n"); |
| 70 | 74 | ||
| 71 | sTest.erase("Homer the Great"); | 75 | sTest.erase("Homer the Great"); |
| 72 | sTest["Bart's Comet"].erase(); | 76 | sTest["Bart's Comet"].erase(); |
| 73 | 77 | ||
| 74 | for( Hash<std::string, int>::iterator i = sTest.begin(); | 78 | for( Hash<const char *, int>::iterator i = sTest.begin(); |
| 75 | i != sTest.end(); i++ ) | 79 | i != sTest.end(); i++ ) |
| 76 | { | 80 | { |
| 77 | Hash<std::string, int>::iterator j = i; | 81 | Hash<const char *, int>::iterator j = i; |
| 78 | printf("%d: %s\n", (*j).second, (*j).first.c_str() ); | 82 | printf("%d: %s\n", (*j).second, (*j).first ); |
| 79 | } | 83 | } |
| 80 | 84 | ||
| 81 | printf("Testing\n-------------------\n\n"); | 85 | printf("Testing\n-------------------\n\n"); |
| @@ -101,11 +105,12 @@ int main() | |||
| 101 | 105 | ||
| 102 | sTest.clear(); | 106 | sTest.clear(); |
| 103 | 107 | ||
| 104 | for( Hash<std::string, int>::iterator i = sTest.begin(); | 108 | for( Hash<const char *, int>::iterator i = sTest.begin(); |
| 105 | i != sTest.end(); i++ ) | 109 | i != sTest.end(); i++ ) |
| 106 | { | 110 | { |
| 107 | Hash<std::string, int>::iterator j = i; | 111 | Hash<const char *, int>::iterator j = i; |
| 108 | printf("%d: %s\n", (*j).second, (*j).first.c_str() ); | 112 | printf("%d: %s\n", (*j).second, (*j).first ); |
| 109 | } | 113 | } |
| 114 | |||
| 110 | } | 115 | } |
| 111 | 116 | ||
