LCOV - code coverage report
Current view: top level - idl/inc - hash.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 18 18 100.0 %
Date: 2014-11-03 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_IDL_INC_HASH_HXX
      21             : #define INCLUDED_IDL_INC_HASH_HXX
      22             : 
      23             : #include <rtl/ustring.hxx>
      24             : #include <tools/ref.hxx>
      25             : #include <tools/solar.h>
      26             : #include <vector>
      27             : 
      28             : class SvHashTable
      29             : {
      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
      34             : protected:
      35             :     bool                Test_Insert( const OString&, bool bInsert, sal_uInt32 * pInsertPos );
      36             : 
      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;
      41             : public:
      42             :                 SvHashTable( sal_uInt32 nMaxEntries );
      43             :                 virtual ~SvHashTable();
      44             : 
      45      612608 :     sal_uInt32         GetMax() const { return nMax; }
      46             : 
      47             :     virtual bool       IsEntry( sal_uInt32 ) const = 0;
      48             : };
      49             : 
      50             : class SvStringHashTable;
      51             : class SvStringHashEntry : public SvRefBase
      52             : {
      53             : friend class SvStringHashTable;
      54             :     OString     aName;
      55             :     sal_uInt32  nHashId;
      56             :     sal_uLong   nValue;
      57             :     bool        bHasId;
      58             : public:
      59      182432 :     SvStringHashEntry()
      60             :         : nHashId(0)
      61             :         , nValue(0)
      62      182432 :         , bHasId(false)
      63             :     {
      64      182432 :     }
      65       20520 :     SvStringHashEntry( const OString& rName, sal_uInt32 nIdx )
      66             :         : aName(rName)
      67             :         , nHashId(nIdx)
      68             :         , nValue(0)
      69       20520 :         , bHasId(true)
      70             :     {
      71       20520 :     }
      72             :     virtual ~SvStringHashEntry();
      73             : 
      74      270117 :     const OString&  GetName() const { return aName; }
      75      612608 :     bool            HasId() const { return bHasId; }
      76             :     sal_uInt32      GetId() const { return nHashId; }
      77             : 
      78       20288 :     void            SetValue( sal_uLong n ) { nValue = n; }
      79       41940 :     sal_uLong       GetValue() const { return nValue; }
      80             : 
      81             :     bool            operator == ( const SvStringHashEntry & rRef )
      82             :                     { return nHashId == rRef.nHashId; }
      83             :     bool            operator != ( const SvStringHashEntry & rRef )
      84             :                     { return ! operator == ( rRef ); }
      85       20520 :     SvStringHashEntry & operator = ( const SvStringHashEntry & rRef )
      86       20520 :         { SvRefBase::operator=( rRef );
      87       20520 :           aName   = rRef.aName;
      88       20520 :           nHashId = rRef.nHashId;
      89       20520 :           nValue  = rRef.nValue;
      90       20520 :           bHasId  = rRef.bHasId;
      91       20520 :           return *this;
      92             :         }
      93             : };
      94             : 
      95             : typedef tools::SvRef<SvStringHashEntry> SvStringHashEntryRef;
      96             : 
      97             : typedef ::std::vector< SvStringHashEntry* > SvStringHashList;
      98             : 
      99             : class SvStringHashTable : public SvHashTable
     100             : {
     101             :     SvStringHashEntry*      pEntries;
     102             : protected:
     103             :     virtual sal_uInt32          HashFunc( const OString& rElement ) const SAL_OVERRIDE;
     104             :     virtual bool equals( const OString &rElement, sal_uInt32 nIndex ) const SAL_OVERRIDE;
     105             : public:
     106             :             SvStringHashTable( sal_uInt32 nMaxEntries );   // max size of hash-tabel
     107             :             virtual ~SvStringHashTable();
     108             : 
     109             :     OString GetNearString( const OString& rName ) const;
     110             :     virtual bool    IsEntry( sal_uInt32 nIndex ) const SAL_OVERRIDE;
     111             : 
     112             :     bool    Insert( const OString& rStr, sal_uInt32 * pHash ); // insert string
     113             :     bool    Test( const OString& rStr, sal_uInt32 * pHash ) const; // test of insert string
     114             :     SvStringHashEntry * Get ( sal_uInt32 nIndex ) const; // return pointer to string
     115             :     SvStringHashEntry & operator []( sal_uInt32 nPos ) const
     116             :             { return pEntries[ nPos ]; }
     117             : };
     118             : 
     119             : #endif // INCLUDED_IDL_INC_HASH_HXX
     120             : 
     121             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10