1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: stringhash.hxx,v $
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>
37 sal_Bool
operator() ( const String
*r1
,
38 const String
*r2
) const
40 return r1
->Equals(*r2
);
46 sal_Bool
operator() (const String
&r1
, const String
&r2
) const
54 size_t operator() ( const String
*rString
) const
57 h
= nLen
= rString
->Len();
58 const sal_Unicode
*pStr
= rString
->GetBuffer();
62 h
= (h
*37) + *(pStr
++);
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;
78 h
= (h
*39) + ( *pStr
);
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
++);
92 size_t operator() (const String
& rStr
) const
94 return (*this)(&rStr
);
100 size_t operator () (const String
&rStr
) const
104 return aStrHash(&rStr
);
107 #endif // _STRINGHASH_HXX