00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "CeylanHashable.h"
00028
00029
00030 using std::string ;
00031
00032 #include "CeylanOperators.h"
00033
00034
00035
00036 using namespace Ceylan ;
00037
00038
00039
00040 Hashable::Hashable()
00041 {
00042
00043 }
00044
00045
00046
00047 Hashable::~Hashable() throw()
00048 {
00049
00050 }
00051
00052
00053
00054 const string Hashable::toString( VerbosityLevels level ) const
00055 {
00056
00057 if ( level == Ceylan::low )
00058 return "Hashable object" ;
00059
00060 if ( level == Ceylan::medium )
00061 return "Hashable object whose weak hash code is "
00062 + Ceylan::toString( getWeakHashCode() ) ;
00063
00064 return "Hashable object whose strong hash code is "
00065 + Ceylan::toString( getStrongHashCode() ) ;
00066
00067 }
00068
00069
00070
00071 WeakHashCode Hashable::GetWeakHashCode( const std::string & stringToHash )
00072 {
00073
00074 WeakHashCode hash = 0 ;
00075
00076 Ceylan::Uint32 charCount = 0 ;
00077
00078 while ( stringToHash[charCount] )
00079 {
00080
00081 hash <<= 1 ;
00082
00083 hash = hash ^ stringToHash[charCount] ;
00084 charCount++ ;
00085
00086 }
00087
00088 return hash ;
00089
00090 }
00091
00092
00093
00094 StrongHashCode Hashable::GetStrongHashCode( const std::string & stringToHash )
00095 {
00096
00097 StrongHashCode hash = 0 ;
00098
00099 Ceylan::Uint32 charCount = 0 ;
00100
00101 while ( stringToHash[charCount] )
00102 {
00103
00104 hash <<= 1 ;
00105
00106 hash = hash ^ stringToHash[charCount] ;
00107 charCount++ ;
00108
00109 }
00110
00111 return hash ;
00112
00113 }
00114