V
- the vertex typeE
- the edge typepublic class DelegateForest<V,E> extends GraphDecorator<V,E> implements Forest<V,E>
Forest
that delegates to a specified DirectedGraph
instance.delegate
Constructor and Description |
---|
DelegateForest()
Creates an instance backed by a new
DirectedSparseGraph instance. |
DelegateForest(DirectedGraph<V,E> delegate)
Creates an instance backed by the input
DirectedGraph i |
Modifier and Type | Method and Description |
---|---|
boolean |
addEdge(E e,
V v1,
V v2,
EdgeType edgeType)
Add an edge to the tree, connecting v1, the parent and v2, the child.
|
boolean |
addEdgeWithVertices(E edge,
java.util.Collection<? extends V> vertices)
Adds
edge to this graph. |
void |
addTree(Tree<V,E> tree)
Adds
tree to this graph as an element of this forest. |
boolean |
addVertex(V vertex)
Add vertex as a root of the tree
|
int |
getChildCount(V vertex)
Returns the number of children that
vertex has in this tree. |
java.util.Collection<E> |
getChildEdges(V vertex)
Returns the edges connecting
vertex to its children
in this tree. |
java.util.Collection<V> |
getChildren(V v)
Returns the children of
v . |
int |
getDepth(V v)
computes and returns the depth of the tree from the
root to the passed vertex
|
int |
getHeight()
computes and returns the height of the tree
|
int |
getIncidentCount(E edge)
Returns the number of vertices that are incident to
edge . |
V |
getParent(V child)
Returns the parent of
vertex in this tree. |
E |
getParentEdge(V vertex)
Returns the edge connecting
vertex to its parent in
this tree. |
java.util.List<V> |
getPath(V child)
returns an ordered list of the nodes beginning at the root
and ending at the passed child node, including all intermediate
nodes.
|
V |
getRoot()
getter for the root of the tree
returns null, as this tree has >1 roots
|
java.util.Collection<V> |
getRoots()
Returns the root of each tree of this forest as a
Collection . |
java.util.Collection<Tree<V,E>> |
getTrees()
Returns a view of this graph as a collection of
Tree instances. |
boolean |
isInternal(V v)
computes and returns whether the passed node is
neither the root, nor a leaf node.
|
boolean |
isLeaf(V v)
Returns true if
v has no child nodes. |
boolean |
isRoot(V v)
Returns true if
v has no parent node. |
boolean |
removeChild(V orphan)
removes a node from the tree, causing all descendants of
the removed node also to be removed
|
boolean |
removeEdge(E edge)
Removes
edge from this tree, and the subtree rooted
at the child vertex incident to edge . |
boolean |
removeEdge(E edge,
boolean remove_subtree)
Removes
edge from this tree. |
boolean |
removeVertex(V vertex)
Removes
vertex from this tree, and the subtree
rooted at vertex . |
boolean |
removeVertex(V vertex,
boolean remove_subtrees)
Removes
vertex from this tree. |
void |
setRoot(V root)
adds root as a root of the tree
|
addEdge, addEdgeWithVertices, containsEdge, containsVertex, degree, findEdge, findEdgeSet, getDefaultEdgeType, getDest, getEdgeCount, getEdgeCount, getEdges, getEdgesView, getEdgeType, getEndpoints, getIncidentEdges, getIncidentVertices, getInEdges, getNeighborCount, getNeighbors, getOpposite, getOutEdges, getPredecessorCount, getPredecessors, getSource, getSuccessorCount, getSuccessors, getVertexCount, getVerticesView, inDegree, isDest, isIncident, isNeighbor, isPredecessor, isSource, isSuccessor, outDegree
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addEdge, getDest, getEndpoints, getInEdges, getOpposite, getOutEdges, getPredecessorCount, getPredecessors, getSource, getSuccessorCount, getSuccessors, inDegree, isDest, isPredecessor, isSource, isSuccessor, outDegree
addEdgeWithVertices, containsEdge, containsVertex, degree, findEdge, findEdgeSet, getDefaultEdgeType, getEdgeCount, getEdgeCount, getEdges, getEdgesView, getEdgeType, getIncidentEdges, getIncidentVertices, getNeighborCount, getNeighbors, getVertexCount, getVerticesView, isIncident, isNeighbor
public DelegateForest()
DirectedSparseGraph
instance.public DelegateForest(DirectedGraph<V,E> delegate)
DirectedGraph
ipublic boolean addEdge(E e, V v1, V v2, EdgeType edgeType)
public boolean addVertex(V vertex)
addVertex
in interface Hypergraph<V,E>
addVertex
in class GraphDecorator<V,E>
vertex
- the tree root to addpublic boolean removeEdge(E edge)
edge
from this tree, and the subtree rooted
at the child vertex incident to edge
.
(The subtree is removed to ensure that the tree in which the edge
was found is still a tree rather than a forest. To change this
behavior so that theremoveEdge
in interface Hypergraph<V,E>
removeEdge
in class GraphDecorator<V,E>
edge
- the edge to removetrue
iff the tree was modifiedpublic boolean removeEdge(E edge, boolean remove_subtree)
edge
from this tree.
If remove_subtree
is true
, removes
the subtree rooted at the child vertex incident to edge
.
Otherwise, leaves the subtree intact as a new component tree of this
forest.edge
- the edge to removeremove_subtree
- if true
, remove the subtreetrue
iff the tree was modifiedpublic boolean removeVertex(V vertex)
vertex
from this tree, and the subtree
rooted at vertex
.removeVertex
in interface Hypergraph<V,E>
removeVertex
in class GraphDecorator<V,E>
vertex
- the vertex to removetrue
iff the tree was modifiedpublic boolean removeVertex(V vertex, boolean remove_subtrees)
vertex
from this tree.
If remove_subtrees
is true
, removes
the subtrees rooted at the children of vertex
.
Otherwise, leaves these subtrees intact as new component trees of this
forest.vertex
- the vertex to removeremove_subtrees
- if true
, remove the subtrees
rooted at vertex
's childrentrue
iff the tree was modifiedpublic java.util.List<V> getPath(V child)
child
- the last node in the path from the rootpublic V getParent(V child)
Forest
vertex
in this tree.
(If vertex
is the root, returns null
.)
The parent of a vertex is defined as being its predecessor in the
(unique) shortest path from the root to this vertex.
This is a convenience method which is equivalent to
Graph.getPredecessors(vertex).iterator().next()
.getParent
in interface Forest<V,E>
vertex
in this treeGraph.getPredecessors(Object)
,
Forest.getParentEdge(Object)
public V getRoot()
public void setRoot(V root)
root
- the initial tree rootpublic boolean removeChild(V orphan)
orphan
- the node to removepublic int getDepth(V v)
v
- the node who's depth is computedpublic int getHeight()
public boolean isInternal(V v)
true
if v
is neither a leaf
nor a rootpublic boolean isLeaf(V v)
v
has no child nodes.public java.util.Collection<V> getChildren(V v)
v
.getChildren
in interface Forest<V,E>
v
- the vertex whose children are to be returnedCollection
of children of vertex
in this treeGraph.getSuccessors(Object)
,
Forest.getChildEdges(Object)
public boolean isRoot(V v)
v
has no parent node.public int getIncidentCount(E edge)
Hypergraph
edge
. For hyperedges, this can be any nonnegative integer; for edges this
must be 2 (or 1 if self-loops are permitted).
Equivalent to getIncidentVertices(edge).size()
.getIncidentCount
in interface Hypergraph<V,E>
getIncidentCount
in class GraphDecorator<V,E>
edge
- the edge whose incident vertex count is to be returnededge
.public boolean addEdgeWithVertices(E edge, java.util.Collection<? extends V> vertices)
Hypergraph
edge
to this graph. Fails under the following circumstances:
edge
is already an element of the graphedge
or vertices
is null
vertices
has the wrong number of vertices for the graph typevertices
are already connected by another edge in this graph, and this graph does not accept parallel edgesaddEdgeWithVertices
in interface Hypergraph<V,E>
addEdgeWithVertices
in class GraphDecorator<V,E>
edge
- the edgevertices
- the verticestrue
if the add is successful, and false
otherwisepublic java.util.Collection<V> getRoots()
Collection
.public java.util.Collection<Tree<V,E>> getTrees()
Forest
Tree
instances.public void addTree(Tree<V,E> tree)
tree
to this graph as an element of this forest.tree
- the tree to add to this forest as a componentpublic int getChildCount(V vertex)
Forest
vertex
has in this tree.
The children of a vertex are defined as being the successors of
that vertex on the respective (unique) shortest paths from the root to
those vertices.
This is syntactic (maple) sugar for getSuccessorCount(vertex)
.getChildCount
in interface Forest<V,E>
vertex
- the vertex whose child edges are to be returnedCollection
of edges connecting
vertex
to its children in this treeForest.getChildEdges(Object)
,
Forest.getChildren(Object)
,
Graph.getSuccessorCount(Object)
public java.util.Collection<E> getChildEdges(V vertex)
Forest
vertex
to its children
in this tree.
The children of a vertex are defined as being the successors of
that vertex on the respective (unique) shortest paths from the root to
those vertices.
This is syntactic (maple) sugar for getOutEdges(vertex)
.getChildEdges
in interface Forest<V,E>
vertex
- the vertex whose child edges are to be returnedCollection
of edges connecting
vertex
to its children in this treeGraph.getOutEdges(Object)
,
Forest.getChildren(Object)
public E getParentEdge(V vertex)
Forest
vertex
to its parent in
this tree.
(If vertex
is the root, returns null
.)
The parent of a vertex is defined as being its predecessor in the
(unique) shortest path from the root to this vertex.
This is a convenience method which is equivalent to
Graph.getInEdges(vertex).iterator().next()
,
and also to Graph.findEdge(vertex, getParent(vertex))
.getParentEdge
in interface Forest<V,E>
vertex
to its parent, or
null
if vertex
is the rootGraph.getInEdges(Object)
,
Forest.getParent(Object)
Copyright © 2021, 2022 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence