LCOV - code coverage report
Current view: top level - idl/inc - hash.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 18 18 100.0 %
Date: 2015-06-13 12:38:46 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      614912 :     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       20547 :     SvStringHashEntry( const OString& rName, sal_uInt32 nIdx )
      66             :         : aName(rName)
      67             :         , nHashId(nIdx)
      68             :         , nValue(0)
      69       20547 :         , bHasId(true)
      70             :     {
      71       20547 :     }
      72             :     virtual ~SvStringHashEntry();
      73             : 
      74      271371 :     const OString&  GetName() const { return aName; }
      75      614912 :     bool            HasId() const { return bHasId; }
      76             :     sal_uInt32      GetId() const { return nHashId; }
      77             : 
      78       20239 :     void            SetValue( sal_uLong n ) { nValue = n; }
      79       42146 :     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       20547 :     SvStringHashEntry & operator = ( const SvStringHashEntry & rRef )
      86       20547 :         { SvRefBase::operator=( rRef );
      87       20547 :           aName   = rRef.aName;
      88       20547 :           nHashId = rRef.nHashId;
      89       20547 :           nValue  = rRef.nValue;
      90       20547 :           bHasId  = rRef.bHasId;
      91       20547 :           return *this;
      92             :         }
      93             : };
      94             : 
      95             : typedef tools::SvRef<SvStringHashEntry> SvStringHashEntryRef;
      96             : 
      97             : 
      98             : class SvStringHashTable : public SvHashTable
      99             : {
     100             :     SvStringHashEntry*      pEntries;
     101             : protected:
     102             :     virtual sal_uInt32          HashFunc( const OString& rElement ) const SAL_OVERRIDE;
     103             :     virtual bool equals( const OString &rElement, sal_uInt32 nIndex ) const SAL_OVERRIDE;
     104             : public:
     105             :             SvStringHashTable( sal_uInt32 nMaxEntries );   // max size of hash-tabel
     106             :             virtual ~SvStringHashTable();
     107             : 
     108             :     OString GetNearString( const OString& rName ) const;
     109             :     virtual bool    IsEntry( sal_uInt32 nIndex ) const SAL_OVERRIDE;
     110             : 
     111             :     bool    Insert( const OString& rStr, sal_uInt32 * pHash ); // insert string
     112             :     bool    Test( const OString& rStr, sal_uInt32 * pHash ) const; // test of insert string
     113             :     SvStringHashEntry * Get ( sal_uInt32 nIndex ) const; // return pointer to string
     114             :     SvStringHashEntry & operator []( sal_uInt32 nPos ) const
     115             :             { return pEntries[ nPos ]; }
     116             : };
     117             : 
     118             : #endif // INCLUDED_IDL_INC_HASH_HXX
     119             : 
     120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11