diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2007-08-05 05:27:17 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2007-08-05 05:27:17 +0000 |
| commit | d3b44beef6e899b65f15a1c27bb76e255d8651d3 (patch) | |
| tree | 68ca3699833496d2126c0a2a3d857c9899665aa9 /src/set.cpp | |
| parent | 9cf4949ff56464ce4737fd3a0e6b757032354b0e (diff) | |
| download | libbu++-d3b44beef6e899b65f15a1c27bb76e255d8651d3.tar.gz libbu++-d3b44beef6e899b65f15a1c27bb76e255d8651d3.tar.bz2 libbu++-d3b44beef6e899b65f15a1c27bb76e255d8651d3.tar.xz libbu++-d3b44beef6e899b65f15a1c27bb76e255d8651d3.zip | |
Ok, the set looks like it works. That's kinda' cool. It could use a few more
operators, but that's a minor issue.
Diffstat (limited to '')
| -rw-r--r-- | src/set.cpp | 101 |
1 files changed, 2 insertions, 99 deletions
diff --git a/src/set.cpp b/src/set.cpp index a207c29..69f4996 100644 --- a/src/set.cpp +++ b/src/set.cpp | |||
| @@ -1,101 +1,4 @@ | |||
| 1 | #include "hash.h" | 1 | #include "set.h" |
| 2 | 2 | ||
| 3 | namespace Bu { subExceptionDef( HashException ) } | 3 | namespace Bu { subExceptionDef( SetException ) } |
| 4 | |||
| 5 | template<> uint32_t Bu::__calcHashCode<int>( const int &k ) | ||
| 6 | { | ||
| 7 | return k; | ||
| 8 | } | ||
| 9 | |||
| 10 | template<> bool Bu::__cmpHashKeys<int>( const int &a, const int &b ) | ||
| 11 | { | ||
| 12 | return a == b; | ||
| 13 | } | ||
| 14 | |||
| 15 | template<> uint32_t Bu::__calcHashCode<unsigned int>( const unsigned int &k ) | ||
| 16 | { | ||
| 17 | return k; | ||
| 18 | } | ||
| 19 | |||
| 20 | template<> bool Bu::__cmpHashKeys<unsigned int>( const unsigned int &a, const unsigned int &b ) | ||
| 21 | { | ||
| 22 | return a == b; | ||
| 23 | } | ||
| 24 | |||
| 25 | template<> | ||
| 26 | uint32_t Bu::__calcHashCode<const char *>( const char * const &k ) | ||
| 27 | { | ||
| 28 | if (k == NULL) | ||
| 29 | { | ||
| 30 | return 0; | ||
| 31 | } | ||
| 32 | |||
| 33 | unsigned long int nPos = 0; | ||
| 34 | for( const char *s = k; *s; s++ ) | ||
| 35 | { | ||
| 36 | nPos = *s + (nPos << 6) + (nPos << 16) - nPos; | ||
| 37 | } | ||
| 38 | |||
| 39 | return nPos; | ||
| 40 | } | ||
| 41 | |||
| 42 | template<> bool Bu::__cmpHashKeys<const char *>( const char * const &a, const char * const &b ) | ||
| 43 | { | ||
| 44 | if( a == b ) | ||
| 45 | return true; | ||
| 46 | |||
| 47 | for(int j=0; a[j] == b[j]; j++ ) | ||
| 48 | if( a[j] == '\0' ) | ||
| 49 | return true; | ||
| 50 | |||
| 51 | return false; | ||
| 52 | } | ||
| 53 | |||
| 54 | template<> | ||
| 55 | uint32_t Bu::__calcHashCode<char *>( char * const &k ) | ||
| 56 | { | ||
| 57 | if (k == NULL) | ||
| 58 | { | ||
| 59 | return 0; | ||
| 60 | } | ||
| 61 | |||
| 62 | unsigned long int nPos = 0; | ||
| 63 | for( const char *s = k; *s; s++ ) | ||
| 64 | { | ||
| 65 | nPos = *s + (nPos << 6) + (nPos << 16) - nPos; | ||
| 66 | } | ||
| 67 | |||
| 68 | return nPos; | ||
| 69 | } | ||
| 70 | |||
| 71 | template<> bool Bu::__cmpHashKeys<char *>( char * const &a, char * const &b ) | ||
| 72 | { | ||
| 73 | if( a == b ) | ||
| 74 | return true; | ||
| 75 | |||
| 76 | for(int j=0; a[j] == b[j]; j++ ) | ||
| 77 | if( a[j] == '\0' ) | ||
| 78 | return true; | ||
| 79 | |||
| 80 | return false; | ||
| 81 | } | ||
| 82 | |||
| 83 | template<> uint32_t Bu::__calcHashCode<std::string>( const std::string &k ) | ||
| 84 | { | ||
| 85 | std::string::size_type j, sz = k.size(); | ||
| 86 | const char *s = k.c_str(); | ||
| 87 | |||
| 88 | unsigned long int nPos = 0; | ||
| 89 | for( j = 0; j < sz; j++, s++ ) | ||
| 90 | { | ||
| 91 | nPos = *s + (nPos << 6) + (nPos << 16) - nPos; | ||
| 92 | } | ||
| 93 | |||
| 94 | return nPos; | ||
| 95 | } | ||
| 96 | |||
| 97 | template<> bool Bu::__cmpHashKeys<std::string>( const std::string &a, const std::string &b ) | ||
| 98 | { | ||
| 99 | return a == b; | ||
| 100 | } | ||
| 101 | 4 | ||
