1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package edu.caltech.cs2.interfaces;
public interface IGraph<V, E> {
/**
* Add a vertex to the graph.
* @param vertex The vertex to add
* @return true if vertex was not present already.
*/
public boolean addVertex(V vertex);
/**
* Adds edge e to the graph.
*
* @param e The edge to add.
* @throws IllegalArgumentException
* If src and dest are not valid vertices (eg. refers to vertices not in the graph).
* @return true if an edge from src to dest did not exist previously.
* false if an edge from src to dest did exist previously, in which case the edge value is updated
*/
public boolean addEdge(V src, V dest, E e);
/**
* Adds edge e to the graph in both directionns.
*
* @param e The edge to add.
* @throws IllegalArgumentException
* If v1 and v2 are not valid vertices (eg. refers to vertices not in the graph).
* @return true if an edge between src and dest did not exist in either direction.
* false if an edge between src and dest existed in either direction, in which case the edge value is
* updated.
*/
public boolean addUndirectedEdge(V v1, V v2, E e);
/**
* Remove an edge from src to dest from the graph.
*
* @throws IllegalArgumentException if src or dest is not in the graph.
* @return true if an edge from src to dest was present.
*/
public boolean removeEdge(V src, V dest);
/**
* Returns the set of vertices in the graph.
* @return The set of all vertices in the graph.
*/
public ISet<V> vertices();
/**
* Tests if vertices i and j are adjacent, returning the edge between
* them if so.
*
* @throws IllegalArgumentException if i or j are not vertices in the graph.
* @return The edge from i to j if it exists in the graph;
* null otherwise.
*/
public E adjacent(V i, V j);
/**
* Return the neighbours of a given vertex when this graph is treated as
* DIRECTED; that is, vertices to which vertex has an outgoing edge.
*
* @param vertex The vertex the neighbours of which to return.
* @throws IllegalArgumentException if vertex is not in the graph.
* @return The set of neighbors of vertex.
*/
public ISet<V> neighbors(V vertex);
}