public HistoryManager(string filepath) { this.filepath = filepath; this.historyList = new List <string>(); this.autocompleteTrie = new PatriciaTrie <int>(); this.numCommands = 0; }
public void TestTrieDeterminism() { // No matter the order that things are put in, if the contents are the same then root hash is the same var trie1 = new PatriciaTrie(); var trie2 = new PatriciaTrie(); trie1.Put(dog, cat); trie1.Put(fish, bird); trie2.Put(fish, bird); trie2.Put(dog, cat); Assert.Equal(trie1.GetRootHash(), trie2.GetRootHash()); trie1.Put(dog, bird); trie1.Put(dog, fish); trie1.Put(dodecahedron, dog); trie1.Put(dodecahedron, cat); trie1.Put(fish, bird); trie1.Put(fish, cat); trie2.Put(dog, fish); trie2.Put(fish, cat); trie2.Put(dodecahedron, cat); Assert.Equal(trie1.GetRootHash(), trie2.GetRootHash()); }
public void TestOverflowBit() { PatriciaTrie <string> .KeyMapper <String> keyMapper = new PatriciaTrie <string> .StringKeyMapper(); String key = "a"; // a = U+0061 = 0000 0000 0110 0001 Assert.IsFalse(keyMapper.IsSet(0, key)); Assert.IsFalse(keyMapper.IsSet(1, key)); Assert.IsFalse(keyMapper.IsSet(2, key)); Assert.IsFalse(keyMapper.IsSet(3, key)); Assert.IsFalse(keyMapper.IsSet(4, key)); Assert.IsFalse(keyMapper.IsSet(5, key)); Assert.IsFalse(keyMapper.IsSet(6, key)); Assert.IsFalse(keyMapper.IsSet(7, key)); Assert.IsFalse(keyMapper.IsSet(8, key)); Assert.IsTrue(keyMapper.IsSet(9, key)); Assert.IsTrue(keyMapper.IsSet(10, key)); Assert.IsFalse(keyMapper.IsSet(11, key)); Assert.IsFalse(keyMapper.IsSet(12, key)); Assert.IsFalse(keyMapper.IsSet(13, key)); Assert.IsFalse(keyMapper.IsSet(14, key)); Assert.IsTrue(keyMapper.IsSet(15, key)); // Asking for overflow bits should return 1 Assert.IsTrue(keyMapper.IsSet(16, key)); Assert.IsTrue(keyMapper.IsSet(17, key)); Assert.IsTrue(keyMapper.IsSet(100, key)); }
/** * Construct airportTree, cityTree, and countryTree * REQUIREMENT: * 1. The list of airports should be constructed first */ public void constructAirportTrees() { // if error occured when loading the airports // skip this step if (_currentState == State.ERROR) return; // initialize the fields airportTree = new PatriciaTrie<AirportObject.Airport>(); cityTree = new PatriciaTrie<AirportObject.Airport>(); countryTree = new PatriciaTrie<AirportObject.Airport>(); for (int i = 0; i < airports.Count; i++) { AirportObject.Airport a = airports[i]; // skip it the airport name is null if (a.name == null) continue; // insert airport name, city, and country to each tree airportTree.Add(a.name.ToLower(), a); cityTree.Add(a.city.ToLower(), a); countryTree.Add(a.country.ToLower(), a); } // set the final state currentState = State.READY; }
public void Testing() { var trie = new PatriciaTrie <int>(); trie.Insert("SOME", 1); trie.Insert("ABACUS", 2); trie.Insert("SOMETHING", 3); trie.Insert("B", 4); trie.Insert("ABRACADABRA", 5); trie.Insert("THIS", 6); trie.Insert("SOMERSET", 7); trie.Delete("ABACUS"); var test1 = trie.Find("SOME"); var test2 = trie.Find("ABACUS"); var test3 = trie.Find("SOMETHING"); var test4 = trie.Find("B"); var test5 = trie.Find("ABRACADABRA"); var test6 = trie.Find("THIS"); var test7 = trie.Find("SOMERSET"); var test8 = trie.Find("SQUIRREL"); }
public void TestNull() { var trie = new PatriciaTrie <string>(); trie.Add("null", null); trie["null"].IsNull(); Assert.ThrowsException <ArgumentNullException>(() => trie.Add(null, "null")); }
public void TestNullKeyMap() { var keyMapper = new PatriciaTrie <string> .StringKeyMapper(); keyMapper.IsSet(0, null).IsFalse(); keyMapper.IsSet(100, null).IsFalse(); keyMapper.IsSet(1000, null).IsFalse(); }
public void TestNullKeyMap() { PatriciaTrie <string> .KeyMapper <String> keyMapper = new PatriciaTrie <string> .StringKeyMapper(); Assert.IsFalse(keyMapper.IsSet(0, null)); Assert.IsFalse(keyMapper.IsSet(100, null)); Assert.IsFalse(keyMapper.IsSet(1000, null)); }
public void TestEmpty() { PatriciaTrie <string> trie = new PatriciaTrie <string>(); Assert.IsTrue(trie.IsEmpty()); trie["hello"] = "world"; Assert.IsFalse(trie.IsEmpty()); }
public void TestCount() { var trie = new PatriciaTrie <string>(); trie.Count.Is(0); trie.Add("hello", "world"); trie.Count.Is(1); }
public void TestIsEmpty() { var trie = new PatriciaTrie <string>(); trie.IsEmpty.IsTrue(); trie.Add("hello", "world"); trie.IsEmpty.IsFalse(); }
public void TestEscapeChars() { PatriciaTrie <string> trie = new PatriciaTrie <string>(); trie["new"] = "no error"; Assert.IsFalse(trie.ContainsKeyPrefix("new\na")); Assert.IsFalse(trie.ContainsKeyPrefix("\n")); Assert.IsFalse(trie.ContainsKeyPrefix("\t")); }
public void TestJapanese() { var trie = new PatriciaTrie <string>(); trie.Add("寿司", "sushi"); trie.Add("刺身", "sashimi"); trie["寿司"].Is("sushi"); trie["刺身"].Is("sashimi"); }
public void TestEmptyKeyMap() { PatriciaTrie <string> .KeyMapper <string> keyMapper = new PatriciaTrie <string> .StringKeyMapper(); // Note: this is a special case handled in PatriciaTrie Assert.IsTrue(keyMapper.IsSet(0, "")); Assert.IsTrue(keyMapper.IsSet(100, "")); Assert.IsTrue(keyMapper.IsSet(1000, "")); }
public void TestJapanese() { PatriciaTrie <string> trie = new PatriciaTrie <string>(); trie["寿司"] = "sushi"; trie["刺身"] = "sashimi"; Assert.AreEqual("sushi", trie["寿司"]); Assert.AreEqual("sashimi", trie["刺身"]); }
public void TestEmptyKeyMap() { var keyMapper = new PatriciaTrie <string> .StringKeyMapper(); // Note: this is a special case handled in PatriciaTrie keyMapper.IsSet(0, "").IsTrue(); keyMapper.IsSet(100, "").IsTrue(); keyMapper.IsSet(1000, "").IsTrue(); }
public void Remove_OneKeyOneValue_Removed() { var trie = new PatriciaTrie <int>(); trie.Add("foo", 42); trie.Remove("foo", v => true); Assert.Equal(0, Enumerable.Count <int>(trie.Get("foo"))); }
public void TestLongString() { String longMovieTitle = "マルキ・ド・サドの演出のもとにシャラントン精神病院患者たちによって演じられたジャン=ポール・マラーの迫害と暗殺"; PatriciaTrie <string> trie = new PatriciaTrie <string>(); trie[longMovieTitle] = "found it"; Assert.AreEqual("found it", trie[longMovieTitle]); }
public void TestEscapeChars() { var trie = new PatriciaTrie <string>(); trie.Add("new", "no error"); trie.ContainsKeyPrefix("new\na").IsFalse(); trie.ContainsKeyPrefix("\n").IsFalse(); trie.ContainsKeyPrefix("\t").IsFalse(); }
public void TestTrieGetAfterFlush() { var memDb = new MemoryDictionarySource(); var trie = new PatriciaTrie(memDb); trie.Put(dog, cat); Assert.Equal(cat, trie.Get(dog)); trie.Flush(); Assert.Equal(cat, trie.Get(dog)); }
public void TestNotExactMatched() { ITrie <int> trie = new PatriciaTrie <int>(); trie.Add("aaabbb", 1); trie.Add("aaaccc", 2); var actual = trie.Retrieve("aab"); CollectionAssert.AreEquivalent(Enumerable.Empty <int>(), actual); }
public void TestLongString() { const string Value = "found it"; var longMovieTitle = "マルキ・ド・サドの演出のもとにシャラントン精神病院患者たちによって演じられたジャン=ポール・マラーの迫害と暗殺"; var trie = new PatriciaTrie <string>(); trie.Add(longMovieTitle, Value); trie[longMovieTitle].Is(Value); }
public void Add_OneKeyTwice_TwoResultValues() { var trie = new PatriciaTrie <int>(); trie.Add("foo", 42); trie.Add("foo", 43); var result = trie.Get("foo"); Assert.Equal(2, Enumerable.Count <int>(result)); }
public void Remove_OneKeyTwoValuesRemoveOne_ExpectedValueLost() { var trie = new PatriciaTrie <int>(); trie.Add("foo", 42); trie.Add("foo", 43); trie.Remove("foo", v => v == 42); Assert.Equal(43, Enumerable.First <int>(trie.Get("foo"))); }
public void TestEmptyInsert() { var trie = new PatriciaTrie <string>(); trie.Count.Is(0); trie.Add("", "i am empty bottle of beer!"); trie.Count.Is(1); trie[""].Is("i am empty bottle of beer!"); trie.Add("", "...and i'm an empty bottle of sake"); trie[""].Is("...and i'm an empty bottle of sake"); }
public void TestPrefix() { var trie = new PatriciaTrie <string>(); var tokyoPlaces = new string[] { "Hachiōji", "Tachikawa", "Musashino", "Mitaka", "Ōme", "Fuchū", "Akishima", "Chōfu", "Machida", "Koganei", "Kodaira", "Hino", "Higashimurayama", "Kokubunji", "Kunitachi", "Fussa", "Komae", "Higashiyamato", "Kiyose", "Higashikurume", "Musashimurayama", "Tama", "Inagi", "Hamura", "Akiruno", "Nishitōkyō" }; foreach (var place in tokyoPlaces) { trie.Add(place, place); } // Prefixes of Kodaira trie.ContainsKeyPrefix("K").IsTrue(); trie.ContainsKeyPrefix("Ko").IsTrue(); trie.ContainsKeyPrefix("Kod").IsTrue(); trie.ContainsKeyPrefix("Koda").IsTrue(); trie.ContainsKeyPrefix("Kodai").IsTrue(); trie.ContainsKeyPrefix("Kodair").IsTrue(); trie.ContainsKeyPrefix("Kodaira").IsTrue(); trie.ContainsKeyPrefix("Kodaira ").IsFalse(); trie.ContainsKeyPrefix("Kodaira ").IsFalse(); trie["Kodaira"].IsNotNull(); // Prefixes of Fussa trie.ContainsKeyPrefix("fu").IsFalse(); trie.ContainsKeyPrefix("Fu").IsTrue(); trie.ContainsKeyPrefix("Fus").IsTrue(); }
public void TestPrefix() { PatriciaTrie <string> trie = new PatriciaTrie <string>(); string[] tokyoPlaces = new string[] { "Hachiōji", "Tachikawa", "Musashino", "Mitaka", "Ōme", "Fuchū", "Akishima", "Chōfu", "Machida", "Koganei", "Kodaira", "Hino", "Higashimurayama", "Kokubunji", "Kunitachi", "Fussa", "Komae", "Higashiyamato", "Kiyose", "Higashikurume", "Musashimurayama", "Tama", "Inagi", "Hamura", "Akiruno", "Nishitōkyō" }; for (int i = 0; i < tokyoPlaces.Length; i++) { trie[tokyoPlaces[i]] = tokyoPlaces[i]; } // Prefixes of Kodaira Assert.IsTrue(trie.ContainsKeyPrefix("K")); Assert.IsTrue(trie.ContainsKeyPrefix("Ko")); Assert.IsTrue(trie.ContainsKeyPrefix("Kod")); Assert.IsTrue(trie.ContainsKeyPrefix("Koda")); Assert.IsTrue(trie.ContainsKeyPrefix("Kodai")); Assert.IsTrue(trie.ContainsKeyPrefix("Kodair")); Assert.IsTrue(trie.ContainsKeyPrefix("Kodaira")); Assert.IsFalse(trie.ContainsKeyPrefix("Kodaira ")); Assert.IsFalse(trie.ContainsKeyPrefix("Kodaira ")); Assert.IsTrue(trie["Kodaira"] != null); // Prefixes of Fussa Assert.IsFalse(trie.ContainsKeyPrefix("fu")); Assert.IsTrue(trie.ContainsKeyPrefix("Fu")); Assert.IsTrue(trie.ContainsKeyPrefix("Fus")); }
public void TestEmptyInsert() { PatriciaTrie <string> trie = new PatriciaTrie <string>(); Assert.IsTrue(trie.IsEmpty()); trie[""] = "i am empty bottle of beer!"; Assert.IsFalse(trie.IsEmpty()); Assert.AreEqual("i am empty bottle of beer!", trie[""]); trie[""] = "...and i'm an empty bottle of sake"; Assert.AreEqual("...and i'm an empty bottle of sake", trie[""]); }
public void Add_OneKeyTwice_ExpectedValues() { var trie = new PatriciaTrie <int>(); trie.Add("foo", 42); trie.Add("foo", 43); var result = Enumerable.ToArray <int>(trie.Get("foo")); Assert.Equal(42, result[0]); Assert.Equal(43, result[1]); }
public void TestTrieFlush() { var memDb = new MemoryDictionarySource(); var trie = new PatriciaTrie(memDb); trie.Put(dog, cat); trie.Put(fish, bird); Assert.Equal(cat, trie.Get(dog)); Assert.Empty(memDb.Db.Keys); trie.Flush(); Assert.NotEmpty(memDb.Db.Keys); // This should be more specific in future. How many nodes are we expecting? }
public void TestClear() { PatriciaTrie <string> trie = new PatriciaTrie <string>(); Assert.IsTrue(trie.IsEmpty()); Assert.AreEqual(0, trie.Count); trie["hello"] = "world"; trie["world"] = "hello"; Assert.IsFalse(trie.IsEmpty()); trie.Clear(); Assert.IsTrue(trie.IsEmpty()); Assert.AreEqual(0, trie.Count); }