Feb 13 11:03:42 <sberg> muthusuba, 8f8bc0dcf3bc253ae49159d52db049767f476ced is broken: (a) the
general O[U]String::hashCode does sampling-only by design; if that's not considered good these days we
should change the implementation rather than add another function (is 64-bit vs. 32-bit hash code of any
added value? doubt it given most hash maps will not be too big, anyway); (b) adding OString::hashCode64
but not OUString::hashCode64? (c) rtl_str_hashCode64_WithLength must
Feb 13 11:03:42 <sberg> go into a LIBO_UDK_4.3 section in sal.map, not UDK_3_0_0; (d)
rtl_ustr_hashCode64_WithLength missing from sal.map; (e) missing @since tags
include/rtl/string.h | 18 ++++++++++++++++++
include/rtl/string.hxx | 13 +++++++++++++
include/rtl/ustring.h | 18 ++++++++++++++++++
sal/rtl/strtmpl.cxx | 13 +++++++++++++
sal/util/sal.map | 1 +
sd/source/core/sdpage2.cxx | 12 +-----------
6 files changed, 64 insertions(+), 11 deletions(-)
New commits:
commit 8f8bc0dcf3bc253ae49159d52db049767f476ced
Author: Muthu Subramanian <sumuthu@collabora.com>
Date: Thu Feb 13 13:13:53 2014 +0530
Move string hash function into String class.
hashCode() seems to do sampling while creating the hash.
hashCode64() will not.
Change-Id: Id30f5a2a774cf5244dbc00da9649e95a532484be
diff --git a/include/rtl/string.h b/include/rtl/string.h
index 32344bf..71e0955 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -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.
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index fb7283b..24bb980 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -892,6 +892,19 @@ public:
}
/**
+ 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.
@return a hash code value for this object.
diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index 80c6bcc..2069899 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -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.
diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx
index fc618d3..f2eac10 100644
--- a/sal/rtl/strtmpl.cxx
+++ b/sal/rtl/strtmpl.cxx
@@ -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()
diff --git a/sal/util/sal.map b/sal/util/sal.map
index 1456d6d..470da31 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -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;
diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx
index 0f7f7cf..a870895 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -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();
}
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.