Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef _HASH_HXX
21 : : #define _HASH_HXX
22 : :
23 : : #include <tools/ref.hxx>
24 : : #include <tools/string.hxx>
25 : : #include <vector>
26 : :
27 : : class SvHashTable
28 : : {
29 : : sal_uInt32 nMax; // size of hash-tabel
30 : : sal_uInt32 nFill; // elements in hash-tabel
31 : : sal_uInt32 lAsk; // number of requests
32 : : sal_uInt32 lTry; // number of tries
33 : : protected:
34 : : sal_Bool Test_Insert( const rtl::OString&, sal_Bool bInsert, sal_uInt32 * pInsertPos );
35 : :
36 : : // compare element with entry
37 : : virtual bool equals( const rtl::OString& , sal_uInt32 ) const = 0;
38 : : // get hash value from subclass
39 : : virtual sal_uInt32 HashFunc( const rtl::OString& ) const = 0;
40 : : public:
41 : : SvHashTable( sal_uInt32 nMaxEntries );
42 : : virtual ~SvHashTable();
43 : :
44 : 1900256 : sal_uInt32 GetMax() const { return nMax; }
45 : :
46 : : virtual sal_Bool IsEntry( sal_uInt32 ) const = 0;
47 : : };
48 : :
49 : : class SvStringHashTable;
50 : : class SvStringHashEntry : public SvRefBase
51 : : {
52 : : friend class SvStringHashTable;
53 : : rtl::OString aName;
54 : : sal_uInt32 nHashId;
55 : : sal_uLong nValue;
56 : : sal_Bool bHasId;
57 : : public:
58 : 364864 : SvStringHashEntry() : bHasId( sal_False ) {;}
59 : 41912 : SvStringHashEntry( const rtl::OString& rName, sal_uInt32 nIdx )
60 : : : aName( rName )
61 : : , nHashId( nIdx )
62 : : , nValue( 0 )
63 : 41912 : , bHasId( sal_True ) {}
64 : : ~SvStringHashEntry();
65 : :
66 : 659042 : const rtl::OString& GetName() const { return aName; }
67 : 1580192 : sal_Bool HasId() const { return bHasId; }
68 : : sal_uInt32 GetId() const { return nHashId; }
69 : :
70 : 41466 : void SetValue( sal_uLong n ) { nValue = n; }
71 : 124004 : sal_uLong GetValue() const { return nValue; }
72 : :
73 : : sal_Bool operator == ( const SvStringHashEntry & rRef )
74 : : { return nHashId == rRef.nHashId; }
75 : : sal_Bool operator != ( const SvStringHashEntry & rRef )
76 : : { return ! operator == ( rRef ); }
77 : 41912 : SvStringHashEntry & operator = ( const SvStringHashEntry & rRef )
78 : 41912 : { SvRefBase::operator=( rRef );
79 : 41912 : aName = rRef.aName;
80 : 41912 : nHashId = rRef.nHashId;
81 : 41912 : nValue = rRef.nValue;
82 : 41912 : bHasId = rRef.bHasId;
83 : 41912 : return *this;
84 : : }
85 : : };
86 : :
87 [ + + ][ + - ]: 14526514 : SV_DECL_IMPL_REF(SvStringHashEntry)
88 : :
89 : : typedef ::std::vector< SvStringHashEntry* > SvStringHashList;
90 : :
91 : : class SvStringHashTable : public SvHashTable
92 : : {
93 : : SvStringHashEntry* pEntries;
94 : : protected:
95 : : virtual sal_uInt32 HashFunc( const rtl::OString& rElement ) const;
96 : : virtual bool equals( const rtl::OString &rElement, sal_uInt32 nIndex ) const;
97 : : public:
98 : : SvStringHashTable( sal_uInt32 nMaxEntries ); // max size of hash-tabel
99 : : virtual ~SvStringHashTable();
100 : :
101 : : rtl::OString GetNearString( const rtl::OString& rName ) const;
102 : : virtual sal_Bool IsEntry( sal_uInt32 nIndex ) const;
103 : :
104 : : sal_Bool Insert( const rtl::OString& rStr, sal_uInt32 * pHash ); // insert string
105 : : sal_Bool Test( const rtl::OString& rStr, sal_uInt32 * pHash ) const; // test of insert string
106 : : SvStringHashEntry * Get ( sal_uInt32 nIndex ) const; // return pointer to string
107 : : SvStringHashEntry & operator []( sal_uInt32 nPos ) const
108 : : { return pEntries[ nPos ]; }
109 : :
110 : : void FillHashList( SvStringHashList * rList ) const;
111 : : };
112 : :
113 : : #endif // _RSCHASH_HXX
114 : :
115 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|