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