public TreeNodeMap Merge(ICollection <TreeNode> nodes) { if (nodes == null || nodes.Count == 0) { return(this); } if (_nodes.IsEmpty) { return(new TreeNodeMap(nodes)); } var set = Merge(this, new TreeNodeMap(nodes)); var tree = new TreeNodeMap(set); return(tree); }
private static ReadOnlyMemory <TreeNode> Merge(TreeNodeMap first, TreeNodeMap second) { var newArray = new TreeNode[first.Count + second.Count]; var i = 0; var aIndex = 0; var bIndex = 0; for (; aIndex < first.Count || bIndex < second.Count; i++) { if (aIndex >= first.Count) { newArray[i] = second[bIndex++]; } else if (bIndex >= second.Count) { newArray[i] = first[aIndex++]; } else { var a = first[aIndex]; var b = second[bIndex]; var cmp = StringComparer.Ordinal.Compare(a.Name, b.Name); if (cmp == 0) { newArray[i] = b; ++bIndex; ++aIndex; } else if (cmp < 0) { newArray[i] = a; ++aIndex; } else { newArray[i] = b; ++bIndex; } } } return(new ReadOnlyMemory <TreeNode>(newArray, 0, i)); }
public TreeNodeMap Merge(TreeNodeMap nodes) { if (nodes == default || nodes.Count == 0) { return(this); } if (_nodes.IsEmpty || _nodes.Length == 0) { return(nodes); } var set = Merge(this, nodes); var tree = new TreeNodeMap(set); return(tree); }
public override bool Equals(TreeNodeMap x, TreeNodeMap y) => x._nodes.MemoryEquals(y._nodes);
public override int GetHashCode(TreeNodeMap obj) => HashCode.Combine(obj._nodes.Length);