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(); }
public VariableConfiguration(Action <string> onError) { Tree = new StringTree <TypeVariableDefinition>(onError, "\t", '.'); Definitions = new Dictionary <string, V>(StringComparer.InvariantCultureIgnoreCase); AutoSave = true; }
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); }
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)); }
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); }
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)); }
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);
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; }
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)); }
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>")); }
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); }
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>")); }
// 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]); }
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)); }
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())); }
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); }
/// <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); }
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")); }
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); }
private StringTree FormatLooseListItem(StringTree listItem) => IsBlankLines(listItem) ? EmptyListItem : StringTree.From("<li>", _newline, listItem, "</li>", _newline);
private StringTree FormatTightParagraph(StringTree par) => StringTree.From("<li>", ParagraphContents(par), "</li>", _newline);
private StringTree ParagraphContents(StringTree st) => st.TagTarget.ListValues.Skip(1).First();
private bool IsBlankLines(StringTree st) => st.TagValue == Tags.BlankLines;
private bool IsParagraph(StringTree st) => st.TagValue == Tags.Paragraph;
protected override StringTree BlockQuote(long start, long end, StringTree blocks) => StringTree.From("<blockquote>", _newline, blocks, "</blockquote>", _newline);