V
- the vertex typeE
- the edge typepublic class NeighborCache<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.
The cache also keeps track of successors and predecessors for each vertex. This means that the result of the union of calling predecessorsOf(v) and successorsOf(v) is equal to the result of calling neighborsOf(v) for a given vertex v.
Constructor and Description |
---|
NeighborCache(Graph<V,E> graph)
Constructor
|
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 unique neighbors of the given vertex if it exists in the cache, otherwise it is
initialized.
|
Set<V> |
predecessorsOf(V v)
Returns the unique predecessors of the given vertex if it exists in the cache, otherwise it
is initialized.
|
Set<V> |
successorsOf(V v)
Returns the unique successors of the given vertex if it exists in the cache, otherwise it is
initialized.
|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
edgeWeightUpdated
public NeighborCache(Graph<V,E> graph)
graph
- the input graphNullPointerException
- if the input graph is nullpublic Set<V> predecessorsOf(V v)
v
- the given vertexpublic Set<V> successorsOf(V v)
v
- the given vertexpublic Set<V> neighborsOf(V v)
v
- the given vertexpublic List<V> neighborListOf(V v)
neighborsOf(V)
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.public void edgeRemoved(GraphEdgeChangeEvent<V,E> e)
GraphListener
edgeRemoved
in interface GraphListener<V,E>
e
- the edge event.public void vertexAdded(GraphVertexChangeEvent<V> e)
VertexSetListener
vertexAdded
in interface VertexSetListener<V>
e
- the vertex event.public void vertexRemoved(GraphVertexChangeEvent<V> e)
VertexSetListener
vertexRemoved
in interface VertexSetListener<V>
e
- the vertex event.Copyright © 2018. All rights reserved.