示例#1
0
        public void Structure_MultipleBranchDeletion3()
        {
            var tree = new ZFastTrieSortedSet <string, string>(binarize);

            Assert.True(tree.Add("0tA", "0A"));
            Assert.True(tree.Add("UUa", "Ua"));
            Assert.True(tree.Add("0b5", "05"));
            Assert.True(tree.Add("8ll", "8l"));
            ZFastTrieDebugHelpers.DumpTree(tree);

            Assert.True(tree.Remove("0tA"));
            ZFastTrieDebugHelpers.DumpTree(tree);
            ZFastTrieDebugHelpers.StructuralVerify(tree);
        }
示例#2
0
        public void Structure_MultipleBranch_Simple()
        {
            var tree = new ZFastTrieSortedSet <string, string>(binarize);

            tree.Add("a", "8Jp3");
            tree.Add("c", "V6sl");
            tree.Add("h", "GX37");
            tree.Add("b", "KmGx");

            ZFastTrieDebugHelpers.DumpTree(tree);
            ZFastTrieDebugHelpers.StructuralVerify(tree);

            Assert.Equal(4, tree.Count);
        }
示例#3
0
        public void Structure_MultipleBranchDeletion2()
        {
            var tree = new ZFastTrieSortedSet <string, string>(binarize);

            Assert.True(tree.Add("CDb", "8J3"));
            Assert.True(tree.Add("tCK", "GX7"));
            Assert.True(tree.Add("B25", "f0o"));
            Assert.True(tree.Add("2mW", "Kmx"));
            Assert.True(tree.Add("gov", string.Empty));
            ZFastTrieDebugHelpers.DumpTree(tree);

            Assert.True(tree.Remove("CDb"));
            ZFastTrieDebugHelpers.DumpTree(tree);
            ZFastTrieDebugHelpers.StructuralVerify(tree);

            Assert.Equal(4, tree.Count);
        }
示例#4
0
        public void Structure_MultipleBranch_InternalExtent()
        {
            var tree = new ZFastTrieSortedSet <string, string>(binarize);

            tree.Add("8Jp3V6sl", "8Jp3");
            ZFastTrieDebugHelpers.DumpTree(tree);
            tree.Add("VJ7hXe8d", "V6sl");
            ZFastTrieDebugHelpers.DumpTree(tree);
            tree.Add("39XCGX37", "GX37");
            ZFastTrieDebugHelpers.DumpTree(tree);
            tree.Add("f04oKmGx", "f04o");
            ZFastTrieDebugHelpers.DumpTree(tree);
            tree.Add("feiF1gdt", "KmGx");
            ZFastTrieDebugHelpers.DumpTree(tree);

            ZFastTrieDebugHelpers.StructuralVerify(tree);
            Assert.Equal(5, tree.Count);
        }
示例#5
0
        public void Operations_SingleBranchInsertion()
        {
            string smallestKey = "Ar";
            string lesserKey   = "Oren";
            string greaterKey  = "oren";
            string greatestKey = "zz";

            var tree = new ZFastTrieSortedSet <string, string>(binarize);

            Assert.True(tree.Add(lesserKey, "eini"));
            ZFastTrieDebugHelpers.DumpTree(tree);
            Assert.True(tree.Add(greaterKey, "Eini"));
            ZFastTrieDebugHelpers.DumpTree(tree);

            ZFastTrieDebugHelpers.StructuralVerify(tree);

            Assert.Equal(lesserKey, tree.FirstKey());
            Assert.Equal(greaterKey, tree.LastKey());

            Assert.True(tree.Contains(greaterKey));
            Assert.True(tree.Contains(lesserKey));

            string value;

            Assert.True(tree.TryGet(lesserKey, out value));
            Assert.True(tree.TryGet(greaterKey, out value));
            Assert.False(tree.TryGet(greaterKey + "1", out value));
            Assert.False(tree.TryGet("1", out value));

            // x+ = min{y ? S | y = x} (the successor of x in S) - Page 160 of [1]
            // Therefore the successor of the key "oren" is greater or equal to "oren"
            Assert.Equal(lesserKey, tree.SuccessorOrDefault(lesserKey));
            Assert.Equal(greaterKey, tree.SuccessorOrDefault(greaterKey));
            Assert.Equal(greaterKey, tree.SuccessorOrDefault(lesserKey + "1"));
            Assert.Null(tree.SuccessorOrDefault(greatestKey));

            // x- = max{y ? S | y < x} (the predecessor of x in S) - Page 160 of [1]
            // Therefore the predecessor of the key "oren" is strictly less than "oren".
            Assert.Equal(lesserKey, tree.PredecessorOrDefault(greaterKey));
            Assert.Null(tree.PredecessorOrDefault(lesserKey));
            Assert.Null(tree.PredecessorOrDefault(smallestKey));
        }