LCOV - code coverage report
Current view: top level - editeng/source/lookuptree - LatinTreeNode.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 41 100.0 %
Date: 2012-08-25 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 32 40 80.0 %

           Branch data     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                 :            : #include <editeng/LatinTreeNode.hxx>
      21                 :            : #include <editeng/LatinLookupTree.hxx>
      22                 :            : 
      23                 :      33234 : LatinTreeNode::LatinTreeNode(TreeHead* pHead, Node* pParent, const sal_Unicode cKey, const int nProbability) :
      24                 :      33234 :     Node( pHead, pParent, cKey, nProbability )
      25                 :            : {
      26         [ +  + ]:     897318 :     for ( sal_Unicode i = 0; i < 26; ++i )
      27                 :            :     {
      28                 :     864084 :         m_pLeaves[i] = NULL;
      29                 :            :     }
      30                 :      33234 : }
      31                 :            : 
      32                 :      33234 : LatinTreeNode::~LatinTreeNode()
      33                 :            : {
      34         [ +  - ]:      33234 :     freeMemory();
      35         [ -  + ]:      66468 : }
      36                 :            : 
      37                 :        300 : bool LatinTreeNode::isSeparatedlyHandled(const sal_Unicode cKey) const
      38                 :            : {
      39 [ +  + ][ +  - ]:        300 :     return ( cKey >= sal_Unicode('a') && cKey <= sal_Unicode('z') );
      40                 :            : }
      41                 :            : 
      42                 :      81899 : Node*& LatinTreeNode::getChildRef(const sal_Unicode cKey, bool bCreatePlaceholder)
      43                 :            : {
      44                 :            :     // determine position in array if possible
      45 [ +  + ][ +  + ]:      81899 :     if ( cKey >= sal_Unicode('a') && cKey <= sal_Unicode('z') )
      46                 :            :     {
      47                 :       7769 :         return m_pLeaves[cKey - LatinLookupTree::our_nLowerCaseA];
      48                 :            :     }
      49                 :            :     else
      50                 :            :     {
      51         [ +  + ]:      89028 :         for ( std::list<Node*>::iterator i = m_lChildren.begin(); i != m_lChildren.end(); ++i )
      52                 :            :         {
      53         [ +  + ]:      58092 :             if ( (*i)->m_cKey == cKey )
      54                 :            :             {
      55                 :      43194 :                 return *i;
      56                 :            :             }
      57                 :            :         }
      58         [ +  - ]:      30936 :         if ( bCreatePlaceholder )
      59                 :            :         {
      60                 :            :             // Create new entry in case there isn't one.
      61         [ +  - ]:      30936 :             m_lChildren.push_back( NULL );
      62                 :      30936 :             return *(--m_lChildren.end());
      63                 :            :         }
      64                 :            :         else
      65                 :            :         {
      66                 :      81899 :             return our_pNodeNullPointer;
      67                 :            :         }
      68                 :            :     }
      69                 :            : }
      70                 :            : 
      71                 :        350 : void LatinTreeNode::evaluateSeparateStorage(int& nSuggest, Node*& pSuggest) const
      72                 :            : {
      73         [ +  + ]:       9450 :     for ( sal_Unicode i = 0; i < 26; ++i )
      74                 :            :     {
      75         [ +  + ]:       9100 :         if ( m_pLeaves[i] )
      76                 :            :         {
      77         [ +  - ]:        200 :             if ( m_pLeaves[i]->m_nHighestProbaInSubtree > nSuggest )
      78                 :            :             {
      79                 :        200 :                 nSuggest = m_pLeaves[i]->m_nHighestProbaInSubtree;
      80                 :        200 :                 pSuggest = m_pLeaves[i];
      81                 :            :             }
      82         [ +  + ]:        200 :             if ( m_pLeaves[i]->m_nKeyProbability > nSuggest )
      83                 :            :             {
      84                 :         10 :                 nSuggest = m_pLeaves[i]->m_nKeyProbability;
      85                 :         10 :                 pSuggest = m_pLeaves[i];
      86                 :            :             }
      87                 :            :         }
      88                 :            :     }
      89                 :        350 : }
      90                 :            : 
      91                 :      35283 : void LatinTreeNode::freeMemory()
      92                 :            : {
      93                 :            :     // remove nodes from array
      94         [ +  + ]:     952641 :     for ( sal_Unicode i = 0; i < 26; ++i )
      95                 :            :     {
      96         [ +  + ]:     917358 :         if ( m_pLeaves[i] )
      97                 :            :         {
      98                 :       2004 :             m_pLeaves[i]->freeMemory();
      99         [ +  - ]:       2004 :             delete m_pLeaves[i];
     100                 :       2004 :             m_pLeaves[i] = NULL;
     101                 :            :         }
     102                 :            :     }
     103                 :            :     // clear list
     104         [ +  + ]:      66119 :     while ( m_lChildren.size() )
     105                 :            :     {
     106                 :      30836 :         Node* pTmp = m_lChildren.front();
     107                 :      30836 :         m_lChildren.pop_front();
     108         [ +  - ]:      30836 :         delete pTmp;
     109                 :            :     }
     110                 :      35283 : }
     111                 :            : 
     112                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10