V
- the graph vertex typeE
- the graph edge typepublic class NeighborIndex<V,E> extends Object implements GraphListener<V,E>
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 and Description |
---|
NeighborIndex(Graph<V,E> g)
Creates a neighbor index for the specified undirected graph.
|
Modifier and Type | Method and Description |
---|---|
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.
|
List<V> |
neighborListOf(V v)
Returns a list of vertices which are adjacent to a specified vertex.
|
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.
|
public Set<V> neighborsOf(V v)
v
- the vertex whose neighbors are desiredpublic List<V> neighborListOf(V v)
neighborsOf(Object)
unless duplicate neighbors are important.v
- the vertex whose neighbors are desiredpublic 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)
Copyright © 2017. All rights reserved.