LCOV - code coverage report
Current view: top level - libreoffice/editeng/source/lookuptree - LatinTreeNode.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 41 97.6 %
Date: 2012-12-17 Functions: 7 7 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             : #include <editeng/LatinTreeNode.hxx>
      21             : #include <editeng/LatinLookupTree.hxx>
      22             : 
      23         268 : LatinTreeNode::LatinTreeNode(TreeHead* pHead, Node* pParent, const sal_Unicode cKey, const int nProbability) :
      24         268 :     Node( pHead, pParent, cKey, nProbability )
      25             : {
      26        7236 :     for ( sal_Unicode i = 0; i < 26; ++i )
      27             :     {
      28        6968 :         m_pLeaves[i] = NULL;
      29             :     }
      30         268 : }
      31             : 
      32         804 : LatinTreeNode::~LatinTreeNode()
      33             : {
      34         268 :     freeMemory();
      35         536 : }
      36             : 
      37         120 : bool LatinTreeNode::isSeparatedlyHandled(const sal_Unicode cKey) const
      38             : {
      39         120 :     return ( cKey >= sal_Unicode('a') && cKey <= sal_Unicode('z') );
      40             : }
      41             : 
      42         921 : Node*& LatinTreeNode::getChildRef(const sal_Unicode cKey, bool bCreatePlaceholder)
      43             : {
      44             :     // determine position in array if possible
      45         921 :     if ( cKey >= sal_Unicode('a') && cKey <= sal_Unicode('z') )
      46             :     {
      47         744 :         return m_pLeaves[cKey - LatinLookupTree::our_nLowerCaseA];
      48             :     }
      49             :     else
      50             :     {
      51         191 :         for ( std::list<Node*>::iterator i = m_lChildren.begin(); i != m_lChildren.end(); ++i )
      52             :         {
      53         122 :             if ( (*i)->m_cKey == cKey )
      54             :             {
      55         108 :                 return *i;
      56             :             }
      57             :         }
      58          69 :         if ( bCreatePlaceholder )
      59             :         {
      60             :             // Create new entry in case there isn't one.
      61          69 :             m_lChildren.push_back( NULL );
      62          69 :             return *(--m_lChildren.end());
      63             :         }
      64             :         else
      65             :         {
      66           0 :             return our_pNodeNullPointer;
      67             :         }
      68             :     }
      69             : }
      70             : 
      71         140 : void LatinTreeNode::evaluateSeparateStorage(int& nSuggest, Node*& pSuggest) const
      72             : {
      73        3780 :     for ( sal_Unicode i = 0; i < 26; ++i )
      74             :     {
      75        3640 :         if ( m_pLeaves[i] )
      76             :         {
      77          80 :             if ( m_pLeaves[i]->m_nHighestProbaInSubtree > nSuggest )
      78             :             {
      79          80 :                 nSuggest = m_pLeaves[i]->m_nHighestProbaInSubtree;
      80          80 :                 pSuggest = m_pLeaves[i];
      81             :             }
      82          80 :             if ( m_pLeaves[i]->m_nKeyProbability > nSuggest )
      83             :             {
      84           4 :                 nSuggest = m_pLeaves[i]->m_nKeyProbability;
      85           4 :                 pSuggest = m_pLeaves[i];
      86             :             }
      87             :         }
      88             :     }
      89         140 : }
      90             : 
      91         377 : void LatinTreeNode::freeMemory()
      92             : {
      93             :     // remove nodes from array
      94       10179 :     for ( sal_Unicode i = 0; i < 26; ++i )
      95             :     {
      96        9802 :         if ( m_pLeaves[i] )
      97             :         {
      98          98 :             m_pLeaves[i]->freeMemory();
      99          98 :             delete m_pLeaves[i];
     100          98 :             m_pLeaves[i] = NULL;
     101             :         }
     102             :     }
     103             :     // clear list
     104         783 :     while ( m_lChildren.size() )
     105             :     {
     106          29 :         Node* pTmp = m_lChildren.front();
     107          29 :         m_lChildren.pop_front();
     108          29 :         delete pTmp;
     109             :     }
     110         377 : }
     111             : 
     112             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10