public final class UndirectedGraphKruskal<T>
extends java.lang.Object
implements java.lang.Iterable<T>
Constructor and Description |
---|
UndirectedGraphKruskal() |
Modifier and Type | Method and Description |
---|---|
void |
addEdge(T one,
T two,
double length)
Given two nodes and a length, adds an arc of that length between those
nodes.
|
boolean |
addNode(T node)
Adds a new node to the graph.
|
boolean |
containsNode(T node)
Returns whether a given node is contained in the graph.
|
double |
edgeCost(T one,
T two)
Given two endpoints, returns the cost of the edge between them.
|
java.util.Map<T,java.lang.Double> |
edgesFrom(T node)
Given a node in the graph, returns an immutable view of the edges
leaving that node, as a map from endpoints to costs.
|
boolean |
isEmpty()
Returns whether the graph is empty.
|
java.util.Iterator<T> |
iterator()
Returns an iterator that can traverse the nodes in the graph.
|
void |
removeEdge(T one,
T two)
Removes the edge between the indicated endpoints from the graph.
|
int |
size()
Returns the number of nodes in the graph.
|
public boolean addNode(T node)
node
- The node to add.public void addEdge(T one, T two, double length)
one
- The first node.two
- The second node.length
- The length of the edge.java.util.NoSuchElementException
- If either the start or destination nodes
do not exist.public void removeEdge(T one, T two)
one
- The start node.two
- The destination node.java.util.NoSuchElementException
- If either node is not in the graph.public double edgeCost(T one, T two)
one
- The first endpoint.two
- The second endpoint.java.util.NoSuchElementException
- If the edge is not found or the endpoints
are not nodes in the graph.public java.util.Map<T,java.lang.Double> edgesFrom(T node)
node
- The node whose edges should be queried.java.util.NoSuchElementException
- If the node does not exist.public boolean containsNode(T node)
node
- to test for inclusion.public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public int size()
public boolean isEmpty()