private SVBlockTree(IEnumerable <SVBlockTree> children, SVBlockTree parent = null) { if (children is null) { throw new ArgumentNullException(nameof(children)); } Parent = parent; AddChildren(children); }
private bool SearchChildren(SVBlockTree tree) { // Block includes block (>) var firstIncludes = Children.Reverse().FirstOrDefault(t => t.Block.Includes(tree.Block)); if (firstIncludes != null) { bool added = firstIncludes.SearchChildren(tree); if (!added) { firstIncludes.AddChild(tree); return(true); } } return(false); }
public SVBlockTree Merge(SVBlockTree tree) { if (IsRoot) { if (!HasChildren) { Block = tree.Block; AddChildren(tree.Children); return(this); } if (tree.IsRoot) { return(new SVBlockTree(Children.Union(tree.Children))); } var added = SearchChildren(tree); if (!added) { AddChild(tree); } return(this); } if (tree.IsRoot) { if (!tree.HasChildren) { return(this); } SVBlockTree newTree = Merge(tree.Children.Last()); foreach (var child in tree.Children) { newTree = newTree.Merge(child); } return(newTree); } var block = tree.Block; int comparasion = Block.CompareTo(block); if (comparasion == 0) { return(this); } if (comparasion < 0) { return(tree.Merge(this)); } // Block > block bool includes = Block.Includes(block); if (includes) { bool added = SearchChildren(tree); if (!added) { AddChild(tree); } return(this); } if (Parent == null) { return(new SVBlockTree(new[] { tree, this })); } Parent.AddChild(tree); return(Parent); }
private void AddChild(SVBlockTree tree) { _subblocks.TryAdd(tree.Block.Vector, tree); tree.Parent = this; }