public List <string> Predictions(string prefix) { List <string> pred = new List <string>(); if (prefix == null || prefix.Length == 0 || !root.ContainsKey(prefix[0])) { return(pred); } Node cur = root[prefix[0]]; for (int i = 1; i < prefix.Length; i++) { if (cur.hasChild(prefix[i])) { cur = cur.getChild(prefix[i]); } else { break; } } GetWords(cur, pred); return(pred); }
private void GetWords(Node node, List <string> pred) { if (pred.Count >= maxPredictions) { return; } foreach (char c in node.dict.Keys) { Node cur = node.getChild(c); if (cur.IsWord) { pred.Add(cur.str); if (pred.Count > maxPredictions) { return; } } GetWords(cur, pred); } }
private void GetWords(Node node, List<string> pred) { if (pred.Count >= maxPredictions) return; foreach (char c in node.dict.Keys) { Node cur = node.getChild(c); if (cur.IsWord) { pred.Add(cur.str); if (pred.Count > maxPredictions) return; } GetWords(cur, pred); } }