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 .
20 #ifndef INCLUDED_IDL_INC_HASH_HXX
21 #define INCLUDED_IDL_INC_HASH_HXX
23 #include <rtl/ustring.hxx>
24 #include <tools/ref.hxx>
25 #include <tools/solar.h>
30 sal_uInt32 nMax
; // size of hash-tabel
31 sal_uInt32 nFill
; // elements in hash-tabel
32 sal_uInt32 lAsk
; // number of requests
33 sal_uInt32 lTry
; // number of tries
35 bool Test_Insert( const OString
&, bool bInsert
, sal_uInt32
* pInsertPos
);
37 // compare element with entry
38 virtual bool equals( const OString
& , sal_uInt32
) const = 0;
39 // get hash value from subclass
40 virtual sal_uInt32
HashFunc( const OString
& ) const = 0;
42 SvHashTable( sal_uInt32 nMaxEntries
);
43 virtual ~SvHashTable();
45 sal_uInt32
GetMax() const { return nMax
; }
47 virtual bool IsEntry( sal_uInt32
) const = 0;
50 class SvStringHashTable
;
51 class SvStringHashEntry
: public SvRefBase
53 friend class SvStringHashTable
;
65 SvStringHashEntry( const OString
& rName
, sal_uInt32 nIdx
)
72 virtual ~SvStringHashEntry();
74 const OString
& GetName() const { return aName
; }
75 bool HasId() const { return bHasId
; }
76 sal_uInt32
GetId() const { return nHashId
; }
78 void SetValue( sal_uLong n
) { nValue
= n
; }
79 sal_uLong
GetValue() const { return nValue
; }
81 bool operator == ( const SvStringHashEntry
& rRef
)
82 { return nHashId
== rRef
.nHashId
; }
83 bool operator != ( const SvStringHashEntry
& rRef
)
84 { return ! operator == ( rRef
); }
85 SvStringHashEntry
& operator = ( const SvStringHashEntry
& rRef
)
86 { SvRefBase::operator=( rRef
);
88 nHashId
= rRef
.nHashId
;
95 typedef tools::SvRef
<SvStringHashEntry
> SvStringHashEntryRef
;
98 class SvStringHashTable
: public SvHashTable
100 SvStringHashEntry
* pEntries
;
102 virtual sal_uInt32
HashFunc( const OString
& rElement
) const SAL_OVERRIDE
;
103 virtual bool equals( const OString
&rElement
, sal_uInt32 nIndex
) const SAL_OVERRIDE
;
105 SvStringHashTable( sal_uInt32 nMaxEntries
); // max size of hash-tabel
106 virtual ~SvStringHashTable();
108 OString
GetNearString( const OString
& rName
) const;
109 virtual bool IsEntry( sal_uInt32 nIndex
) const SAL_OVERRIDE
;
111 bool Insert( const OString
& rStr
, sal_uInt32
* pHash
); // insert string
112 bool Test( const OString
& rStr
, sal_uInt32
* pHash
) const; // test of insert string
113 SvStringHashEntry
* Get ( sal_uInt32 nIndex
) const; // return pointer to string
114 SvStringHashEntry
& operator []( sal_uInt32 nPos
) const
115 { return pEntries
[ nPos
]; }
118 #endif // INCLUDED_IDL_INC_HASH_HXX
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */