00001 #include "HashString.h" 00002 00003 HashString::HashString() 00004 : m_ulHash(0) 00005 { 00006 } 00007 00008 HashString::HashString(const std::string &typeStr) 00009 : m_ulHash(0) 00010 { 00011 setStr(typeStr); 00012 } 00013 00014 void HashString::setStr(const std::string &typeStr) 00015 { 00016 m_sTypeStr = typeStr; 00017 m_ulHash = HashString::StringToHash(typeStr); 00018 } 00019 00020 unsigned long HashString::StringToHash(const std::string &str) 00021 { 00022 const char* pCStr = str.c_str(); 00023 00024 unsigned long hash = 5381; 00025 int c; 00026 00027 while (c = *pCStr++) 00028 hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 00029 00030 return hash; 00031 }
1.5.9