diff options
author | th <th@openoffice.org> | 2001-03-16 15:38:28 +0000 |
---|---|---|
committer | th <th@openoffice.org> | 2001-03-16 15:38:28 +0000 |
commit | c07bfba36e7a8288c6dc40795bd28ca3594e05b5 (patch) | |
tree | 4e7b4080b40b0070c63714595cb6f887fd4bec16 | |
parent | 92fc8945b3ba35d5eec4652761a04009213e205e (diff) |
create better hashcodes
-rw-r--r-- | sal/rtl/source/strtmpl.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/sal/rtl/source/strtmpl.c b/sal/rtl/source/strtmpl.c index ff269f1e5..b961f3965 100644 --- a/sal/rtl/source/strtmpl.c +++ b/sal/rtl/source/strtmpl.c @@ -2,9 +2,9 @@ * * $RCSfile: strtmpl.c,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: th $ $Date: 2001-03-16 14:57:57 $ + * last change: $Author: th $ $Date: 2001-03-16 16:38:28 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -158,11 +158,10 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode )( const IMPL_RTL_STRCODE* pStr ) sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCODE* pStr, sal_Int32 nLen ) { - sal_Int32 h; + sal_Int32 h = nLen; if ( nLen < 16 ) { - h = 0; while ( nLen > 0 ) { h = (h*37) + IMPL_RTL_USTRCODE( *pStr ); @@ -173,11 +172,11 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCO else { sal_Int32 nSkip; - const IMPL_RTL_STRCODE* pEndStr = pStr+nLen-4; + const IMPL_RTL_STRCODE* pEndStr = pStr+nLen-5; /* only sample some characters */ - /* the first 3, some characters between, and the last 3 */ - h = IMPL_RTL_USTRCODE( *pStr ); + /* the first 3, some characters between, and the last 5 */ + h = (h*39) + IMPL_RTL_USTRCODE( *pStr ); pStr++; h = (h*39) + IMPL_RTL_USTRCODE( *pStr ); pStr++; @@ -188,7 +187,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCO nSkip = nLen / 4; else nSkip = nLen / 8; - nLen -= 6; + nLen -= 8; while ( nLen > 0 ) { h = (h*39) + IMPL_RTL_USTRCODE( *pStr ); @@ -201,6 +200,10 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCO h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr ); pEndStr++; h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr ); + pEndStr++; + h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr ); + pEndStr++; + h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr ); } return h; |