Use stable sort in the engine.

So that unigram nodes with the same log probability are sorted
according to the order in which they were added to the language
model.
This commit is contained in:
Lukhnos Liu 2012-09-10 10:21:27 -07:00
parent 7b4568e152
commit 71921b848a
2 changed files with 2 additions and 2 deletions

View File

@ -90,7 +90,7 @@ namespace Formosa {
, m_selectedUnigramIndex(0)
, m_score(0.0)
{
sort(m_unigrams.begin(), m_unigrams.end(), Unigram::ScoreCompare);
stable_sort(m_unigrams.begin(), m_unigrams.end(), Unigram::ScoreCompare);
if (m_unigrams.size()) {
m_score = m_unigrams[0].score;

View File

@ -1043,7 +1043,7 @@ public:
vector<NodeAnchor> nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex);
// sort the nodes, so that longer nodes (representing longer phrases) are placed at the top of the candidate list
sort(nodes.begin(), nodes.end(), NodeAnchorDescendingSorter());
stable_sort(nodes.begin(), nodes.end(), NodeAnchorDescendingSorter());
// then use the C++ trick to retrieve the candidates for each node at/crossing the cursor
for (vector<NodeAnchor>::iterator ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) {