|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jgrapht.alg.NeighborIndex<V,E>
public class NeighborIndex<V,E>
Maintains a cache of each vertex's neighbors. While lists of neighbors can be
obtained from Graphs
, they are re-calculated at each invocation by
walking a vertex's incident edges, which becomes inordinately expensive when
performed often.
Edge direction is ignored when evaluating neighbors; to take edge
direction into account when indexing neighbors, use DirectedNeighborIndex
.
A vertex's neighbors are cached the first time they are asked for (i.e. the index is built on demand). The index will only be updated automatically if it is added to the associated graph as a listener. If it is added as a listener to a graph other than the one it indexes, results are undefined.
Constructor Summary | |
---|---|
NeighborIndex(Graph<V,E> g)
Creates a neighbor index for the specified undirected graph. |
Method Summary | |
---|---|
void |
edgeAdded(GraphEdgeChangeEvent<V,E> e)
Notifies that an edge has been added to the graph. |
void |
edgeRemoved(GraphEdgeChangeEvent<V,E> e)
Notifies that an edge has been removed from the graph. |
java.util.List<V> |
neighborListOf(V v)
Returns a list of vertices which are adjacent to a specified vertex. |
java.util.Set<V> |
neighborsOf(V v)
Returns the set of vertices which are adjacent to a specified vertex. |
void |
vertexAdded(GraphVertexChangeEvent<V> e)
Notifies that a vertex has been added to the graph. |
void |
vertexRemoved(GraphVertexChangeEvent<V> e)
Notifies that a vertex has been removed from the graph. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NeighborIndex(Graph<V,E> g)
g
- the graph for which a neighbor index is to be created.Method Detail |
---|
public java.util.Set<V> neighborsOf(V v)
v
- the vertex whose neighbors are desired
public java.util.List<V> neighborListOf(V v)
neighborsOf(Object)
unless duplicate neighbors are important.
v
- the vertex whose neighbors are desired
public void edgeAdded(GraphEdgeChangeEvent<V,E> e)
GraphListener
edgeAdded
in interface GraphListener<V,E>
e
- the edge event.GraphListener.edgeAdded(GraphEdgeChangeEvent)
public void edgeRemoved(GraphEdgeChangeEvent<V,E> e)
GraphListener
edgeRemoved
in interface GraphListener<V,E>
e
- the edge event.GraphListener.edgeRemoved(GraphEdgeChangeEvent)
public void vertexAdded(GraphVertexChangeEvent<V> e)
VertexSetListener
vertexAdded
in interface VertexSetListener<V>
e
- the vertex event.VertexSetListener.vertexAdded(GraphVertexChangeEvent)
public void vertexRemoved(GraphVertexChangeEvent<V> e)
VertexSetListener
vertexRemoved
in interface VertexSetListener<V>
e
- the vertex event.VertexSetListener.vertexRemoved(GraphVertexChangeEvent)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |