/// <summary> /// looks to see if any prefix is presents /// </summary> /// <param name="prefix">the prefix ebing searched for</param> /// <returns>a set of names </returns> private SortedSet <Employee> PrefixSearch(string prefix) { uxListBox.Items.Clear(); ITrie names = _names.GetCompletions(prefix); List <string> temp = new List <string>(); if (names != null) { uxListBox.BeginUpdate(); names.AddAll(new StringBuilder(prefix), temp); uxListBox.EndUpdate(); } SortedSet <Employee> nNames = new SortedSet <Employee>(); foreach (string s in temp) { int i = 0; if (_namesDictionary.TryGetValue(s, out List <Employee> tempList) == true) { nNames.Add(tempList[i]); i++; } } return(nNames); }
/// <summary> /// Adds all of the strings in this trie alphabetically to the end of the given list, with each /// string prefixed by the given prefix. /// </summary> /// <param name="prefix">The prefix.</param> /// <param name="list">The list to which the strings are to be added.</param> public void AddAll(StringBuilder prefix, IList list) { if (_hasEmptyString) { list.Add(prefix.ToString()); } prefix.Append(_childLabel); _child.AddAll(prefix, list); prefix.Length--; }
/// <summary> /// Handles a Click event on the "Look up Word" button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxLookUp_Click(object sender, EventArgs e) { uxCompletions.Items.Clear(); ITrie completions = _dictionary.GetCompletions(uxWord.Text); // Replace null with code to get the trie containing all completions of uxWord.Text if (completions != null) { uxCompletions.BeginUpdate(); completions.AddAll(new StringBuilder(uxWord.Text), uxCompletions.Items); uxCompletions.EndUpdate(); } }
/// <summary> /// Handles a Click event on the "Look up Completions" button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxLookUp_Click(object sender, EventArgs e) { uxCompletions.Items.Clear(); ITrie completions = _dictionary.GetCompletions(uxWord.Text); if (completions != null) { uxCompletions.BeginUpdate(); completions.AddAll(new StringBuilder(uxWord.Text), uxCompletions.Items); uxCompletions.EndUpdate(); } }
/// <summary> /// Handles a Click event on the "Look up Word" button. /// </summary> /// <param name="sender">boject from the event</param> /// <param name="e">event object</param> private void uxLookUp_Click(object sender, EventArgs e) { uxCompletions.Items.Clear(); ITrie completions = _dictionary.GetCompletions(uxWord.Text);// Fill in code to get the trie containing all completions of uxWord.Text if (completions != null) { uxCompletions.BeginUpdate(); // Add code to place all words beginning with uxWord.Text into the IList uxCompletions.Items. StringBuilder prefix = new StringBuilder(uxWord.Text); completions.AddAll(prefix, uxCompletions.Items); uxCompletions.EndUpdate(); } }