LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/idl/inc - hash.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 16 100.0 %
Date: 2013-07-09 Functions: 12 12 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 _HASH_HXX
      21             : #define _HASH_HXX
      22             : 
      23             : #include <tools/ref.hxx>
      24             : #include <tools/string.hxx>
      25             : #include <vector>
      26             : 
      27             : class SvHashTable
      28             : {
      29             :     sal_uInt32       nMax;                 // size of hash-tabel
      30             :     sal_uInt32       nFill;                // elements in hash-tabel
      31             :     sal_uInt32       lAsk;                 // number of requests
      32             :     sal_uInt32       lTry;                 // number of tries
      33             : protected:
      34             :     sal_Bool        Test_Insert( const OString&, sal_Bool bInsert, sal_uInt32 * pInsertPos );
      35             : 
      36             :                             // compare element with entry
      37             :     virtual bool equals( const OString& , sal_uInt32 ) const = 0;
      38             :                             // get hash value from subclass
      39             :     virtual sal_uInt32          HashFunc( const OString& ) const = 0;
      40             : public:
      41             :                 SvHashTable( sal_uInt32 nMaxEntries );
      42             :                 virtual ~SvHashTable();
      43             : 
      44      967897 :     sal_uInt32      GetMax() const { return nMax; }
      45             : 
      46             :     virtual sal_Bool            IsEntry( sal_uInt32 ) const = 0;
      47             : };
      48             : 
      49             : class SvStringHashTable;
      50             : class SvStringHashEntry : public SvRefBase
      51             : {
      52             : friend class SvStringHashTable;
      53             :     OString aName;
      54             :     sal_uInt32  nHashId;
      55             :     sal_uLong   nValue;
      56             :     sal_Bool    bHasId;
      57             : public:
      58      182432 :                     SvStringHashEntry() : bHasId( sal_False ) {;}
      59       21339 :                     SvStringHashEntry( const OString& rName, sal_uInt32 nIdx )
      60             :                         : aName( rName )
      61             :                         , nHashId( nIdx )
      62             :                         , nValue( 0 )
      63       21339 :                         , bHasId( sal_True ) {}
      64             :                     ~SvStringHashEntry();
      65             : 
      66      340005 :     const OString& GetName() const { return aName; }
      67      807865 :     sal_Bool            HasId() const { return bHasId; }
      68             :     sal_uInt32          GetId() const { return nHashId; }
      69             : 
      70       21116 :     void            SetValue( sal_uLong n ) { nValue = n; }
      71       63541 :     sal_uLong           GetValue() const { return nValue; }
      72             : 
      73             :     sal_Bool            operator == ( const SvStringHashEntry & rRef )
      74             :                     { return nHashId == rRef.nHashId; }
      75             :     sal_Bool            operator != ( const SvStringHashEntry & rRef )
      76             :                     { return ! operator == ( rRef ); }
      77       21339 :     SvStringHashEntry & operator = ( const SvStringHashEntry & rRef )
      78       21339 :         { SvRefBase::operator=( rRef );
      79       21339 :           aName   = rRef.aName;
      80       21339 :           nHashId = rRef.nHashId;
      81       21339 :           nValue  = rRef.nValue;
      82       21339 :           bHasId  = rRef.bHasId;
      83       21339 :           return *this;
      84             :         }
      85             : };
      86             : 
      87     7504595 : SV_DECL_IMPL_REF(SvStringHashEntry)
      88             : 
      89             : typedef ::std::vector< SvStringHashEntry* > SvStringHashList;
      90             : 
      91             : class SvStringHashTable : public SvHashTable
      92             : {
      93             :     SvStringHashEntry*      pEntries;
      94             : protected:
      95             :     virtual sal_uInt32          HashFunc( const OString& rElement ) const;
      96             :     virtual bool equals( const OString &rElement, sal_uInt32 nIndex ) const;
      97             : public:
      98             :             SvStringHashTable( sal_uInt32 nMaxEntries );   // max size of hash-tabel
      99             :             virtual ~SvStringHashTable();
     100             : 
     101             :     OString GetNearString( const OString& rName ) const;
     102             :     virtual sal_Bool    IsEntry( sal_uInt32 nIndex ) const;
     103             : 
     104             :     sal_Bool    Insert( const OString& rStr, sal_uInt32 * pHash ); // insert string
     105             :     sal_Bool    Test( const OString& rStr, sal_uInt32 * pHash ) const; // test of insert string
     106             :     SvStringHashEntry * Get ( sal_uInt32 nIndex ) const; // return pointer to string
     107             :     SvStringHashEntry & operator []( sal_uInt32 nPos ) const
     108             :             { return pEntries[ nPos ]; }
     109             : 
     110             :     void    FillHashList( SvStringHashList * rList ) const;
     111             : };
     112             : 
     113             : #endif // _RSCHASH_HXX
     114             : 
     115             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10