public class OrderedKAryTree<V,E> extends AbstractTypedGraph<V,E> implements Tree<V,E>
Tree in which each vertex has
≤ k children. The value of 'k' is specified by the constructor
parameter. A specific child (edge) can be retrieved directly by specifying the
index at which the child is located. By default, new (child) vertices
are added at the lowest index available, if no index is specified.| Modifier and Type | Class and Description |
|---|---|
protected class |
OrderedKAryTree.VertexData |
| Modifier and Type | Field and Description |
|---|---|
protected Map<E,Pair<V>> |
edge_vpairs |
protected int |
height |
protected int |
order |
protected V |
root |
protected Map<V,OrderedKAryTree.VertexData> |
vertex_data |
edge_type| Constructor and Description |
|---|
OrderedKAryTree(int order)
Creates a new instance with the specified order (maximum number of children).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdge(E edge,
Collection<? extends V> vertices,
EdgeType edge_type) |
boolean |
addEdge(E edge,
Pair<? extends V> endpoints,
EdgeType edgeType)
Adds
edge to this graph with the specified endpoints
and EdgeType. |
boolean |
addEdge(E e,
V parent,
V child) |
boolean |
addEdge(E e,
V v1,
V v2,
EdgeType edge_type) |
boolean |
addEdge(E e,
V parent,
V child,
int index)
Adds the specified
child vertex and edge e to the graph
with the specified parent vertex parent. |
boolean |
addVertex(V vertex) |
boolean |
containsEdge(E edge) |
boolean |
containsVertex(V vertex) |
E |
findEdge(V v1,
V v2) |
Collection<E> |
findEdgeSet(V v1,
V v2) |
V |
getChild(V vertex,
int index)
Returns the child of
vertex at position index
in this tree, or null if it has no child at that position. |
int |
getChildCount(V vertex) |
E |
getChildEdge(V vertex,
int index) |
Collection<E> |
getChildEdges(V vertex) |
Collection<V> |
getChildren(V vertex)
Returns an ordered list of
vertex's child vertices. |
int |
getDepth(V vertex) |
V |
getDest(E directed_edge) |
int |
getEdgeCount() |
Collection<E> |
getEdges() |
Pair<V> |
getEndpoints(E edge) |
static <V,E> com.google.common.base.Supplier<DirectedGraph<V,E>> |
getFactory(int order) |
int |
getHeight()
Returns the height of the tree, or -1 if the tree is empty.
|
int |
getIncidentCount(E edge) |
Collection<E> |
getIncidentEdges(V vertex) |
Collection<V> |
getIncidentVertices(E edge) |
Collection<E> |
getInEdges(V vertex) |
int |
getNeighborCount(V vertex) |
Collection<V> |
getNeighbors(V vertex) |
V |
getOpposite(V vertex,
E edge) |
Collection<E> |
getOutEdges(V vertex) |
V |
getParent(V vertex) |
E |
getParentEdge(V vertex) |
int |
getPredecessorCount(V vertex) |
Collection<V> |
getPredecessors(V vertex) |
V |
getRoot() |
V |
getSource(E directed_edge) |
int |
getSuccessorCount(V vertex) |
Collection<V> |
getSuccessors(V vertex) |
Collection<Tree<V,E>> |
getTrees() |
int |
getVertexCount() |
Collection<V> |
getVertices() |
int |
inDegree(V vertex) |
boolean |
isDest(V vertex,
E edge) |
boolean |
isIncident(V vertex,
E edge) |
boolean |
isLeaf(V vertex)
Returns
true if vertex is a leaf of this tree,
i.e., if it has no children. |
boolean |
isNeighbor(V v1,
V v2) |
boolean |
isPredecessor(V v1,
V v2)
Returns true iff
v1 is the parent of v2. |
boolean |
isRoot(V vertex)
Returns
true if vertex is a leaf of this tree,
i.e., if it has no children. |
boolean |
isSource(V vertex,
E edge) |
boolean |
isSuccessor(V v1,
V v2) |
int |
outDegree(V vertex) |
boolean |
removeEdge(E edge) |
boolean |
removeVertex(V vertex) |
getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType, hasEqualEdgeType, validateEdgeTypeaddEdge, addEdge, degree, getValidatedEndpoints, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddEdge, degree, getDefaultEdgeType, getEdgeCount, getEdges, getEdgeTypeprotected Map<V,OrderedKAryTree.VertexData> vertex_data
protected int height
protected V root
protected int order
public OrderedKAryTree(int order)
order - the maximum number of children ("k") that any vertex can havepublic static <V,E> com.google.common.base.Supplier<DirectedGraph<V,E>> getFactory(int order)
V - the vertex type for the graph SupplierE - the edge type for the graph Supplierorder - the maximum number of children ("k") that any vertex can haveSupplier that creates an instance of this graph type.public int getChildCount(V vertex)
getChildCount in interface Forest<V,E>vertex - the vertex whose number of children is to be returnedvertex hasForest.getChildCount(java.lang.Object)public E getChildEdge(V vertex, int index)
vertex - the vertex whose child edge is to be returnedindex - the index of the edge to be returnedvertex at index index, that is,
its ith child edge.public Collection<E> getChildEdges(V vertex)
getChildEdges in interface Forest<V,E>Forest.getChildEdges(java.lang.Object)public Collection<V> getChildren(V vertex)
vertex's child vertices.
If there is no child in position i, then the list will contain
null in position i. If vertex has no children
then the empty set will be returned.getChildren in interface Forest<V,E>Forest.getChildren(java.lang.Object)public int getDepth(V vertex)
getDepth in interface Tree<V,E>Tree.getDepth(java.lang.Object)public int getHeight()
getHeight in interface Tree<V,E>Tree.getHeight()public V getParent(V vertex)
getParent in interface Forest<V,E>Forest.getParent(java.lang.Object)public E getParentEdge(V vertex)
getParentEdge in interface Forest<V,E>Forest.getParentEdge(java.lang.Object)public Collection<Tree<V,E>> getTrees()
getTrees in interface Forest<V,E>Forest.getTrees()public boolean addEdge(E e, V parent, V child, int index)
child vertex and edge e to the graph
with the specified parent vertex parent. If index is
greater than or equal to 0, then the child is placed at position
index; if it is less than 0, the child is placed at the lowest
available position; if it is greater than or equal to the order of this
tree, an exception is thrown.e - the edge to addparent - the source of the edge to be addedchild - the destination of the edge to be addedindex - the position at which e is to be added as a child of parenttrue if the graph has been modifiedGraph.addEdge(java.lang.Object, java.lang.Object, java.lang.Object)public boolean addEdge(E e, V parent, V child)
addEdge in interface Graph<V,E>addEdge in class AbstractGraph<V,E>Graph.addEdge(java.lang.Object, java.lang.Object, java.lang.Object)public boolean addEdge(E e, V v1, V v2, EdgeType edge_type)
addEdge in interface Graph<V,E>addEdge in class AbstractGraph<V,E>Graph.addEdge(java.lang.Object, java.lang.Object, java.lang.Object, edu.uci.ics.jung.graph.util.EdgeType)public V getDest(E directed_edge)
getDest in interface Graph<V,E>getDest in interface Hypergraph<V,E>Graph.getDest(java.lang.Object)public Pair<V> getEndpoints(E edge)
getEndpoints in interface Graph<V,E>Graph.getEndpoints(java.lang.Object)public Collection<E> getInEdges(V vertex)
getInEdges in interface Graph<V,E>getInEdges in interface Hypergraph<V,E>Graph.getInEdges(java.lang.Object)public V getOpposite(V vertex, E edge)
getOpposite in interface Graph<V,E>getOpposite in class AbstractGraph<V,E>Graph.getOpposite(java.lang.Object, java.lang.Object)public Collection<E> getOutEdges(V vertex)
getOutEdges in interface Graph<V,E>getOutEdges in interface Hypergraph<V,E>Graph.getOutEdges(java.lang.Object)public int getPredecessorCount(V vertex)
getPredecessorCount in interface Graph<V,E>getPredecessorCount in class AbstractGraph<V,E>vertex is the root, -1 if the vertex is
not an element of this tree, and 1 otherwiseGraph.getPredecessorCount(java.lang.Object)public Collection<V> getPredecessors(V vertex)
getPredecessors in interface Graph<V,E>getPredecessors in interface Hypergraph<V,E>Graph.getPredecessors(java.lang.Object)public V getSource(E directed_edge)
getSource in interface Graph<V,E>getSource in interface Hypergraph<V,E>Graph.getSource(java.lang.Object)public int getSuccessorCount(V vertex)
getSuccessorCount in interface Graph<V,E>getSuccessorCount in class AbstractGraph<V,E>Graph.getSuccessorCount(java.lang.Object)public Collection<V> getSuccessors(V vertex)
getSuccessors in interface Graph<V,E>getSuccessors in interface Hypergraph<V,E>Graph.getSuccessors(java.lang.Object)public int inDegree(V vertex)
inDegree in interface Graph<V,E>inDegree in interface Hypergraph<V,E>inDegree in class AbstractGraph<V,E>Graph.inDegree(java.lang.Object)public boolean isDest(V vertex, E edge)
isDest in interface Graph<V,E>Graph.isDest(java.lang.Object, java.lang.Object)public boolean isLeaf(V vertex)
true if vertex is a leaf of this tree,
i.e., if it has no children.vertex - the vertex to be queriedtrue if outDegree(vertex)==0public boolean isPredecessor(V v1, V v2)
v1 is the parent of v2.
Note that if v2 is the root and v1 is null,
this method returns true.isPredecessor in interface Graph<V,E>isPredecessor in class AbstractGraph<V,E>Graph.isPredecessor(java.lang.Object, java.lang.Object)public boolean isRoot(V vertex)
true if vertex is a leaf of this tree,
i.e., if it has no children.vertex - the vertex to be queriedtrue if outDegree(vertex)==0public boolean isSource(V vertex, E edge)
isSource in interface Graph<V,E>Graph.isSource(java.lang.Object, java.lang.Object)public boolean isSuccessor(V v1, V v2)
isSuccessor in interface Graph<V,E>isSuccessor in class AbstractGraph<V,E>Graph.isSuccessor(java.lang.Object, java.lang.Object)public int outDegree(V vertex)
outDegree in interface Graph<V,E>outDegree in interface Hypergraph<V,E>outDegree in class AbstractGraph<V,E>Graph.outDegree(java.lang.Object)public boolean addEdge(E edge, Collection<? extends V> vertices, EdgeType edge_type)
addEdge in interface Hypergraph<V,E>addEdge in class AbstractGraph<V,E>Hypergraph.addEdge(java.lang.Object, java.util.Collection)public boolean addVertex(V vertex)
addVertex in interface Hypergraph<V,E>Hypergraph.addVertex(java.lang.Object)public boolean isIncident(V vertex, E edge)
isIncident in interface Hypergraph<V,E>isIncident in class AbstractGraph<V,E>Hypergraph.isIncident(java.lang.Object, java.lang.Object)public boolean isNeighbor(V v1, V v2)
isNeighbor in interface Hypergraph<V,E>isNeighbor in class AbstractGraph<V,E>Hypergraph.isNeighbor(java.lang.Object, java.lang.Object)public boolean containsEdge(E edge)
containsEdge in interface Hypergraph<V,E>Hypergraph.containsEdge(java.lang.Object)public boolean containsVertex(V vertex)
containsVertex in interface Hypergraph<V,E>Hypergraph.containsVertex(java.lang.Object)public E findEdge(V v1, V v2)
findEdge in interface Hypergraph<V,E>findEdge in class AbstractGraph<V,E>Hypergraph.findEdge(java.lang.Object, java.lang.Object)public Collection<E> findEdgeSet(V v1, V v2)
findEdgeSet in interface Hypergraph<V,E>findEdgeSet in class AbstractGraph<V,E>Hypergraph.findEdgeSet(java.lang.Object, java.lang.Object)public V getChild(V vertex, int index)
vertex at position index
in this tree, or null if it has no child at that position.vertex - the vertex to queryindex - the index of the child to returnvertex at position index
in this tree, or null if it has no child at that positionArrayIndexOutOfBoundsException - if index is not in
the range [0, order-1]public int getEdgeCount()
getEdgeCount in interface Hypergraph<V,E>Hypergraph.getEdgeCount()public Collection<E> getEdges()
getEdges in interface Hypergraph<V,E>Hypergraph.getEdges()public int getIncidentCount(E edge)
getIncidentCount in interface Hypergraph<V,E>getIncidentCount in class AbstractGraph<V,E>Hypergraph.getIncidentCount(java.lang.Object)public Collection<E> getIncidentEdges(V vertex)
getIncidentEdges in interface Hypergraph<V,E>Hypergraph.getIncidentEdges(java.lang.Object)public Collection<V> getIncidentVertices(E edge)
getIncidentVertices in interface Hypergraph<V,E>getIncidentVertices in class AbstractGraph<V,E>Hypergraph.getIncidentVertices(java.lang.Object)public int getNeighborCount(V vertex)
getNeighborCount in interface Hypergraph<V,E>getNeighborCount in class AbstractGraph<V,E>Hypergraph.getNeighborCount(java.lang.Object)public Collection<V> getNeighbors(V vertex)
getNeighbors in interface Hypergraph<V,E>Hypergraph.getNeighbors(java.lang.Object)public int getVertexCount()
getVertexCount in interface Hypergraph<V,E>Hypergraph.getVertexCount()public Collection<V> getVertices()
getVertices in interface Hypergraph<V,E>Hypergraph.getVertices()public boolean removeEdge(E edge)
removeEdge in interface Hypergraph<V,E>Hypergraph.removeEdge(java.lang.Object)public boolean removeVertex(V vertex)
removeVertex in interface Hypergraph<V,E>Hypergraph.removeVertex(java.lang.Object)public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType)
AbstractGraphedge to this graph with the specified endpoints
and EdgeType.addEdge in class AbstractGraph<V,E>edge - the edge to be addedendpoints - the endpoints to be connected to this edgeedgeType - the type of edge to addCopyright © 2016. All rights reserved.