static void Main(string[] args)
        {
            // Instantiate a new IntTree and populate it with Nodes.
            IntTree tree = new IntTree();

            tree.Add(tree.Root, 10);
            tree.Add(tree.Root, 5);
            tree.Add(tree.Root, 3);
            tree.Add(tree.Root, 4);
            tree.Add(tree.Root, 7);
            tree.Add(tree.Root, 15);

            // Convert the IntTree Nodes to an array of int values.
            int[] TreeArray = tree.PreOrder(tree.Root);

            // Output the int array to the console.
            foreach (int value in TreeArray)
            {
                Console.Write($"{value}, ");
            }
            Console.WriteLine();

            // Convert the IntTree to a FizzBuzz StringTree.
            StringTree st = FizzBuzzTree(tree);

            // Convert the StringTree Nodes to an array of string values.
            string[] FizzArray = st.PreOrder(st.Root);

            // Output the string array to the console.
            foreach (string value in FizzArray)
            {
                Console.Write($"{value}, ");
            }
            Console.WriteLine();
        }
예제 #2
0
 public VariableConfiguration(Action <string> onError)
 {
     Tree        = new StringTree <TypeVariableDefinition>(onError, "\t", '.');
     Definitions =
         new Dictionary <string, V>(StringComparer.InvariantCultureIgnoreCase);
     AutoSave = true;
 }
예제 #3
0
        private StringTree FormatTightListItem(StringTree listItem)
        {
            if (IsBlankLines(listItem))
            {
                return(EmptyListItem);
            }
            if (IsParagraph(listItem))
            {
                return(FormatTightParagraph(listItem));
            }
            var list = listItem.ListValues.SkipWhile(IsBlankLines);
            var cnt  = list.Count();

            if (cnt == 0)
            {
                return(EmptyListItem);
            }
            var first = list.First();

            if (IsParagraph(first))
            {
                var last = list.Last();
                if (cnt == 1 ||
                    (cnt == 2 && IsBlankLines(last) && !last.TagTarget.IsList))
                {
                    return(FormatTightParagraph(first));
                }
                return(StringTree.From("<li>", ParagraphContents(first), _newline,
                                       list.Skip(1).ToStringTree(), "</li>", _newline));
            }
            var items = list.Select(i => IsParagraph(i) ? ParagraphContents(i) : i);

            return(StringTree.From("<li>", _newline, items.ToStringTree(), "</li>",
                                   _newline));
        }
        [MenuItem(itemName: "Assets/Create/Atoms Search &1", isValidateFunction: false, priority: -1)] // Adds to the project window's create menu
        public static void AtomsSearchMenu()
        {
            StringTree <Type> typeTree = new StringTree <Type>();

            foreach (var type in TypeCache.GetTypesWithAttribute <CreateAssetMenuAttribute>()
                     .Where(t => t.GetCustomAttribute <AtomsSearchable>(true) != null))
            {
                var name = type.GetCustomAttribute <CreateAssetMenuAttribute>().menuName;
                var i    = name.LastIndexOf('/');
                name = (i == -1) ? name : name.Substring(0, i + 1) + type.Name;
                typeTree.Insert(name, type, 1);
            }

            var projectBrowserType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.ProjectBrowser");
            var projectBrowser     = EditorWindow.GetWindow(projectBrowserType);

            Vector2 xy = new Vector2(projectBrowser.position.x + 10, projectBrowser.position.y + 60);

            var dropdown = new SearchTypeDropdown(new AdvancedDropdownState(), typeTree,
                                                  (s) =>
            {
                EditorApplication.ExecuteMenuItem("Assets/Create/" + s.GetCustomAttribute <CreateAssetMenuAttribute>().menuName);
            })
            {
                MinimumSize = new Vector2(projectBrowser.position.width - 20, projectBrowser.position.height - 80)
            };

            var rect = new Rect(xy.x, xy.y, projectBrowser.position.width - 20, projectBrowser.position.height);

            dropdown.Show(new Rect()); // don't use this to position the
            var window = typeof(SearchTypeDropdown).GetField("m_WindowInstance", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(dropdown) as EditorWindow;

            window.position = rect;
        }
        static StringTree FizzBuzzTree(IntTree tree)
        {
            StringTree NewTree = new StringTree();

            PreOrderFizzBuzz(tree.Root, NewTree);

            return(NewTree);
        }
예제 #6
0
        protected override StringTree Heading(long start, long end, int headingLevel,
                                              StringTree headingText)
        {
            var tag = "h" + headingLevel;

            return(StringTree.From(HtmlHelper.OpenTag(tag), headingText,
                                   HtmlHelper.CloseTag(tag), _newline));
        }
예제 #7
0
 public StringTreeTest()
 {
     words = new List <string>()
     {
         "hellow", "car", "sleep", "home"
     };
     tree = new StringTree(words);
 }
        public void CheckTreeRootIfNotFizzBuzz()
        {
            StringTree stringTree = new StringTree(new Node("4"));

            Program.FizzBuzzTree(stringTree);

            Assert.Equal("4", stringTree.Root.Value);
        }
예제 #9
0
        protected override StringTree OrderedList(long start, long end,
                                                  string firstNumber, StringTree listItems)
        {
            var num = int.Parse(firstNumber);

            return(FormatListItems(
                       num == 1 ? "<ol>" : string.Format("<ol start=\"{0}\">", num),
                       "</ol>", listItems.ListValues));
        }
예제 #10
0
 protected override StringTree CodeBlock(long start, long end,
                                         string codeBlock, string infoString) =>
 StringTree.From(
     infoString == null ?
     "<pre><code>" :
     string.Format("<pre><code class=\"language-{0}\">",
                   infoString.Split(' ', '\t')[0]),
     HtmlHelper.HtmlEncode(codeBlock),
     "</code></pre>", _newline);
예제 #11
0
 public VariableConfiguration(Action <string> onError)
 {
     this.Tree = new StringTree <TypeVariableDefinition>(onError, "\t", new char[1]
     {
         '.'
     });
     this.Definitions =
         new Dictionary <string, V>((IEqualityComparer <string>)StringComparer.InvariantCultureIgnoreCase);
     this.AutoSave = true;
 }
예제 #12
0
        protected override StringTree BlankLines(long start, long end, StringTree lines)
        {
            var res = StringTree.Empty;

            if (lines.ListValues.Count() > 1)
            {
                res = res.Tag(Tags.MultiLines);
            }
            return(res.Tag(Tags.BlankLines));
        }
예제 #13
0
 protected override StringTree Link(long start, long end, StringTree text,
                                    string dest, string title)
 {
     dest = HtmlHelper.HtmlEncode(Uri.EscapeUriString(dest),
                                  HtmlHelper.ExtendedEncode);
     title = HtmlHelper.HtmlEncode(title);
     return(StringTree.From("<a href=\"", dest ?? StringTree.Empty,
                            title != null ? "\" title=\"" + title : StringTree.Empty,
                            "\">", text, "</a>"));
 }
예제 #14
0
 protected override StringTree Image(long start, long end, StringTree alt,
                                     string dest, string title)
 {
     dest  = Uri.EscapeUriString(dest);
     title = HtmlHelper.HtmlEncode(title);
     return(StringTree.From("<img src=\"", dest ?? StringTree.Empty,
                            "\" alt=\"", alt,
                            title != null ? "\" title=\"" + title : StringTree.Empty,
                            "\" />"));
 }
        public void CheckOtherNodesAlsoChange()
        {
            StringTree stringTree = new StringTree(new Node("4"));

            stringTree.Add(new Node("3"), stringTree.Root);
            stringTree.Add(new Node("7"), stringTree.Root);
            stringTree.Add(new Node("15"), stringTree.Root);
            Program.FizzBuzzTree(stringTree);

            Assert.Equal("FizzBuzz", stringTree.Root.LeftChild.LeftChild.Value);
        }
예제 #16
0
 protected override StringTree StrongEmphasis(long start, long end,
                                              StringTree text)
 {
     if (text.IsList && text.ListValues.Count() == 1 &&
         text.ListValues.First().TagValue == Tags.Emphasis)
     {
         var list = text.ListValues.First().TagTarget.ListValues;
         return(Emphasis(start, end,
                         StringTree.From("<strong>", list.Skip(1).First(), "</strong>")));
     }
     return(StringTree.From("<strong>", text, "</strong>"));
 }
예제 #17
0
        // HACK ALERT: We exploit the point when value in datacontext have been changed but UI did not update yet
        private void StringOperatorUpdated(object sender, DataTransferEventArgs e)
        {
            DropDownBox src = e.Source as DropDownBox;

            if (src == null)
            {
                return;
            }
            FilterTree tree = src.DataContext as FilterTree;

            if (tree == null)
            {
                return;
            }
            int newType = tree.Children[0].Type;
            int oldType = StringExprTypePicker.ConvertBack(src.SelectedIndex);

            if (newType != StringPatternLexer.COMPLEX && oldType == StringPatternLexer.COMPLEX)
            {
                StringTree constTree = tree.Children[0].GetChild(1) as StringTree;
                if (constTree != null)
                {
                    constTree.Text = Filter.Escape(constTree.Text);
                    MarkNodeAsUpdated(constTree);
                }
            }
            else if (newType == StringPatternLexer.COMPLEX && oldType != StringPatternLexer.COMPLEX)
            {
                StringTree constTree = tree.Children[0].GetChild(1) as StringTree;
                if (constTree != null)
                {
                    switch (oldType)
                    {
                    case StringPatternLexer.IS:
                        constTree.Text = "%" + constTree.Text + "%";
                        break;

                    case StringPatternLexer.BEGINS:
                        constTree.Text = constTree.Text + "%";
                        break;

                    case StringPatternLexer.ENDS:
                        constTree.Text = "%" + constTree.Text;
                        break;
                    }
                }
                MarkNodeAsUpdated(constTree);
            }
            MarkNodeAsUpdated((FilterTree)tree.Children[0]);
        }
예제 #18
0
        private static string Dump(Haplogroup group, bool dumpSnps)
        {
            var d = dumpSnps;

            return(StringTree.Create(
                       group,
                       x => !d || !x.Mutations.Any() ?
                       x.Name :
                       string.Format(
                           "{0} ({1})",
                           x.Name,
                           x.Mutations.Select(y => y.Snp).Join(", ")),
                       x => x.Children));
        }
예제 #19
0
        private bool IsLooseListItem(StringTree listItem, bool isLast)
        {
            if (IsParagraph(listItem))
            {
                return(false);
            }
            if (IsBlankLines(listItem))
            {
                return(listItem.HasTag(Tags.MultiLines));
            }
            var list  = listItem.ListValues.Skip(1);
            var blank = list.FirstOrDefault(li => IsBlankLines(li));

            return(blank != null && !(isLast && blank == list.Last()));
        }
예제 #20
0
        static void Main(string[] args)
        {
            StringTree stringTree = new StringTree(new Node("3"));

            stringTree.Add(new Node("5"), stringTree.Root);
            stringTree.Add(new Node("2"), stringTree.Root);
            stringTree.Add(new Node("4"), stringTree.Root);
            stringTree.Add(new Node("10"), stringTree.Root);
            stringTree.Add(new Node("9"), stringTree.Root);
            stringTree.Add(new Node("22"), stringTree.Root);
            stringTree.Add(new Node("15"), stringTree.Root);
            stringTree.BreadthFirst(stringTree.Root);
            Console.WriteLine("-----");
            FizzBuzzTree(stringTree);
            stringTree.BreadthFirst(stringTree.Root);
        }
        static void PreOrderFizzBuzz(Node root, StringTree newTree)
        {
            if (root.IntValue % 3 == 0 && root.IntValue % 5 == 0)
            {
                newTree.Add(root, "FizzBuzz", root.IntValue);
            }
            else if (root.IntValue % 3 == 0)
            {
                newTree.Add(root, "Fizz", root.IntValue);
            }
            else if (root.IntValue % 5 == 0)
            {
                newTree.Add(root, "Buzz", root.IntValue);
            }
            else
            {
                newTree.Add(root, root.IntValue.ToString(), root.IntValue);
            }

            PreOrderFizzBuzz(root.LeftChild, newTree);

            PreOrderFizzBuzz(root.RightChild, newTree);
        }
예제 #22
0
        /// <summary>
        /// Method utilizing the breadthFirst traversal approach. Takes in a tree and
        /// checks the value of each node and conducts if it is Fizz, Buzz or FizzBuzz
        /// </summary>
        /// <param name="stringTree">Input is a tree</param>
        /// <returns>The tree modified</returns>
        public static StringTree FizzBuzzTree(StringTree stringTree)
        {
            Node root = stringTree.Root;

            Queue <Node> breadth = new Queue <Node>();

            breadth.Enqueue(root);

            while (breadth.TryPeek(out root))
            {
                Node front = breadth.Dequeue();
                front.Value = FizzBuzz(front.Value);
                if (front.LeftChild != null)
                {
                    breadth.Enqueue(front.LeftChild);
                }
                if (front.RightChild != null)
                {
                    breadth.Enqueue(front.RightChild);
                }
            }
            return(stringTree);
        }
예제 #23
0
    public static void Main(string[] args)
    {
        StringTree tt = new StringTree();

        tt.add("banana");
        tt.add("apple");
        tt.add("mango");
        tt.add("banana");
        tt.add("apple");
        tt.add("mango");
        Console.WriteLine("\nSearch results for apple, banana, grapes and mango :\n");
        tt.find("apple");
        tt.find("banana");
        tt.find("banan");
        tt.find("applkhjkhkj");
        tt.find("grapes");
        tt.find("mango");
        tt.print();
        Console.WriteLine("frequency returned :: " + tt.frequency("apple"));
        Console.WriteLine("frequency returned :: " + tt.frequency("banana"));
        Console.WriteLine("frequency returned :: " + tt.frequency("mango"));
        Console.WriteLine("frequency returned :: " + tt.frequency("hemant"));
    }
예제 #24
0
        private StringTree FormatListItems(string startTag, string EndTag,
                                           List <StringTree> items)
        {
            var last    = items.Last();
            var isLoose = items.Any(i => IsLooseListItem(i, i == last));

            var res = StringTree.From(startTag, _newline,
                                      (isLoose ?
                                       items.Select(FormatLooseListItem) :
                                       items.Select(FormatTightListItem))
                                      .ToStringTree(),
                                      EndTag, _newline);

            // Lift the BlankLines tag if the last line of the list is empty
            if (last.IsList)
            {
                var lastBlock = last.ListValues.Last();
                if (IsBlankLines(lastBlock))
                {
                    res = res.Tag(Tags.BlankLines);
                }
            }
            return(res);
        }
예제 #25
0
 private StringTree FormatLooseListItem(StringTree listItem) =>
 IsBlankLines(listItem) ?
 EmptyListItem :
 StringTree.From("<li>", _newline, listItem, "</li>", _newline);
예제 #26
0
 private StringTree FormatTightParagraph(StringTree par) =>
 StringTree.From("<li>", ParagraphContents(par), "</li>", _newline);
예제 #27
0
 private StringTree ParagraphContents(StringTree st) =>
 st.TagTarget.ListValues.Skip(1).First();
예제 #28
0
 private bool IsBlankLines(StringTree st) =>
 st.TagValue == Tags.BlankLines;
예제 #29
0
 private bool IsParagraph(StringTree st) =>
 st.TagValue == Tags.Paragraph;
예제 #30
0
 protected override StringTree BlockQuote(long start, long end,
                                          StringTree blocks) =>
 StringTree.From("<blockquote>", _newline, blocks, "</blockquote>", _newline);