public void A_trie_with_some_values() { subject = new Trie<object>(); subject.Add("polyglot", "one"); subject.Add("polyhedron", "two"); subject.Add("polyglottal", "three"); }
private static void BuildUp(string fileName, ITrie<int> trie) { IEnumerable<WordAndLine> allWordsInFile = GetWordsFromFile(fileName); foreach (WordAndLine wordAndLine in allWordsInFile) { trie.Add(wordAndLine.Word, wordAndLine.Line); } }
public virtual void Setup() { Trie = CreateTrie(); for (int i = 0; i < KeyWords.Length; i++) { Trie.Add(KeyWords[i], i); } }
private void BuildUpTamil(string fileName, ITrie<string> trie) { IEnumerable<string> allWordsInFile = GetTamilWordsFromFile(fileName); foreach (var word in allWordsInFile) { trie.Add(word, word); } _isLoaded = true; }
public virtual void Setup() { Trie = CreateTrie(); for (int i = 0; i < Words40.Length; i++) { var q = new Queue<int>(); q.Enqueue(i); Trie.Add( Words40[i].ToCharArray(), q, (existing, insert) => existing == null ? insert : existing.Concat(insert)); } }
private Container InnerRegister(Type key, Type target, string name, ActivationMethod activationMethod) { if (key != target && target.IsAssignableFrom(key)) { throw new Exception($"Unnable to register type {target} with key {key}, target must be assignable to key."); } var containerRegistry = new ContainerRegistry(activationMethod, target); registries.Add(key.FullName, containerRegistry); if (key != target) { registries.Add(target.FullName, containerRegistry); } if (!string.IsNullOrEmpty(name)) { registries.Add(name, containerRegistry); } return(this); }
public ITrie Add(string s) { if (s == "") { _hasEmptyString = true; } else if (s[0] == _label) { _onlyChild = _onlyChild.Add(s.Substring(1)); } else { return(new TrieWithManyChildren(s, _hasEmptyString, _label, _onlyChild)); } return(this); }
private static void AddWordsToTrie(ICollection<string> words, ITrie trie) { Console.WriteLine("Adding words to trie... "); Console.WriteLine(new string('-', 30)); Timer.Start(); foreach (var word in words) { trie.Add(word); } Timer.Stop(); Console.WriteLine("Added words to trie {0} -> Elapsed time: {1}", words.Count, Timer.Elapsed); Console.WriteLine(new string('-', 30)); Timer.Reset(); }
/// <summary> /// add item to ITrie /// </summary> /// <param name="s"></param> /// <returns></returns> public ITrie Add(string s) { if (s == "") { _check = true; } else if (s[0].Equals(_label)) { _child = _child.Add(s.Substring(1)); } else { return(new TrieWithManyChildren(s, _check, _label, _child)); } return(this); }
public TrieWithOneChild(string s, bool wordHere) { if (s.Length <= 0) { throw new Exception("This trie should have a child"); } if (Char.IsUpper(s[0])) { throw new Exception(); } _letter = s[0]; _wordEndsHere = wordHere; _child = new TrieWithNoChildren(); _child = _child.Add(s.Substring(1)); }
public void ExhaustiveAddTimeMeasurement() { var stopwatch = new Stopwatch(); stopwatch.Start(); ITrie <int> trie = CreateTrie(); foreach (var phrase in Words40) { trie.Add(phrase, phrase.GetHashCode()); } stopwatch.Stop(); Console.WriteLine("Time: {0} milliseconds", stopwatch.Elapsed.TotalMilliseconds); }
public void TrieContractTryGetValue3() { ITrie <String, char, String> trie = this.GetInstance(); String key = "test"; trie.Add(key, "a"); String value; Assert.IsTrue(trie.TryGetValue(key, out value)); Assert.AreEqual("a", value); for (int i = 1; i < key.Length; i++) { Assert.IsFalse(trie.TryGetValue(key.Substring(0, i), out value)); Assert.IsNull(value); } }
public ITrie Add(string t) { if (t == "") { _empty = true; return(this); } else if (t[0] == _label) { _child.Add(t.Substring(1)); } else { return(new TrieWithManyChildren(t, _empty, _label, _child)); } return(this); }
public ITrie Add(string s) { if (s.Length == 0) { _wordEndsHere = true; return(this); } else if (s[0] == _letter) { _child = _child.Add(s.Substring(1)); return(this); } else { return(new TrieWithManyChildren(s, _wordEndsHere, _letter, _child)); } }
/// <summary> /// adds a string to the current trie /// </summary> /// <param name="s">string being added</param> /// <returns></returns> public ITrie Add(string s) { if (s == "") { _containsEmptyString = true; return(this); } else if (s[0] == _childLabel) { _child = _child.Add(s.Substring(1)); return(this); } else { return(new TrieWithManyChildren(s, _containsEmptyString, _childLabel, _child)); } }
/// <summary> /// Adds the given string to the trie rooted at this node. /// </summary> /// <param name="s"> string to be added </param> /// <returns></returns> public ITrie Add(string s) { if (s == "") { _hasEmptyString = true; } else if (s[0] < 'a' || s[0] > 'z') { throw new ArgumentException(); } else if (s[0] == _childLabel) { _child = _child.Add(s.Substring(1)); } else { return(new TrieWithManyChildren(s, _hasEmptyString, _childLabel, _child)); } return(this); }
/// <summary> /// Constructor man /// </summary> public CipherSolver() { InitializeComponent(); _dictionary = new TrieWithNoChildren(); try { using (StreamReader input = File.OpenText("dictionary.txt")) { while (!input.EndOfStream) { string word = input.ReadLine(); _dictionary = _dictionary.Add(word); } } MessageBox.Show("Dictionary successfully read."); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public static ITrie GetWordList(string file) { try { OpenFileDialog ofd = new OpenFileDialog(); file = ofd.FileName; using (StreamReader sr = new StreamReader(file)) { string line; while ((line = sr.ReadLine()) != null) { _words = _words.Add(line); } } } catch { throw new IOException("The word list contains the empty string."); } return(_words); }
/// <summary> /// Handles a Click event on the Open Dictionary button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxOpen_Click(object sender, EventArgs e) { if (uxOpenDialog.ShowDialog() == DialogResult.OK) { _dictionary = new TrieWithNoChildren(); try { using (StreamReader input = File.OpenText(uxOpenDialog.FileName)) { while (!input.EndOfStream) { string word = input.ReadLine(); _dictionary = _dictionary.Add(word); } } MessageBox.Show("Dictionary successfully read."); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
/// <summary> /// Handles a Load event on the GUI. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UserInterface_Load(object sender, EventArgs e) { uxOpenDialog.ShowDialog(); try { using (StreamReader input = File.OpenText(uxOpenDialog.FileName)) { while (!input.EndOfStream) { string word = input.ReadLine(); if (word.Length >= _minimumWordLength) { _wordList = _wordList.Add(word); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); Application.Exit(); } }
public ITrie Add(string s) { if (s == "") { _contains = true; return(this); } else if (s[0] < 'a' || s[0] > 'z') { throw new ArgumentException(); } else if (s[0] == _label) { s = s.Substring(1); _child = _child.Add(s); return(this); } else { TrieWithManyChildren children = new TrieWithManyChildren(s, _contains, _label, _child); return(children); } }
/// <summary> /// Adds a string to a trie /// </summary> /// <param name="s"> string to be added </param> /// <returns> either an added trie, or a new trie with many children </returns> public ITrie Add(string s) { if (s == "") { _empty = true; } else if (s[0] < 'a' || s[0] > 'z') { throw new ArgumentException(); } else { if (_label == s[0]) { _onlyChild = _onlyChild.Add(s.Substring(1)); return(this); } else { return(new TrieWithManyChildren(s, _empty, _label, _onlyChild)); } } return(this); }
private async void Load() { if (IsLoading) { return; } IsLoading = true; ReinitTrie(); try { var store = ServiceContainer.Resolve <IDataStore> (); var userId = ServiceContainer.Resolve <AuthManager> ().GetUserId(); var baseQuery = store.Table <TimeEntryData> () .OrderBy(r => r.StartTime, false) .Where(r => r.State != TimeEntryState.New && r.DeletedAt == null && r.UserId == userId && r.Description != null); var entries = await baseQuery.QueryAsync(); TimeEntries.AddRange(entries.ToList()); foreach (var entry in TimeEntries) { var description = entry.Description; trie.Add(description.Substring(0, Math.Min(description.Length, StringMaxLength)).ToLower(), entry); } } catch (Exception exc) { var log = ServiceContainer.Resolve <ILogger> (); log.Error(Tag, exc, "Failed to fetch time entries"); } finally { IsLoading = false; FilterByInfix(currentFilterInfix); } }
public void Trie_NotContainsUnrelated(ITrie trie) { trie.Add("a"); Assert.IsFalse(trie.Contains("b")); }
public void Trie_One(ITrie trie) { trie.Add("con"); }
public void Trie_Blank(ITrie trie) { trie.Add(""); Assert.IsTrue(trie.Contains("")); }
public void Trie_Contains(ITrie trie) { trie.Add("con"); Assert.IsTrue(trie.Contains("con")); }