From 9cf4949ff56464ce4737fd3a0e6b757032354b0e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 5 Aug 2007 04:57:04 +0000 Subject: Set is just a copy of hash for now. It'd be cool if they could be linked, not really sure how that could happen easily. --- src/set.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/set.cpp (limited to 'src/set.cpp') diff --git a/src/set.cpp b/src/set.cpp new file mode 100644 index 0000000..a207c29 --- /dev/null +++ b/src/set.cpp @@ -0,0 +1,101 @@ +#include "hash.h" + +namespace Bu { subExceptionDef( HashException ) } + +template<> uint32_t Bu::__calcHashCode( const int &k ) +{ + return k; +} + +template<> bool Bu::__cmpHashKeys( const int &a, const int &b ) +{ + return a == b; +} + +template<> uint32_t Bu::__calcHashCode( const unsigned int &k ) +{ + return k; +} + +template<> bool Bu::__cmpHashKeys( const unsigned int &a, const unsigned int &b ) +{ + return a == b; +} + +template<> +uint32_t Bu::__calcHashCode( const char * const &k ) +{ + if (k == NULL) + { + return 0; + } + + unsigned long int nPos = 0; + for( const char *s = k; *s; s++ ) + { + nPos = *s + (nPos << 6) + (nPos << 16) - nPos; + } + + return nPos; +} + +template<> bool Bu::__cmpHashKeys( const char * const &a, const char * const &b ) +{ + if( a == b ) + return true; + + for(int j=0; a[j] == b[j]; j++ ) + if( a[j] == '\0' ) + return true; + + return false; +} + +template<> +uint32_t Bu::__calcHashCode( char * const &k ) +{ + if (k == NULL) + { + return 0; + } + + unsigned long int nPos = 0; + for( const char *s = k; *s; s++ ) + { + nPos = *s + (nPos << 6) + (nPos << 16) - nPos; + } + + return nPos; +} + +template<> bool Bu::__cmpHashKeys( char * const &a, char * const &b ) +{ + if( a == b ) + return true; + + for(int j=0; a[j] == b[j]; j++ ) + if( a[j] == '\0' ) + return true; + + return false; +} + +template<> uint32_t Bu::__calcHashCode( const std::string &k ) +{ + std::string::size_type j, sz = k.size(); + const char *s = k.c_str(); + + unsigned long int nPos = 0; + for( j = 0; j < sz; j++, s++ ) + { + nPos = *s + (nPos << 6) + (nPos << 16) - nPos; + } + + return nPos; +} + +template<> bool Bu::__cmpHashKeys( const std::string &a, const std::string &b ) +{ + return a == b; +} + -- cgit v1.2.3