summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2013-06-22 18:54:16 +0200
committerTomaž Vajngerl <quikee@gmail.com>2013-06-22 18:56:53 +0200
commit30e5a445254dac571d0b3ba2dc7a48e17ad58ec8 (patch)
treed6db9db0c3773eba4ea7473e354ac7b6a91af5ea /editeng
parent0291994f133644683e5d4fdea91c61471531bc93 (diff)
Trie lookup tree code review fixes
Change-Id: Ib2d2b668f2ec17742a069d63506cdd2d25d10f0d
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/lookuptree/Trie.cxx61
1 files changed, 39 insertions, 22 deletions
diff --git a/editeng/source/lookuptree/Trie.cxx b/editeng/source/lookuptree/Trie.cxx
index 1b8eeb7c84a5..4fbc19430bdb 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++ )