#include "stdafx.h" #include "ioHashString.h" ioHashString::ioHashString() { m_iCapacity = DEFAULT_CAPACITY; m_pString = new char[ m_iCapacity ]; Clear(); m_dwHashCode = CalcHashCode( m_pString ); } ioHashString::ioHashString( const char* str ) : m_pString(NULL) { m_iLength = strlen( str ); int iCapacity = max( m_iLength + 1, DEFAULT_CAPACITY ); ReAllocCapacity( iCapacity ); strcpy_s( m_pString, iCapacity, str ); m_dwHashCode = CalcHashCode( str ); } ioHashString::ioHashString( const ioHashString &rhs ) : m_pString(NULL) { m_iLength = rhs.Length(); ReAllocCapacity( rhs.m_iCapacity ); strcpy_s( m_pString, rhs.m_iCapacity, rhs.m_pString ); m_dwHashCode = rhs.m_dwHashCode; } ioHashString::~ioHashString() { if( m_pString ) { delete[] m_pString; m_pString = NULL; } } bool ioHashString::IsEmpty() const { return ( m_iLength == 0 ); } int ioHashString::Length() const { return m_iLength; } void ioHashString::Clear() { memset( m_pString, 0, m_iCapacity ); m_iLength = 0; } const char* ioHashString::c_str() const { return m_pString; } void ioHashString::ReAllocCapacity( int iNewCapacity ) { if( m_pString ) { delete[] m_pString; m_pString = NULL; } m_iCapacity = iNewCapacity; m_pString = new char[iNewCapacity]; } DWORD ioHashString::CalcHashCode( const char *str ) { DWORD dwLen, dwCh, dwResult; dwLen = strlen( str ); dwResult = HASH_CONST; for( DWORD i=0; i