xref: /AOO41X/main/idl/inc/hash.hxx (revision 67e470dafe1997e73f56ff7ff4878983707e3e07)
1*f3ea6674SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f3ea6674SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f3ea6674SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f3ea6674SAndrew Rist  * distributed with this work for additional information
6*f3ea6674SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f3ea6674SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f3ea6674SAndrew Rist  * "License"); you may not use this file except in compliance
9*f3ea6674SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f3ea6674SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f3ea6674SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f3ea6674SAndrew Rist  * software distributed under the License is distributed on an
15*f3ea6674SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f3ea6674SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f3ea6674SAndrew Rist  * specific language governing permissions and limitations
18*f3ea6674SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f3ea6674SAndrew Rist  *************************************************************/
21*f3ea6674SAndrew Rist 
22*f3ea6674SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _HASH_HXX
25cdf0e10cSrcweir #define _HASH_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/ref.hxx>
30cdf0e10cSrcweir #include <tools/string.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir /****************** H a s h - T a b l e **********************************/
33cdf0e10cSrcweir class SvHashTable
34cdf0e10cSrcweir {
35cdf0e10cSrcweir     sal_uInt32       nMax;                 // size of hash-tabel
36cdf0e10cSrcweir     sal_uInt32       nFill;                // elements in hash-tabel
37cdf0e10cSrcweir     sal_uInt32       lAsk;                 // Anzahl der Anfragen
38cdf0e10cSrcweir     sal_uInt32       lTry;                 // Anzahl der Versuche
39cdf0e10cSrcweir protected:
40cdf0e10cSrcweir     sal_Bool        Test_Insert( const void *, sal_Bool bInsert, sal_uInt32 * pInsertPos );
41cdf0e10cSrcweir 
42cdf0e10cSrcweir                             // compare element with entry
43cdf0e10cSrcweir     virtual StringCompare   Compare( const void * , sal_uInt32 ) const = 0;
44cdf0e10cSrcweir                             // get hash value from subclass
45cdf0e10cSrcweir     virtual sal_uInt32          HashFunc( const void * ) const = 0;
46cdf0e10cSrcweir public:
47cdf0e10cSrcweir                 SvHashTable( sal_uInt32 nMaxEntries );
48cdf0e10cSrcweir                 virtual ~SvHashTable();
49cdf0e10cSrcweir 
GetMax() const50cdf0e10cSrcweir     sal_uInt32      GetMax() const { return nMax; }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     virtual sal_Bool            IsEntry( sal_uInt32 ) const = 0;
53cdf0e10cSrcweir };
54cdf0e10cSrcweir 
55cdf0e10cSrcweir /************** S t r i n g H a s h T a b l e E n t r y ******************/
56cdf0e10cSrcweir class SvStringHashTable;
57cdf0e10cSrcweir class SvStringHashEntry : public SvRefBase
58cdf0e10cSrcweir {
59cdf0e10cSrcweir friend class SvStringHashTable;
60cdf0e10cSrcweir     ByteString  aName;
61cdf0e10cSrcweir     sal_uInt32  nHashId;
62cdf0e10cSrcweir     sal_uLong   nValue;
63cdf0e10cSrcweir     sal_Bool    bHasId;
64cdf0e10cSrcweir public:
SvStringHashEntry()65cdf0e10cSrcweir                     SvStringHashEntry() : bHasId( sal_False ) {;}
SvStringHashEntry(const ByteString & rName,sal_uInt32 nIdx)66cdf0e10cSrcweir                     SvStringHashEntry( const ByteString & rName, sal_uInt32 nIdx )
67cdf0e10cSrcweir                         : aName( rName )
68cdf0e10cSrcweir                         , nHashId( nIdx )
69cdf0e10cSrcweir                         , nValue( 0 )
70cdf0e10cSrcweir                         , bHasId( sal_True ) {}
71cdf0e10cSrcweir                     ~SvStringHashEntry();
72cdf0e10cSrcweir 
GetName() const73cdf0e10cSrcweir     const ByteString &  GetName() const { return aName; }
HasId() const74cdf0e10cSrcweir     sal_Bool            HasId() const { return bHasId; }
GetId() const75cdf0e10cSrcweir     sal_uInt32          GetId() const { return nHashId; }
76cdf0e10cSrcweir 
SetValue(sal_uLong n)77cdf0e10cSrcweir     void            SetValue( sal_uLong n ) { nValue = n; }
GetValue() const78cdf0e10cSrcweir     sal_uLong           GetValue() const { return nValue; }
79cdf0e10cSrcweir 
operator ==(const SvStringHashEntry & rRef)80cdf0e10cSrcweir     sal_Bool            operator == ( const SvStringHashEntry & rRef )
81cdf0e10cSrcweir                     { return nHashId == rRef.nHashId; }
operator !=(const SvStringHashEntry & rRef)82cdf0e10cSrcweir     sal_Bool            operator != ( const SvStringHashEntry & rRef )
83cdf0e10cSrcweir                     { return ! operator == ( rRef ); }
operator =(const SvStringHashEntry & rRef)84cdf0e10cSrcweir     SvStringHashEntry & operator = ( const SvStringHashEntry & rRef )
85cdf0e10cSrcweir 		{ SvRefBase::operator=( rRef );
86cdf0e10cSrcweir 		  aName   = rRef.aName;
87cdf0e10cSrcweir 		  nHashId = rRef.nHashId;
88cdf0e10cSrcweir 	      nValue  = rRef.nValue;
89cdf0e10cSrcweir 		  bHasId  = rRef.bHasId;
90cdf0e10cSrcweir 		  return *this;
91cdf0e10cSrcweir 		}
92cdf0e10cSrcweir };
93cdf0e10cSrcweir 
94cdf0e10cSrcweir SV_DECL_IMPL_REF(SvStringHashEntry)
95cdf0e10cSrcweir 
96cdf0e10cSrcweir /****************** S t r i n g H a s h T a b l e ************************/
97cdf0e10cSrcweir DECLARE_LIST(SvStringHashList,SvStringHashEntry *)
98cdf0e10cSrcweir 
99cdf0e10cSrcweir class SvStringHashTable : public SvHashTable
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     SvStringHashEntry * pEntries;
102cdf0e10cSrcweir protected:
103cdf0e10cSrcweir     virtual sal_uInt32          HashFunc( const void * pElement ) const;
104cdf0e10cSrcweir     virtual StringCompare   Compare( const void * pElement, sal_uInt32 nIndex ) const;
105cdf0e10cSrcweir public:
106cdf0e10cSrcweir             SvStringHashTable( sal_uInt32 nMaxEntries );   // max size of hash-tabel
107cdf0e10cSrcweir             virtual ~SvStringHashTable();
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     ByteString          GetNearString( const ByteString & rName ) const;
110cdf0e10cSrcweir     virtual sal_Bool    IsEntry( sal_uInt32 nIndex ) const;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     sal_Bool    Insert( const ByteString & rStr, sal_uInt32 * pHash ); // insert string
113cdf0e10cSrcweir     sal_Bool    Test( const ByteString & rStr, sal_uInt32 * pHash ) const; // test of insert string
114cdf0e10cSrcweir     SvStringHashEntry * Get ( sal_uInt32 nIndex ) const; // return pointer to string
operator [](sal_uInt32 nPos) const115cdf0e10cSrcweir     SvStringHashEntry & operator []( sal_uInt32 nPos ) const
116cdf0e10cSrcweir             { return pEntries[ nPos ]; }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     void    FillHashList( SvStringHashList * rList ) const;
119cdf0e10cSrcweir };
120cdf0e10cSrcweir 
121cdf0e10cSrcweir #endif // _RSCHASH_HXX
122