private void inputBox_TextChanged(object sender, EventArgs e)
        {
            autocompleteList.Items.Clear();

            // Stopwatch — это полезный инструмент для того, чтобы точно засекать время.
            // При измерении скорости работы алгоритма нужно использовать именно его.
            Stopwatch sw     = Stopwatch.StartNew();
            string    prefix = inputBox.Text;

            string[] foundItems      = autocompleter.FindByPrefix(prefix, 10);
            int      foundItemsCount = autocompleter.FindCount(prefix);

            if (foundItems.Length == 0)
            {
                string oneItem = autocompleter.FindByPrefix(prefix);
                if (oneItem != null)
                {
                    foundItems = new[] { oneItem }
                }
                ;
            }
            sw.Stop();
            sumMs += sw.ElapsedMilliseconds;
            count++;
            statusLabel.Text = string.Format("Found: {0}; Last time: {1} ms; Average time: {2} ms", foundItemsCount, sw.ElapsedMilliseconds, sumMs / count);
            foreach (string foundItem in foundItems)
            {
                autocompleteList.Items.Add(foundItem);
            }
        }
Esempio n. 2
0
 public void FindByPrefixTest()
 {
     var completer = new autocomplete.Autocompleter(new String[] { "abc", "abcd", "afb", "afe", "azsd" });
     var result = completer.FindByPrefix("az");
     Assert.AreEqual("azsd", result);
 }