[Libreoffice-commits] core.git: editeng/source include/editeng

Tomaž Vajngerl quikee at gmail.com
Sat Jun 22 09:58:56 PDT 2013


 editeng/source/lookuptree/Trie.cxx |   61 +++++++++++++++++++++++--------------
 include/editeng/Trie.hxx           |   23 +------------
 2 files changed, 42 insertions(+), 42 deletions(-)

New commits:
commit 30e5a445254dac571d0b3ba2dc7a48e17ad58ec8
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Sat Jun 22 18:54:16 2013 +0200

    Trie lookup tree code review fixes
    
    Change-Id: Ib2d2b668f2ec17742a069d63506cdd2d25d10f0d

diff --git a/editeng/source/lookuptree/Trie.cxx b/editeng/source/lookuptree/Trie.cxx
index 1b8eeb7..4fbc194 100644
--- a/editeng/source/lookuptree/Trie.cxx
+++ b/editeng/source/lookuptree/Trie.cxx
@@ -16,6 +16,27 @@ using namespace std;
 
 /* TrieNode */
 
+struct TrieNode
+{
+    static const int LATIN_ARRAY_SIZE = 26;
+
+    sal_Unicode             mCharacter;
+    bool                    mMarker;
+    std::vector<TrieNode*>  mChildren;
+    TrieNode*               mLatinArray[LATIN_ARRAY_SIZE];
+
+
+    TrieNode(sal_Unicode aCharacter = '\0');
+    virtual ~TrieNode();
+
+    void      markWord();
+    TrieNode* findChild(sal_Unicode aCharacter);
+    TrieNode* traversePath(OUString sPath);
+    void      addNewChild(TrieNode* pChild);
+    void      collectSuggestions(OUString sPath, std::vector<OUString>& rSuggestionList);
+    void      collectSuggestionsForCurrentNode(TrieNode* pCurrent, OUString sPath, vector<OUString>& rSuggestionList);
+};
+
 TrieNode::TrieNode(sal_Unicode aCharacter) :
     mCharacter(aCharacter),
     mMarker(false)
@@ -85,13 +106,7 @@ void TrieNode::collectSuggestions(OUString sPath, vector<OUString>& rSuggestionL
     {
         TrieNode* pCurrent = mLatinArray[i];
         if (pCurrent != NULL)
-        {
-            OUString aStringPath = sPath + OUString(pCurrent->mCharacter);
-            if(pCurrent->mMarker)
-                rSuggestionList.push_back(aStringPath);
-            // recursivly traverse tree
-            pCurrent->collectSuggestions(aStringPath, rSuggestionList);
-        }
+            collectSuggestionsForCurrentNode(pCurrent, sPath, rSuggestionList);
     }
 
     // traverse nodes for other characters
@@ -100,16 +115,21 @@ void TrieNode::collectSuggestions(OUString sPath, vector<OUString>& rSuggestionL
     {
         TrieNode* pCurrent = *iNode;
         if (pCurrent != NULL)
-        {
-            OUString aStringPath = sPath + OUString(pCurrent->mCharacter);
-            if(pCurrent->mMarker)
-                rSuggestionList.push_back(aStringPath);
-            // recursivly traverse tree
-            pCurrent->collectSuggestions(aStringPath, rSuggestionList);
-        }
+            collectSuggestionsForCurrentNode(pCurrent, sPath, rSuggestionList);
     }
 }
 
+void TrieNode::collectSuggestionsForCurrentNode(TrieNode* pCurrent, OUString sPath, vector<OUString>& rSuggestionList)
+{
+    OUString aStringPath = sPath + OUString(pCurrent->mCharacter);
+    if(pCurrent->mMarker)
+    {
+        rSuggestionList.push_back(aStringPath);
+    }
+    // recursivly descend tree
+    pCurrent->collectSuggestions(aStringPath, rSuggestionList);
+}
+
 TrieNode* TrieNode::traversePath(OUString sPath)
 {
     TrieNode* pCurrent = this;
@@ -127,15 +147,12 @@ TrieNode* TrieNode::traversePath(OUString sPath)
 
 /* TRIE */
 
-Trie::Trie()
-{
-    mRoot = new TrieNode();
-}
+Trie::Trie() :
+    mRoot(new TrieNode())
+{}
 
 Trie::~Trie()
-{
-    delete mRoot;
-}
+{}
 
 void Trie::insert(OUString sInputString) const
 {
@@ -147,7 +164,7 @@ void Trie::insert(OUString sInputString) const
 
     // traverse the input string and modify the tree with new nodes / characters
 
-    TrieNode* pCurrent = mRoot;
+    TrieNode* pCurrent = mRoot.get();
     sal_Unicode aCurrentChar;
 
     for ( sal_Int32 i = 0; i < sInputString.getLength(); i++ )
diff --git a/include/editeng/Trie.hxx b/include/editeng/Trie.hxx
index 2ac76ae..3ade079 100644
--- a/include/editeng/Trie.hxx
+++ b/include/editeng/Trie.hxx
@@ -14,34 +14,17 @@
 #include <rtl/ustring.hxx>
 #include <vector>
 #include <editeng/editengdllapi.h>
+#include <boost/scoped_ptr.hpp>
 
 namespace editeng
 {
 
-struct TrieNode
-{
-    static const int LATIN_ARRAY_SIZE = 26;
-
-    sal_Unicode             mCharacter;
-    bool                    mMarker;
-    std::vector<TrieNode*>  mChildren;
-    TrieNode*               mLatinArray[LATIN_ARRAY_SIZE];
-
-
-    TrieNode(sal_Unicode aCharacter = '\0');
-    virtual ~TrieNode();
-
-    void      markWord();
-    TrieNode* findChild(sal_Unicode aCharacter);
-    TrieNode* traversePath(OUString sPath);
-    void      addNewChild(TrieNode* pChild);
-    void      collectSuggestions(OUString sPath, std::vector<OUString>& rSuggestionList);
-};
+struct TrieNode;
 
 class EDITENG_DLLPUBLIC Trie
 {
 private:
-    TrieNode* mRoot;
+    boost::scoped_ptr<TrieNode> mRoot;
 
 public:
     Trie();


More information about the Libreoffice-commits mailing list