Kaydet (Commit) 8f8bc0dc authored tarafından Muthu Subramanian's avatar Muthu Subramanian

Move string hash function into String class.

hashCode() seems to do sampling while creating the hash.
hashCode64() will not.

Change-Id: Id30f5a2a774cf5244dbc00da9649e95a532484be
üst 67b1dad8
......@@ -277,6 +277,24 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_hashCode(
SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_hashCode_WithLength(
const sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
/** Return a hash code (64bit) for a string.
It is not allowed to store the hash code persistently, because later
versions could return other hash codes.
@param str
a string. Need not be null-terminated, but must be at least as long as
the specified len.
@param len
the length of the string.
@return
a hash code for the given string.
*/
SAL_DLLPUBLIC sal_uInt64 SAL_CALL rtl_str_hashCode64_WithLength(
const sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
/** Search for the first occurrence of a character within a string.
The string must be null-terminated.
......
......@@ -891,6 +891,19 @@ public:
return !( literal == rStr );
}
/**
Returns a 64bit hash of the string data.
This hashes the entire data, while hashCode would do sampling for larger string sizes.
@return a hash code value of the string data
@see hashCode() for simple hashes
*/
sal_uInt64 hashCode64() const SAL_THROW(())
{
return rtl_str_hashCode64_WithLength( pData->buffer, pData->length );
}
/**
Returns a hashcode for this string.
......
......@@ -551,6 +551,24 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_hashCode(
SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_hashCode_WithLength(
const sal_Unicode * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
/** Return a hash code (64bit) for a string.
It is not allowed to store the hash code persistently, because later
versions could return other hash codes.
@param str
a string. Need not be null-terminated, but must be at least as long as
the specified len.
@param len
the length of the string.
@return
a hash code for the given string.
*/
SAL_DLLPUBLIC sal_uInt64 SAL_CALL rtl_ustr_hashCode64_WithLength(
const sal_Unicode * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
/** Search for the first occurrence of a character within a string.
The string must be null-terminated.
......
......@@ -252,6 +252,19 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode )( const IMPL_RTL_STRCODE* pStr )
/* ----------------------------------------------------------------------- */
sal_uInt64 SAL_CALL IMPL_RTL_STRNAME( hashCode64_WithLength )( const IMPL_RTL_STRCODE* pStr,
sal_Int32 nLen )
SAL_THROW_EXTERN_C()
{
sal_uInt64 nHash = 0;
for( sal_Int32 i = 0; i < nLen; i++ )
nHash = (nHash << 5) - nHash + *pStr++;
return nHash;
}
/* ----------------------------------------------------------------------- */
sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCODE* pStr,
sal_Int32 nLen )
SAL_THROW_EXTERN_C()
......
......@@ -221,6 +221,7 @@ UDK_3_0_0 {
rtl_str_shortenedCompareIgnoreAsciiCase_WithLength;
rtl_str_hashCode;
rtl_str_hashCode_WithLength;
rtl_str_hashCode64_WithLength;
rtl_str_indexOfChar;
rtl_str_indexOfChar_WithLength;
rtl_str_indexOfStr;
......
......@@ -54,16 +54,6 @@ using namespace ::com::sun::star::office;
extern void NotifyDocumentEvent( SdDrawDocument* pDocument, const OUString& rEventName, const Reference< XInterface >& xSource );
static sal_uInt64 lcl_getHash( OString aString )
{
sal_Int32 len = aString.getLength();
sal_uInt64 nHash = 0;
for( sal_Int32 i = 0; i < len; i++ )
nHash = (nHash << 5) - nHash + aString[i];
return nHash;
}
/*************************************************************************
|*
|* Sets: names of layout, master page links and templates for presentation
......@@ -615,7 +605,7 @@ OString SdPage::stringify() const
sal_uInt64 SdPage::getHash() const
{
return lcl_getHash( stringify() );
return stringify().hashCode64();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment