2010-10-27 13:11:31 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-11 19:49:09 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2014-04-18 22:32:17 +02:00
|
|
|
#ifndef INCLUDED_IDL_INC_HASH_HXX
|
|
|
|
#define INCLUDED_IDL_INC_HASH_HXX
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2013-10-20 15:15:42 +01:00
|
|
|
#include <rtl/ustring.hxx>
|
2000-09-18 15:33:13 +00:00
|
|
|
#include <tools/ref.hxx>
|
2013-10-20 15:15:42 +01:00
|
|
|
#include <tools/solar.h>
|
2010-12-28 21:50:36 -08:00
|
|
|
#include <vector>
|
2000-09-18 15:33:13 +00:00
|
|
|
|
|
|
|
class SvHashTable
|
|
|
|
{
|
2010-11-03 15:49:08 +01:00
|
|
|
sal_uInt32 nMax; // size of hash-tabel
|
|
|
|
sal_uInt32 nFill; // elements in hash-tabel
|
2011-03-12 02:42:58 +01:00
|
|
|
sal_uInt32 lAsk; // number of requests
|
|
|
|
sal_uInt32 lTry; // number of tries
|
2000-09-18 15:33:13 +00:00
|
|
|
protected:
|
2014-05-08 11:42:16 +02:00
|
|
|
bool Test_Insert( const OString&, bool bInsert, sal_uInt32 * pInsertPos );
|
2000-09-18 15:33:13 +00:00
|
|
|
|
|
|
|
// compare element with entry
|
2014-05-08 11:42:16 +02:00
|
|
|
virtual bool equals( const OString& , sal_uInt32 ) const = 0;
|
2000-09-18 15:33:13 +00:00
|
|
|
// get hash value from subclass
|
2014-05-08 11:42:16 +02:00
|
|
|
virtual sal_uInt32 HashFunc( const OString& ) const = 0;
|
2000-09-18 15:33:13 +00:00
|
|
|
public:
|
2010-11-03 15:49:08 +01:00
|
|
|
SvHashTable( sal_uInt32 nMaxEntries );
|
2006-06-19 09:40:18 +00:00
|
|
|
virtual ~SvHashTable();
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2014-05-08 11:42:16 +02:00
|
|
|
sal_uInt32 GetMax() const { return nMax; }
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2014-05-08 11:42:16 +02:00
|
|
|
virtual bool IsEntry( sal_uInt32 ) const = 0;
|
2000-09-18 15:33:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SvStringHashTable;
|
|
|
|
class SvStringHashEntry : public SvRefBase
|
|
|
|
{
|
2003-12-01 14:50:41 +00:00
|
|
|
friend class SvStringHashTable;
|
2014-05-08 11:42:16 +02:00
|
|
|
OString aName;
|
2010-11-03 15:49:08 +01:00
|
|
|
sal_uInt32 nHashId;
|
2011-01-13 09:32:03 +01:00
|
|
|
sal_uLong nValue;
|
2014-05-08 11:42:16 +02:00
|
|
|
bool bHasId;
|
2000-09-18 15:33:13 +00:00
|
|
|
public:
|
2014-02-11 12:37:16 +00:00
|
|
|
SvStringHashEntry()
|
|
|
|
: nHashId(0)
|
|
|
|
, nValue(0)
|
|
|
|
, bHasId(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
SvStringHashEntry( const OString& rName, sal_uInt32 nIdx )
|
|
|
|
: aName(rName)
|
|
|
|
, nHashId(nIdx)
|
|
|
|
, nValue(0)
|
|
|
|
, bHasId(true)
|
|
|
|
{
|
|
|
|
}
|
2014-04-01 19:18:35 +02:00
|
|
|
virtual ~SvStringHashEntry();
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2014-02-11 12:37:16 +00:00
|
|
|
const OString& GetName() const { return aName; }
|
2014-05-08 11:42:16 +02:00
|
|
|
bool HasId() const { return bHasId; }
|
2014-02-11 12:37:16 +00:00
|
|
|
sal_uInt32 GetId() const { return nHashId; }
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2011-01-13 09:32:03 +01:00
|
|
|
void SetValue( sal_uLong n ) { nValue = n; }
|
2014-05-08 11:42:16 +02:00
|
|
|
sal_uLong GetValue() const { return nValue; }
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2014-05-08 11:42:16 +02:00
|
|
|
bool operator == ( const SvStringHashEntry & rRef )
|
2000-09-18 15:33:13 +00:00
|
|
|
{ return nHashId == rRef.nHashId; }
|
2014-05-08 11:42:16 +02:00
|
|
|
bool operator != ( const SvStringHashEntry & rRef )
|
2000-09-18 15:33:13 +00:00
|
|
|
{ return ! operator == ( rRef ); }
|
|
|
|
SvStringHashEntry & operator = ( const SvStringHashEntry & rRef )
|
|
|
|
{ SvRefBase::operator=( rRef );
|
|
|
|
aName = rRef.aName;
|
|
|
|
nHashId = rRef.nHashId;
|
|
|
|
nValue = rRef.nValue;
|
|
|
|
bHasId = rRef.bHasId;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-07 12:31:09 +02:00
|
|
|
typedef tools::SvRef<SvStringHashEntry> SvStringHashEntryRef;
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2010-12-28 21:50:36 -08:00
|
|
|
typedef ::std::vector< SvStringHashEntry* > SvStringHashList;
|
2000-09-18 15:33:13 +00:00
|
|
|
|
|
|
|
class SvStringHashTable : public SvHashTable
|
|
|
|
{
|
2010-12-28 21:50:36 -08:00
|
|
|
SvStringHashEntry* pEntries;
|
2000-09-18 15:33:13 +00:00
|
|
|
protected:
|
2014-03-26 16:37:00 +01:00
|
|
|
virtual sal_uInt32 HashFunc( const OString& rElement ) const SAL_OVERRIDE;
|
|
|
|
virtual bool equals( const OString &rElement, sal_uInt32 nIndex ) const SAL_OVERRIDE;
|
2000-09-18 15:33:13 +00:00
|
|
|
public:
|
2010-11-03 15:49:08 +01:00
|
|
|
SvStringHashTable( sal_uInt32 nMaxEntries ); // max size of hash-tabel
|
2006-06-19 09:40:18 +00:00
|
|
|
virtual ~SvStringHashTable();
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString GetNearString( const OString& rName ) const;
|
2014-05-08 11:42:16 +02:00
|
|
|
virtual bool IsEntry( sal_uInt32 nIndex ) const SAL_OVERRIDE;
|
2000-09-18 15:33:13 +00:00
|
|
|
|
2014-05-08 11:42:16 +02:00
|
|
|
bool Insert( const OString& rStr, sal_uInt32 * pHash ); // insert string
|
|
|
|
bool Test( const OString& rStr, sal_uInt32 * pHash ) const; // test of insert string
|
2010-11-03 15:49:08 +01:00
|
|
|
SvStringHashEntry * Get ( sal_uInt32 nIndex ) const; // return pointer to string
|
|
|
|
SvStringHashEntry & operator []( sal_uInt32 nPos ) const
|
2000-09-18 15:33:13 +00:00
|
|
|
{ return pEntries[ nPos ]; }
|
|
|
|
|
|
|
|
void FillHashList( SvStringHashList * rList ) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _RSCHASH_HXX
|
2010-10-27 13:11:31 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|