merge the formfield patch from ooo-build
[ooovba.git] / sw / inc / stringhash.hxx
blobe034f5458b417c18902a4251abbc967bf6cbc32f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: stringhash.hxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _STRINGHASH_HXX
31 #define _STRINGHASH_HXX
33 #include <tools/string.hxx>
35 struct StringEq
37 sal_Bool operator() ( const String *r1,
38 const String *r2) const
40 return r1->Equals(*r2);
44 struct StringEqRef
46 sal_Bool operator() (const String &r1, const String &r2) const
48 return r1.Equals(r2);
52 struct StringHash
54 size_t operator() ( const String *rString) const
56 sal_Int32 h, nLen;
57 h = nLen = rString->Len();
58 const sal_Unicode *pStr = rString->GetBuffer();
60 if ( nLen < 16 )
61 while ( nLen-- > 0 )
62 h = (h*37) + *(pStr++);
63 else
65 sal_Int32 nSkip;
66 const sal_Unicode* pEndStr = pStr+nLen-5;
68 /* only sample some characters */
69 /* the first 3, some characters between, and the last 5 */
70 h = (h*39) + *(pStr++);
71 h = (h*39) + *(pStr++);
72 h = (h*39) + *(pStr++);
74 nSkip = nLen / nLen < 32 ? 4 : 8;
75 nLen -= 8;
76 while ( nLen > 0 )
78 h = (h*39) + ( *pStr );
79 pStr += nSkip;
80 nLen -= nSkip;
83 h = (h*39) + *(pEndStr++);
84 h = (h*39) + *(pEndStr++);
85 h = (h*39) + *(pEndStr++);
86 h = (h*39) + *(pEndStr++);
87 h = (h*39) + *(pEndStr++);
89 return h;
92 size_t operator() (const String & rStr) const
94 return (*this)(&rStr);
98 struct StringHashRef
100 size_t operator () (const String &rStr) const
102 StringHash aStrHash;
104 return aStrHash(&rStr);
107 #endif // _STRINGHASH_HXX