Bump for 3.6-28
[LibreOffice.git] / idl / inc / hash.hxx
blob733f0ebbdb934cef8e11a7a4dcbfa27d9aa4f867
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _HASH_HXX
30 #define _HASH_HXX
32 #include <tools/ref.hxx>
33 #include <tools/string.hxx>
34 #include <vector>
36 class SvHashTable
38 sal_uInt32 nMax; // size of hash-tabel
39 sal_uInt32 nFill; // elements in hash-tabel
40 sal_uInt32 lAsk; // number of requests
41 sal_uInt32 lTry; // number of tries
42 protected:
43 sal_Bool Test_Insert( const rtl::OString&, sal_Bool bInsert, sal_uInt32 * pInsertPos );
45 // compare element with entry
46 virtual bool equals( const rtl::OString& , sal_uInt32 ) const = 0;
47 // get hash value from subclass
48 virtual sal_uInt32 HashFunc( const rtl::OString& ) const = 0;
49 public:
50 SvHashTable( sal_uInt32 nMaxEntries );
51 virtual ~SvHashTable();
53 sal_uInt32 GetMax() const { return nMax; }
55 virtual sal_Bool IsEntry( sal_uInt32 ) const = 0;
58 class SvStringHashTable;
59 class SvStringHashEntry : public SvRefBase
61 friend class SvStringHashTable;
62 rtl::OString aName;
63 sal_uInt32 nHashId;
64 sal_uLong nValue;
65 sal_Bool bHasId;
66 public:
67 SvStringHashEntry() : bHasId( sal_False ) {;}
68 SvStringHashEntry( const rtl::OString& rName, sal_uInt32 nIdx )
69 : aName( rName )
70 , nHashId( nIdx )
71 , nValue( 0 )
72 , bHasId( sal_True ) {}
73 ~SvStringHashEntry();
75 const rtl::OString& GetName() const { return aName; }
76 sal_Bool HasId() const { return bHasId; }
77 sal_uInt32 GetId() const { return nHashId; }
79 void SetValue( sal_uLong n ) { nValue = n; }
80 sal_uLong GetValue() const { return nValue; }
82 sal_Bool operator == ( const SvStringHashEntry & rRef )
83 { return nHashId == rRef.nHashId; }
84 sal_Bool operator != ( const SvStringHashEntry & rRef )
85 { return ! operator == ( rRef ); }
86 SvStringHashEntry & operator = ( const SvStringHashEntry & rRef )
87 { SvRefBase::operator=( rRef );
88 aName = rRef.aName;
89 nHashId = rRef.nHashId;
90 nValue = rRef.nValue;
91 bHasId = rRef.bHasId;
92 return *this;
96 SV_DECL_IMPL_REF(SvStringHashEntry)
98 typedef ::std::vector< SvStringHashEntry* > SvStringHashList;
100 class SvStringHashTable : public SvHashTable
102 SvStringHashEntry* pEntries;
103 protected:
104 virtual sal_uInt32 HashFunc( const rtl::OString& rElement ) const;
105 virtual bool equals( const rtl::OString &rElement, sal_uInt32 nIndex ) const;
106 public:
107 SvStringHashTable( sal_uInt32 nMaxEntries ); // max size of hash-tabel
108 virtual ~SvStringHashTable();
110 rtl::OString GetNearString( const rtl::OString& rName ) const;
111 virtual sal_Bool IsEntry( sal_uInt32 nIndex ) const;
113 sal_Bool Insert( const rtl::OString& rStr, sal_uInt32 * pHash ); // insert string
114 sal_Bool Test( const rtl::OString& rStr, sal_uInt32 * pHash ) const; // test of insert string
115 SvStringHashEntry * Get ( sal_uInt32 nIndex ) const; // return pointer to string
116 SvStringHashEntry & operator []( sal_uInt32 nPos ) const
117 { return pEntries[ nPos ]; }
119 void FillHashList( SvStringHashList * rList ) const;
122 #endif // _RSCHASH_HXX
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */