merge the formfield patch from ooo-build
[ooovba.git] / idl / inc / hash.hxx
blob400afd54b801e63cadfb8024df7ec4ceb664e197
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hash.hxx,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 #ifndef _HASH_HXX
32 #define _HASH_HXX
36 #include <tools/ref.hxx>
37 #include <tools/string.hxx>
39 /****************** H a s h - T a b l e **********************************/
40 class SvHashTable
42 UINT32 nMax; // size of hash-tabel
43 UINT32 nFill; // elements in hash-tabel
44 UINT32 lAsk; // Anzahl der Anfragen
45 UINT32 lTry; // Anzahl der Versuche
46 protected:
47 BOOL Test_Insert( const void *, BOOL bInsert, UINT32 * pInsertPos );
49 // compare element with entry
50 virtual StringCompare Compare( const void * , UINT32 ) const = 0;
51 // get hash value from subclass
52 virtual UINT32 HashFunc( const void * ) const = 0;
53 public:
54 SvHashTable( UINT32 nMaxEntries );
55 virtual ~SvHashTable();
57 UINT32 GetMax() const { return nMax; }
59 virtual BOOL IsEntry( UINT32 ) const = 0;
62 /************** S t r i n g H a s h T a b l e E n t r y ******************/
63 class SvStringHashTable;
64 class SvStringHashEntry : public SvRefBase
66 friend class SvStringHashTable;
67 ByteString aName;
68 UINT32 nHashId;
69 ULONG nValue;
70 BOOL bHasId;
71 public:
72 SvStringHashEntry() : bHasId( FALSE ) {;}
73 SvStringHashEntry( const ByteString & rName, UINT32 nIdx )
74 : aName( rName )
75 , nHashId( nIdx )
76 , nValue( 0 )
77 , bHasId( TRUE ) {}
78 ~SvStringHashEntry();
80 const ByteString & GetName() const { return aName; }
81 BOOL HasId() const { return bHasId; }
82 UINT32 GetId() const { return nHashId; }
84 void SetValue( ULONG n ) { nValue = n; }
85 ULONG GetValue() const { return nValue; }
87 BOOL operator == ( const SvStringHashEntry & rRef )
88 { return nHashId == rRef.nHashId; }
89 BOOL operator != ( const SvStringHashEntry & rRef )
90 { return ! operator == ( rRef ); }
91 SvStringHashEntry & operator = ( const SvStringHashEntry & rRef )
92 { SvRefBase::operator=( rRef );
93 aName = rRef.aName;
94 nHashId = rRef.nHashId;
95 nValue = rRef.nValue;
96 bHasId = rRef.bHasId;
97 return *this;
101 SV_DECL_IMPL_REF(SvStringHashEntry)
103 /****************** S t r i n g H a s h T a b l e ************************/
104 DECLARE_LIST(SvStringHashList,SvStringHashEntry *)
106 class SvStringHashTable : public SvHashTable
108 SvStringHashEntry * pEntries;
109 protected:
110 virtual UINT32 HashFunc( const void * pElement ) const;
111 virtual StringCompare Compare( const void * pElement, UINT32 nIndex ) const;
112 public:
113 SvStringHashTable( UINT32 nMaxEntries ); // max size of hash-tabel
114 virtual ~SvStringHashTable();
116 ByteString GetNearString( const ByteString & rName ) const;
117 virtual BOOL IsEntry( UINT32 nIndex ) const;
119 BOOL Insert( const ByteString & rStr, UINT32 * pHash ); // insert string
120 BOOL Test( const ByteString & rStr, UINT32 * pHash ) const; // test of insert string
121 SvStringHashEntry * Get ( UINT32 nIndex ) const; // return pointer to string
122 SvStringHashEntry & operator []( UINT32 nPos ) const
123 { return pEntries[ nPos ]; }
125 void FillHashList( SvStringHashList * rList ) const;
128 #endif // _RSCHASH_HXX