Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/Neighbors.java
Show All 13 Lines | |||||
* | * | ||||
* @author The Software Heritage developers | * @author The Software Heritage developers | ||||
* @see org.softwareheritage.graph.AllowedEdges | * @see org.softwareheritage.graph.AllowedEdges | ||||
*/ | */ | ||||
public class Neighbors implements Iterable<Long> { | public class Neighbors implements Iterable<Long> { | ||||
/** Graph used to explore neighbors */ | /** Graph used to explore neighbors */ | ||||
Graph graph; | Graph graph; | ||||
/** Boolean to specify the use of the transposed graph */ | |||||
boolean useTransposed; | |||||
/** Graph edge restriction */ | /** Graph edge restriction */ | ||||
AllowedEdges edges; | AllowedEdges edges; | ||||
/** Source node from which neighbors will be listed */ | /** Source node from which neighbors will be listed */ | ||||
long srcNodeId; | long srcNodeId; | ||||
/** | /** | ||||
* Constructor. | * Constructor. | ||||
* | * | ||||
* @param graph graph used to explore neighbors | * @param graph graph used to explore neighbors | ||||
* @param useTransposed boolean value to use transposed graph | |||||
* @param edges edges allowed to be used in the graph | * @param edges edges allowed to be used in the graph | ||||
* @param srcNodeId source node from where to list neighbors | * @param srcNodeId source node from where to list neighbors | ||||
*/ | */ | ||||
public Neighbors(Graph graph, boolean useTransposed, AllowedEdges edges, long srcNodeId) { | public Neighbors(Graph graph, AllowedEdges edges, long srcNodeId) { | ||||
this.graph = graph; | this.graph = graph; | ||||
this.useTransposed = useTransposed; | |||||
this.edges = edges; | this.edges = edges; | ||||
this.srcNodeId = srcNodeId; | this.srcNodeId = srcNodeId; | ||||
} | } | ||||
@Override | @Override | ||||
public Iterator<Long> iterator() { | public Iterator<Long> iterator() { | ||||
return new NeighborsIterator(); | return new NeighborsIterator(); | ||||
} | } | ||||
/** | /** | ||||
* Inner class for {@link Neighbors} iterator. | * Inner class for {@link Neighbors} iterator. | ||||
* | * | ||||
* @author The Software Heritage developers | * @author The Software Heritage developers | ||||
*/ | */ | ||||
public class NeighborsIterator implements Iterator<Long> { | public class NeighborsIterator implements Iterator<Long> { | ||||
LazyLongIterator neighbors; | LazyLongIterator neighbors; | ||||
long nextNeighborId; | long nextNeighborId; | ||||
public NeighborsIterator() { | public NeighborsIterator() { | ||||
this.neighbors = graph.neighbors(srcNodeId, useTransposed); | this.neighbors = graph.successors(srcNodeId); | ||||
this.nextNeighborId = -1; | this.nextNeighborId = -1; | ||||
} | } | ||||
public boolean hasNext() { | public boolean hasNext() { | ||||
// Case 1: no edge restriction, bypass type checks and skip to next neighbor | // Case 1: no edge restriction, bypass type checks and skip to next neighbor | ||||
if (edges.restrictedTo == null) { | if (edges.restrictedTo == null) { | ||||
nextNeighborId = neighbors.nextLong(); | nextNeighborId = neighbors.nextLong(); | ||||
return (nextNeighborId != -1); | return (nextNeighborId != -1); | ||||
Show All 16 Lines |