it.unimi.dsi.webgraph.LazyIntIterator Java Examples
The following examples show how to use
it.unimi.dsi.webgraph.LazyIntIterator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlobalVisitStats.java From fasten with Apache License 2.0 | 6 votes |
public static int reachable(final ImmutableGraph graph, final int startingNode) { final int n = graph.numNodes(); final boolean[] known = new boolean[n]; final IntArrayFIFOQueue queue = new IntArrayFIFOQueue(); queue.enqueue(startingNode); known[startingNode] = true; int visited = 0; while (!queue.isEmpty()) { final int currentNode = queue.dequeueInt(); visited++; final LazyIntIterator iterator = graph.successors(currentNode); for (int succ; (succ = iterator.nextInt()) != -1;) { if (!known[succ]) { known[succ] = true; queue.enqueue(succ); } } } return visited; }
Example #2
Source File: CallGraphGenerator.java From fasten with Apache License 2.0 | 6 votes |
/** Given <code>g</code>, returns a Fenwick tree for the nodes of <code>g</code> whose counter number <code>i+1</code> corresponds to node <code>i</code> * and it is initialized to <code>d</code> or to <code>D-d+1</code> (the latter iff <code>reverse</code> is true), * where <code>D</code> is the maximum indegree in <code>g</code>, and <code>d</code> is <code>i</code>'s indegree. * * @param g a graph. * @param reverse if true, we generate the <em>reverse</em> distribution. * @return a Fenwick tree as above. */ public static FenwickTree getPreferentialDistribution(final ImmutableGraph g, final boolean reverse) { final int n = g.numNodes(); final int[] indegree = new int[n]; int maxIndegree = 0; final NodeIterator nodeIterator = g.nodeIterator(); while (nodeIterator.hasNext()) { nodeIterator.nextInt(); final LazyIntIterator successors = nodeIterator.successors(); int target; while ((target = successors.nextInt()) >= 0) { indegree[target]++; if (indegree[target] > maxIndegree) maxIndegree = indegree[target]; } } final FenwickTree t = new FenwickTree(n); for (int i = 0; i < indegree.length; i++) t.incrementCount(i + 1, reverse? maxIndegree - indegree[i] + 1 : indegree[i]); return t; }
Example #3
Source File: VisitStats.java From fasten with Apache License 2.0 | 6 votes |
public static int reachable(final ImmutableGraph graph, final int startingNode) { final int n = graph.numNodes(); final boolean[] known = new boolean[n]; final IntArrayFIFOQueue queue = new IntArrayFIFOQueue(); queue.enqueue(startingNode); known[startingNode] = true; int visited = 0; while (!queue.isEmpty()) { final int currentNode = queue.dequeueInt(); visited++; final LazyIntIterator iterator = graph.successors(currentNode); for (int succ; (succ = iterator.nextInt()) != -1;) { if (!known[succ]) { known[succ] = true; queue.enqueue(succ); } } } return visited; }
Example #4
Source File: InGraphArray.java From tagme with Apache License 2.0 | 6 votes |
@Override protected int[][] parseSet() throws IOException { ImmutableGraph in_graph = WikiGraphs.get(lang, IndexType.IN_GRAPH); int[][] arrayGraph = new int[in_graph.numNodes()][]; for(int i=0; i<arrayGraph.length; i++) { int i_deg = in_graph.outdegree(i); if (i_deg > 0){ arrayGraph[i] = new int[i_deg]; LazyIntIterator iter = in_graph.successors(i); for (int j=0; j<arrayGraph[i].length; j++) arrayGraph[i][j] = iter.nextInt(); } } return arrayGraph; }
Example #5
Source File: KnowledgeBase.java From fasten with Apache License 2.0 | 5 votes |
@Override public String toString() { final StringBuilder b = new StringBuilder(); final CallGraphData callGraphData = callGraphData(); for (final NodeIterator nodeIterator = callGraphData.graph.nodeIterator(); nodeIterator.hasNext();) { final FastenURI u = gid2URI(callGraphData.LID2GID[nodeIterator.nextInt()]); final LazyIntIterator successors = nodeIterator.successors(); for (int s; (s = successors.nextInt()) != -1;) b.append(u).append('\t').append(gid2URI(callGraphData.LID2GID[s])).append('\n'); } return b.toString(); }