add shrink for vector in DictTrie.hpp

This commit is contained in:
wyy 2014-04-11 15:25:03 +08:00
parent 0ca598b747
commit bb6c3f9e78

View File

@ -80,6 +80,7 @@ namespace CppJieba
{
assert(!_getInitFlag());
_loadDict(filePath, _nodeInfos);
_shrink(_nodeInfos);
_freqSum = _calculateFreqSum(_nodeInfos);
assert(_freqSum);
_minLogFreq = _calculateLogFreqAndGetMinValue(_nodeInfos, _freqSum);
@ -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;
}
@ -172,6 +174,11 @@ namespace CppJieba
return minLogFreq;
}
void _shrink(vector<DictUnit>& units) const
{
vector<DictUnit>(units.begin(), units.end()).swap(units);
}
};
}