mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add shrink for vector in DictTrie.hpp
This commit is contained in:
parent
0ca598b747
commit
bb6c3f9e78
@ -80,6 +80,7 @@ namespace CppJieba
|
|||||||
{
|
{
|
||||||
assert(!_getInitFlag());
|
assert(!_getInitFlag());
|
||||||
_loadDict(filePath, _nodeInfos);
|
_loadDict(filePath, _nodeInfos);
|
||||||
|
_shrink(_nodeInfos);
|
||||||
_freqSum = _calculateFreqSum(_nodeInfos);
|
_freqSum = _calculateFreqSum(_nodeInfos);
|
||||||
assert(_freqSum);
|
assert(_freqSum);
|
||||||
_minLogFreq = _calculateLogFreqAndGetMinValue(_nodeInfos, _freqSum);
|
_minLogFreq = _calculateLogFreqAndGetMinValue(_nodeInfos, _freqSum);
|
||||||
@ -114,6 +115,7 @@ namespace CppJieba
|
|||||||
words.push_back(dictUnits[i].word);
|
words.push_back(dictUnits[i].word);
|
||||||
valuePointers.push_back(&dictUnits[i]);
|
valuePointers.push_back(&dictUnits[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
TrieType * trie = new TrieType(words, valuePointers);
|
TrieType * trie = new TrieType(words, valuePointers);
|
||||||
return trie;
|
return trie;
|
||||||
}
|
}
|
||||||
@ -172,6 +174,11 @@ namespace CppJieba
|
|||||||
return minLogFreq;
|
return minLogFreq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _shrink(vector<DictUnit>& units) const
|
||||||
|
{
|
||||||
|
vector<DictUnit>(units.begin(), units.end()).swap(units);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user