Skip to content

Commit

Permalink
add shrink for vector in DictTrie.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyiwu committed Apr 11, 2014
1 parent 0ca598b commit bb6c3f9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/DictTrie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace CppJieba
{
assert(!_getInitFlag());
_loadDict(filePath, _nodeInfos);
_shrink(_nodeInfos);
_freqSum = _calculateFreqSum(_nodeInfos);
assert(_freqSum);
_minLogFreq = _calculateLogFreqAndGetMinValue(_nodeInfos, _freqSum);
Expand Down Expand Up @@ -114,6 +115,7 @@ namespace CppJieba
words.push_back(dictUnits[i].word);
valuePointers.push_back(&dictUnits[i]);
}

TrieType * trie = new TrieType(words, valuePointers);
return trie;
}
Expand Down Expand Up @@ -172,6 +174,11 @@ namespace CppJieba
return minLogFreq;
}

void _shrink(vector<DictUnit>& units) const
{
vector<DictUnit>(units.begin(), units.end()).swap(units);
}


};
}
Expand Down

0 comments on commit bb6c3f9

Please sign in to comment.