コード例 #1
0
        public void BurstTrie_ContainsTwo()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("con");
            trie.Add("zip");
            Assert.IsTrue(trie.Contains("con"));
            Assert.IsTrue(trie.Contains("zip"));
        }
コード例 #2
0
        public void BurstTrie_ReconstructDuplicates()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("0000000");
            trie.Add("0000001");
            trie.Add("0000000");

            List <string> allEntries = trie.GetAllEntries();

            Assert.IsTrue(allEntries[0].Equals("0000000"));
            Assert.IsTrue(allEntries[1].Equals("0000000"));
            Assert.IsTrue(allEntries[2].Equals("0000001"));
        }
コード例 #3
0
        public void BurstTrie_SortEnglish2Grams()
        {
            System.Console.Out.WriteLine("Total possibly duplicated words in input: " + _grams.Length);

            string[]  strings = _grams;
            BurstTrie trie    = new BurstTrie();

            foreach (string s in strings)
            {
                trie.Add(s);
            }

            List <string> sorted = trie.GetAllEntries();

            System.Console.Out.WriteLine("Words found through reconstruction: " + sorted.Count);

            //Dictionary<string, int> uniques = new Dictionary<string, int>();
            //foreach (string s in sorted)
            //    if (!uniques.ContainsKey(s))
            //        uniques.Add(s, 1);
            //    else
            //        uniques[s] = uniques[s] + 1;

            //System.Console.Out.WriteLine("unique words found: " + uniques.Keys.Count);
        }
コード例 #4
0
        public void BurstTrie_NotContainsUnrelated()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("a");
            Assert.IsFalse(trie.Contains("b"));
        }
コード例 #5
0
        public void BurstTrie_SuperstringNotContained()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("a");
            Assert.IsFalse(trie.Contains("aa"));
        }
コード例 #6
0
        public void BurstTrie_Blank()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("");
            Assert.IsTrue(trie.Contains(""));
        }
コード例 #7
0
        public void BurstTrie_FailedString()
        {
            string    s    = @"  You may copy it, give it away or\r\nre-use it under the terms of the Project Gutenberg License included\r\nwith this eBook or online at www";
            BurstTrie trie = new BurstTrie();

            trie.Add(s);
            Assert.IsTrue(trie.Contains(s));
        }
コード例 #8
0
        public void BurstTrie_ReconstructSimple()
        {
            BurstTrie trie = new BurstTrie();
            string    s    = "cat";

            trie.Add(s);
            List <string> all = trie.GetAllEntries();

            Assert.IsTrue(all.Contains(s));
        }
コード例 #9
0
        public void BurstTrie_MultiNotContained()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("con");
            trie.Add("cono");
            trie.Add("foo");
            trie.Add("fon");
            trie.Add("fondue");

            Assert.IsTrue(trie.Contains("con"));
            Assert.IsTrue(trie.Contains("fon"));
            Assert.IsTrue(trie.Contains("fondue"));
            Assert.IsFalse(trie.Contains("fo"));
            Assert.IsFalse(trie.Contains("cor"));
            Assert.IsFalse(trie.Contains("corse"));
            Assert.IsFalse(trie.Contains("fondu"));
            Assert.IsFalse(trie.Contains("f"));
            Assert.IsFalse(trie.Contains("x"));
        }
コード例 #10
0
        public void BurstTrie_EnglishWordsPerf()
        {
            string[]  strings = _englishWords;
            BurstTrie trie    = new BurstTrie();

            foreach (string s in strings)
            {
                trie.Add(s);
            }
            foreach (string s in strings)
            {
                Assert.IsTrue(trie.Contains(s));
            }
        }
コード例 #11
0
        public void BurstTrie_NotContained()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("con");
            Assert.IsFalse(trie.Contains("coo"));
            Assert.IsFalse(trie.Contains("cona"));
            Assert.IsFalse(trie.Contains("ocon"));
            Assert.IsFalse(trie.Contains("noc"));
            Assert.IsFalse(trie.Contains("cno"));
            Assert.IsFalse(trie.Contains("ocn"));
            Assert.IsFalse(trie.Contains("ccc"));
            Assert.IsFalse(trie.Contains("nnn"));
            Assert.IsFalse(trie.Contains("ooo"));
        }
コード例 #12
0
        public void BurstTrie_SubstringNotContained()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("abcde");
            Assert.IsFalse(trie.Contains("a"));
            Assert.IsFalse(trie.Contains("ab"));
            Assert.IsFalse(trie.Contains("abc"));
            Assert.IsFalse(trie.Contains("abcd"));
            Assert.IsFalse(trie.Contains("bcde"));
            Assert.IsFalse(trie.Contains("cde"));
            Assert.IsFalse(trie.Contains("de"));
            Assert.IsFalse(trie.Contains("e"));
            Assert.IsFalse(trie.Contains("b"));
            Assert.IsFalse(trie.Contains("c"));
            Assert.IsFalse(trie.Contains("d"));
        }
コード例 #13
0
        public void BurstTrie_AllContained()
        {
            BurstTrie trie = new BurstTrie();

            string[]      data = { "abc",      "abd",       "abe",
                                   "fonduepot",     "fondue",    "l",
                                   "f",             "0",         "aaaaaaaaaaaaaaaaa",
                                   "jkjkjkjkaaaaa", "aaaaaaaaa", "fabc" };
            List <string> items = new List <string>(data);

            foreach (string s in items)
            {
                trie.Add(s);
            }

            VerifyPresence(trie, items);
        }
コード例 #14
0
        public void BurstTrie_BurstBucket()
        {
            // 32 is current limit; revisit?
            string    s    = "test";
            BurstTrie trie = new BurstTrie();

            for (int i = 0; i < 33; i++)
            {
                trie.Add(s);
                s += i.ToString();
            }
            Assert.IsTrue(trie.Contains("test"));
            Assert.IsTrue(trie.Contains("test0"));
            Assert.IsTrue(trie.Contains("test01"));
            Assert.IsFalse(trie.Contains("est"));
            Assert.IsFalse(trie.Contains("est0"));
        }
コード例 #15
0
        public void BurstTrie_ReconstructBucket()
        {
            BurstTrie trie = new BurstTrie();

            BurstTrie.BurstThreshold = 5;

            string s = "TE";

            for (int i = 0; i < 7; i++)
            {
                trie.Add(s + (char)(65 + i));
            }

            List <string> all = trie.GetAllEntries();

            Assert.IsTrue(all.Contains("TEA"));
            Assert.IsTrue(all.Contains("TEF"));
        }
コード例 #16
0
        public void BurstTrie_BurstBucketSimple()
        {
            BurstTrie trie = new BurstTrie();

            BurstTrie.BurstThreshold = 5;

            string s = "TE";

            for (int i = 0; i < 7; i++)
            {
                trie.Add(s + (char)(65 + i));
            }
            Assert.IsTrue(trie.Contains("TEA"));
            Assert.IsTrue(trie.Contains("TEB"));
            Assert.IsTrue(trie.Contains("TEC"));
            Assert.IsTrue(trie.Contains("TED"));
            Assert.IsTrue(trie.Contains("TEE"));
            Assert.IsTrue(trie.Contains("TEF"));
            Assert.IsFalse(trie.Contains("TE"));
            Assert.IsFalse(trie.Contains("EA"));
            Assert.IsFalse(trie.Contains("A"));
        }
コード例 #17
0
        public void BurstTrie_NonBurstBucketSimple()
        {
            // 32 is current limit; revisit?
            BurstTrie trie = new BurstTrie();

            BurstTrie.BurstThreshold = 10;

            string s = "TE";

            for (int i = 0; i < 7; i++)
            {
                trie.Add(s + (char)(65 + i));
            }
            Assert.IsTrue(trie.Contains("TEA"));
            Assert.IsTrue(trie.Contains("TEB"));
            Assert.IsTrue(trie.Contains("TEC"));
            Assert.IsTrue(trie.Contains("TED"));
            Assert.IsTrue(trie.Contains("TEE"));
            Assert.IsTrue(trie.Contains("TEF"));
            Assert.IsFalse(trie.Contains("TE"));
            Assert.IsFalse(trie.Contains("EA"));
            Assert.IsFalse(trie.Contains("A"));
        }
コード例 #18
0
        public void BurstTrie_ReconstructOrdered()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("d");
            trie.Add("de");
            trie.Add("abcd");
            trie.Add("bce");
            trie.Add("0000000");
            trie.Add("def");
            trie.Add("abc");
            trie.Add("0000001");
            trie.Add("cde");
            trie.Add("0a");
            trie.Add("cd");
            trie.Add("bced");

            List <string> allEntries = trie.GetAllEntries();

            Assert.IsTrue(allEntries[0].Equals("0000000"));
            Assert.IsTrue(allEntries[1].Equals("0000001"));
            Assert.IsTrue(allEntries[2].Equals("0a"));
            Assert.IsTrue(allEntries[3].Equals("abc"));
            Assert.IsTrue(allEntries[4].Equals("abcd"));
            Assert.IsTrue(allEntries[5].Equals("bce"));
            Assert.IsTrue(allEntries[6].Equals("bced"));
            Assert.IsTrue(allEntries[7].Equals("cd"));
            Assert.IsTrue(allEntries[8].Equals("cde"));
            Assert.IsTrue(allEntries[9].Equals("d"));
            Assert.IsTrue(allEntries[10].Equals("de"));
            Assert.IsTrue(allEntries[11].Equals("def"));
        }
コード例 #19
0
        public void BurstTrie_OneNoCheck()
        {
            BurstTrie trie = new BurstTrie();

            trie.Add("con");
        }