Skip to content

Commit

Permalink
Delete unneeded candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
p-kankowski committed Apr 16, 2013
1 parent 122ee16 commit 9e98f39
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions apps/keyboard/js/imes/latin/predictions.js
Expand Up @@ -399,16 +399,20 @@ var Predictions = function() {
var node = Object.create(null);
readNode(offset, node);
var i = _candidates.length - 1;

// Find the insertion point
var freq = node.freq * multiplier;
while (i >= 0 && freq > _candidates[i].freq)
i--;
// Don't insert a candidate that is worse than already found candidates
// if we already have the required number of candidates
if (i == _candidates.length - 1 && _candidates.length >= _maxSuggestions)
return;

// Insert the new candidate
_candidates.splice(i + 1, 0, { node: node, prefix: prefix,
multiplier: multiplier, freq: node.freq * multiplier });

// If we already have the required number of candidates,
// delete the candidate that is worse than others
if (_candidates.length > _maxSuggestions)
_candidates.pop();
}

function predictSuffixes() {
Expand Down

0 comments on commit 9e98f39

Please sign in to comment.