1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include <tools/ref.hxx>
24 #include <tools/string.hxx>
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
34 sal_Bool
Test_Insert( const OString
&, sal_Bool bInsert
, sal_uInt32
* pInsertPos
);
36 // compare element with entry
37 virtual bool equals( const OString
& , sal_uInt32
) const = 0;
38 // get hash value from subclass
39 virtual sal_uInt32
HashFunc( const OString
& ) const = 0;
41 SvHashTable( sal_uInt32 nMaxEntries
);
42 virtual ~SvHashTable();
44 sal_uInt32
GetMax() const { return nMax
; }
46 virtual sal_Bool
IsEntry( sal_uInt32
) const = 0;
49 class SvStringHashTable
;
50 class SvStringHashEntry
: public SvRefBase
52 friend class SvStringHashTable
;
58 SvStringHashEntry() : bHasId( sal_False
) {;}
59 SvStringHashEntry( const OString
& rName
, sal_uInt32 nIdx
)
63 , bHasId( sal_True
) {}
66 const OString
& GetName() const { return aName
; }
67 sal_Bool
HasId() const { return bHasId
; }
68 sal_uInt32
GetId() const { return nHashId
; }
70 void SetValue( sal_uLong n
) { nValue
= n
; }
71 sal_uLong
GetValue() const { return nValue
; }
73 sal_Bool
operator == ( const SvStringHashEntry
& rRef
)
74 { return nHashId
== rRef
.nHashId
; }
75 sal_Bool
operator != ( const SvStringHashEntry
& rRef
)
76 { return ! operator == ( rRef
); }
77 SvStringHashEntry
& operator = ( const SvStringHashEntry
& rRef
)
78 { SvRefBase::operator=( rRef
);
80 nHashId
= rRef
.nHashId
;
87 SV_DECL_IMPL_REF(SvStringHashEntry
)
89 typedef ::std::vector
< SvStringHashEntry
* > SvStringHashList
;
91 class SvStringHashTable
: public SvHashTable
93 SvStringHashEntry
* pEntries
;
95 virtual sal_uInt32
HashFunc( const OString
& rElement
) const;
96 virtual bool equals( const OString
&rElement
, sal_uInt32 nIndex
) const;
98 SvStringHashTable( sal_uInt32 nMaxEntries
); // max size of hash-tabel
99 virtual ~SvStringHashTable();
101 OString
GetNearString( const OString
& rName
) const;
102 virtual sal_Bool
IsEntry( sal_uInt32 nIndex
) const;
104 sal_Bool
Insert( const OString
& rStr
, sal_uInt32
* pHash
); // insert string
105 sal_Bool
Test( const 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
]; }
110 void FillHashList( SvStringHashList
* rList
) const;
113 #endif // _RSCHASH_HXX
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */