summaryrefslogtreecommitdiff
path: root/include/rtl
diff options
context:
space:
mode:
authorMuthu Subramanian <sumuthu@collabora.com>2014-02-13 13:13:53 +0530
committerMuthu Subramanian <sumuthu@collabora.com>2014-02-13 13:13:53 +0530
commit8f8bc0dcf3bc253ae49159d52db049767f476ced (patch)
tree080da7007b55eac85432d41337f6ea2cda629334 /include/rtl
parent67b1dad8815f697e92258b8c079720f3a7028ea9 (diff)
Move string hash function into String class.
hashCode() seems to do sampling while creating the hash. hashCode64() will not. Change-Id: Id30f5a2a774cf5244dbc00da9649e95a532484be
Diffstat (limited to 'include/rtl')
-rw-r--r--include/rtl/string.h18
-rw-r--r--include/rtl/string.hxx13
-rw-r--r--include/rtl/ustring.h18
3 files changed, 49 insertions, 0 deletions
diff --git a/include/rtl/string.h b/include/rtl/string.h
index 32344bfa4413..71e095561a37 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 fb7283b3a801..24bb98052e40 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 80c6bccf7f3d..206989934628 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.