Interface EdgeSet<V,E>
- Type Parameters:
V
- the vertices typeE
- the edges type
- All Superinterfaces:
Collection<E>
,Iterable<E>
,Set<E>
- All Known Subinterfaces:
IEdgeSet
Graph<String, Integer> g = ...;
String vertex = ...;
for (EdgeIter<String, Integer> eit = g.outEdges(vertex).iterator(); eit.hasNext();) {
Integer e = eit.next();
String u = eit.source();
String v = eit.target();
assert vertex.equals(u);
System.out.println("Out edge of " + vertex + ": " + e + "(" + u + ", " + v + ")");
}
Note that sets implementing this interface should define Object.equals(Object)
, Object.hashCode()
and
Object.toString()
compatible with the Set
interface. Namely, the above methods should not take into
account the endpoints of the edges, only the edges identifiers themselves.
- Author:
- Barak Ugav
- See Also:
-
Method Summary
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Method Details
-
iterator
Return an edge iterator that iterate over the edges in this set. -
of
Create an edge set object from a plain set of edges.A 'plain' set of edges is a set of the edges identifiers. It does not include any information about the endpoints (source and target) of each edge. This method creates an
EdgeSet
, which does contains information about the endpoints, given a plain set of edges and the graph in which the edges are defined in.The returned set is a view of the given set and graph. Namely, its updated when the original set is updated and visa vera, and the endpoints in the
EdgeSet
will be up to date with the given graph.No validation is performed to ensure that all the given edges are actually in the given graph. If this is not the case, an exception may be thrown later when the graph is queried for an edge source and target.
If
g
isIntGraph
, aIEdgeSet
is returned. In that case, prefer to passIntSet
asedges
to avoid un/boxing, or useIEdgeSet.of(IntSet, IntGraph)
instead.Usually an
EdgeSet
object is obtained via one of the method of aGraph
, and rarely a user need to a create one, but it may be used to add multiple edges to a graph using theGraph.addEdges(EdgeSet)
method. In the following snippet, a maximum cardinality matching is computed on a graph, and a new graph containing only the matching edges is created:Graph<V, E> g = ...; Set<E> matching = MatchingAlgo.newInstance().computeMaximumMatching(g, null).edges(); Graph<V,E> matchingGraph = Graph.newUndirected(); matchingGraph.addVertices(g.vertices()); matchingGraph.addEdges(EdgeSet.of(matching, g));
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
edges
- a set of edges identifiersg
- the graph in which the edges are defined in, and from which the endpoints of the edges should be retrieved- Returns:
- an
EdgeSet
with the given edges, containing the endpoints information from the graph
-
allOf
Create an edge set object of all the edges in a graph.The edge set returned by
Graph.edges()
is a 'plain' set of edges, namely it is a set of the edge identifiers themselves but does not include any information about the endpoints (source and target) of each edge. This method creates anEdgeSet
, which does contains information about the endpoints, of all the edges in a given graph.The returned set is a view of the given set and graph. Namely, its updated when the original set is updated and visa vera, and the endpoints in the
EdgeSet
will be up to date with the given graph.If
g
isIntGraph
, aIEdgeSet
is returned. In that case, prefer to passIntSet
asedges
to avoid un/boxing, or useIEdgeSet.allOf(IntGraph)
instead.Usually an
EdgeSet
object is obtained via one of the method of aGraph
, and rarely a user need to a create one, but it may be used to add multiple edges to a graph using theGraph.addEdges(EdgeSet)
method. In the following snippet, an auxillary graph is created which is a copy of an original graphg
with additional vertex connected to all the original vertices, for shortest path potential function computation (used in Johnson APSP):V auxillaryVertex = ...; Graph<V, E> auxillaryGraph = Graph.newDirected(); auxillaryGraph.addVertices(g.vertices()); auxillaryGraph.addVertex(auxillaryVertex); auxillaryGraph.addEdges(EdgeSet.allOf(g)); for (V v : g.vertices()) auxillaryGraph.addEdge(auxillaryVertex, v, ...
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- a graph- Returns:
- an
EdgeSet
of all the edges in the graph
-