private static void LookUp(string searchString, ITrie <int> trie) { Console.WriteLine("----------------------------------------"); Console.WriteLine("Look-up for string '{0}'", searchString); var stopWatch = new Stopwatch(); stopWatch.Start(); int[] result = trie.Retrieve(searchString).ToArray(); stopWatch.Stop(); string matchesText = String.Join(",", result); int matchesCount = result.Count(); if (matchesCount == 0) { Console.WriteLine("No matches found.\tTime: {0}", stopWatch.Elapsed); } else { Console.WriteLine(" {0} matches found. \tTime: {1}\tLines: {2}", matchesCount, stopWatch.Elapsed, matchesText); } }
private static void LookUp(string searchString, ITrie<int> trie) { Console.WriteLine("----------------------------------------"); Console.WriteLine("Look-up for string '{0}'", searchString); var stopWatch = new Stopwatch(); stopWatch.Start(); int[] result = trie.Retrieve(searchString).ToArray(); stopWatch.Stop(); string matchesText = String.Join(",", result); int matchesCount = result.Count(); if (matchesCount == 0) { Console.WriteLine("No matches found.\tTime: {0}", stopWatch.Elapsed); } else { Console.WriteLine(" {0} matches found. \tTime: {1}\tLines: {2}", matchesCount, stopWatch.Elapsed, matchesText); } }
private void Mesure(ITrie <string> trie, IEnumerable <string> randomText, IEnumerable <string> lookupWords, out TimeSpan buildUp, out TimeSpan avgLookUp) { var stopwatch = new Stopwatch(); stopwatch.Start(); foreach (string word in randomText) { trie.Add(word, word); } stopwatch.Stop(); buildUp = stopwatch.Elapsed; int lookupCount = 0; stopwatch.Reset(); foreach (string lookupWord in lookupWords) { lookupCount++; stopwatch.Start(); string[] found = trie.Retrieve(lookupWord).ToArray(); stopwatch.Stop(); } avgLookUp = new TimeSpan(stopwatch.ElapsedTicks / lookupCount); }
/// <summary> /// Lookup securities by criteria <paramref name="criteria" />. /// </summary> /// <param name="criteria">The instrument whose fields will be used as a filter.</param> /// <returns>Found instruments.</returns> public IEnumerable <Security> Lookup(Security criteria) { if (criteria == null) { throw new ArgumentNullException("criteria"); } var filter = criteria.Id.IsEmpty() ? (criteria.IsLookupAll() ? string.Empty : criteria.Code.ToLowerInvariant()) : criteria.Id.ToLowerInvariant(); IEnumerable <Security> securities; lock (_sync) { if (filter.IsEmpty()) { securities = _allSecurities; } else { securities = _trie.Retrieve(filter); if (!criteria.Id.IsEmpty()) { securities = securities.Where(s => s.Id.CompareIgnoreCase(criteria.Id)); } } securities = securities.ToArray(); } return(securities); //return ExcludeFilter == null ? securities : securities.Where(s => !ExcludeFilter(s)); }
public IEnumerable <string> Match(string query, int maxMatches) { var results = _trie.Retrieve(query.ToLower()).Take(maxMatches); var words = results.Select(x => _wordProvider.Words[x].ToLower()); return(words); }
public override IEnumerable <object> Retrieve(string searchTerm) { if (string.IsNullOrEmpty(searchTerm) || searchTerm.Length < MinSearchTextLength) { return(new List <string>()); } return(searchTrie.Retrieve(searchTerm).ToArray()); }
private void textBox1_TextChanged(object sender, EventArgs e) { string text = textBox1.Text; if (string.IsNullOrEmpty(text) || text.Length < 3) { return; } WordPosition[] result = m_PatriciaTrie.Retrieve(text).ToArray(); listBox1.Items.Clear(); foreach (WordPosition wordPosition in result) { listBox1.Items.Add(wordPosition); } }
public void FilterByInfix(string suff) { var lowerSuff = suff.ToLower(); if (!lowerSuff.Equals(currentFilterInfix)) { currentFilterInfix = lowerSuff; } FilteredEntries.Clear(); if (currentFilterInfix.Length < 3) { OnUpdated(); return; } var result = trie.Retrieve(currentFilterInfix); FilteredEntries.AddRange(result); OnUpdated(); }
/// <summary> /// Найти инструменты, соответствующие фильтру <paramref name="criteria"/>. /// </summary> /// <param name="criteria">Инструмент, поля которого будут использоваться в качестве фильтра.</param> /// <returns>Найденные инструменты.</returns> public IEnumerable <Security> Lookup(Security criteria) { if (criteria == null) { throw new ArgumentNullException("criteria"); } var filter = criteria.Id.IsEmpty() ? (criteria.Code == "*" ? string.Empty : criteria.Code.ToLowerInvariant()) : criteria.Id.ToLowerInvariant(); IEnumerable <Security> securities; if (filter.IsEmpty()) { var syncCollection = Securities as ISynchronizedCollection <Security>; securities = syncCollection != null ? syncCollection.SyncGet(c => c.ToArray()) : Securities.ToArray(); } else { lock (_trie) { securities = _trie.Retrieve(filter).ToArray(); if (!criteria.Id.IsEmpty()) { securities = securities.Where(s => s.Id.CompareIgnoreCase(criteria.Id)); } } } return(ExcludeFilter == null ? securities : securities.Where(s => !ExcludeFilter(s))); }
/// <summary> /// Find all instrument by filter. /// </summary> /// <param name="filter">Filter</param> /// <returns>Founded instruments.</returns> public IEnumerable <Security> Retrieve(string filter) { lock (_sync) return((filter.IsEmpty() ? _allSecurities : _trie.Retrieve(filter)).ToArray()); }
public IEnumerable <TNode> Retrieve(params string[] substrings) { return(indexer.Retrieve(substrings.First())); }