| | 1 | | namespace MoreStructures.RecImmTrees; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Extension methods for <see cref="TreePath{TEdge, TNode}"/>. |
| | 5 | | /// </summary> |
| | 6 | | public static class TreePathExtensions |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Builds a new path of nodes, appending the nodes of the second path to the first path. |
| | 10 | | /// </summary> |
| | 11 | | /// <param name="first">The path, to append nodes to.</param> |
| | 12 | | /// <param name="second">The path, whose nodes have to be appended.</param> |
| | 13 | | /// <returns>A new path, whose nodes are the concatenation of the nodes of the two paths.</returns> |
| | 14 | | public static TreePath<TEdge, TNode> Concat<TEdge, TNode>( |
| | 15 | | this TreePath<TEdge, TNode> first, |
| | 16 | | TreePath<TEdge, TNode> second) |
| | 17 | | where TEdge : IRecImmDictIndexedTreeEdge<TEdge, TNode> |
| | 18 | | where TNode : IRecImmDictIndexedTreeNode<TEdge, TNode> => |
| 35 | 19 | | new(first.PathNodes.Concat(second.PathNodes)); |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Append the provided node with its incoming edge to the provided path, bulding a new path. |
| | 23 | | /// </summary> |
| | 24 | | /// <param name="path">The path, to appended the node and the edge to.</param> |
| | 25 | | /// <param name="edge">The edge, pointing to the node to be appended.</param> |
| | 26 | | /// <param name="node">The node to be appended.</param> |
| | 27 | | /// <returns> |
| | 28 | | /// A new path, whose nodes are the concatenation of the nodes of the provided path and the one appended. |
| | 29 | | /// </returns> |
| | 30 | | public static TreePath<TEdge, TNode> Append<TEdge, TNode>( |
| | 31 | | this TreePath<TEdge, TNode> path, |
| | 32 | | TEdge edge, |
| | 33 | | TNode node) |
| | 34 | | where TEdge : IRecImmDictIndexedTreeEdge<TEdge, TNode> |
| | 35 | | where TNode : IRecImmDictIndexedTreeNode<TEdge, TNode> => |
| 1 | 36 | | new(path.PathNodes.Concat(Enumerable.Repeat(KeyValuePair.Create(edge, node), 1))); |
| | 37 | | } |