本文整理汇总了Java中it.unimi.dsi.webgraph.LazyIntIterator.nextInt方法的典型用法代码示例。如果您正苦于以下问题:Java LazyIntIterator.nextInt方法的具体用法?Java LazyIntIterator.nextInt怎么用?Java LazyIntIterator.nextInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.webgraph.LazyIntIterator
的用法示例。
在下文中一共展示了LazyIntIterator.nextInt方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: distancesFrom
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
private int[] distancesFrom( final ImmutableGraph graph, final int from ) {
final IntArrayFIFOQueue queue = new IntArrayFIFOQueue();
final int n = graph.numNodes();
final int[] dist = new int[ n ];
IntArrays.fill( dist, Integer.MAX_VALUE ); // Initially, all distances are infinity.
queue.enqueue( from );
dist[ from ] = 0;
LazyIntIterator successors;
while( ! queue.isEmpty() ) {
int curr = queue.dequeueInt();
successors = graph.successors( curr );
int d = graph.outdegree( curr );
while( d-- != 0 ) {
int succ = successors.nextInt();
if ( dist[ succ ] == Integer.MAX_VALUE ) {
dist[ succ ] = dist[ curr ] + 1;
queue.enqueue( succ );
}
}
}
return dist;
}
示例2: run
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
@Override
public void run() {
final IntArrayFIFOQueue queue = new IntArrayFIFOQueue();
IntArrays.fill( dists, Integer.MAX_VALUE ); // Initially, all distances are infinity.
int curr, succ;
queue.enqueue( start );
dists[ start ] = 0;
LazyIntIterator successors;
while( ! queue.isEmpty() ) {
curr = queue.dequeueInt();
successors = graph.successors( curr );
int d = graph.outdegree( curr );
while( d-- != 0 ) {
succ = successors.nextInt();
if ( dists[ succ ] == Integer.MAX_VALUE ) {
dists[ succ ] = dists[ curr ] + 1;
queue.enqueue( succ );
}
}
}
startNewThreadAfter(this);
}
示例3: getInEdges
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
@Override
public Collection<Long> getInEdges( final Integer x ) {
final int v = x.intValue();
final ObjectArrayList<Long> list = new ObjectArrayList<Long>( transpose.outdegree( v ) );
final LazyIntIterator pred = transpose.successors( v );
for( long p; ( p = pred.nextInt() ) != -1; ) list.add( Long.valueOf( p << 32 | v ) );
return list;
}
示例4: getOutEdges
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
@Override
public Collection<Long> getOutEdges( final Integer x ) {
final int v = x.intValue();
final ObjectArrayList<Long> list = new ObjectArrayList<Long>( graph.outdegree( v ) );
final LazyIntIterator succ = graph.successors( v );
final long nodeShifted = (long)v << 32;
for( int s; ( s = succ.nextInt() ) != -1; ) list.add( Long.valueOf( nodeShifted | s ) );
return list;
}
示例5: degree
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
@Override
public int degree( final Integer x ) {
final int v = x.intValue();
int self = 0;
final LazyIntIterator succ = graph.successors( v );
for( int s; ( s = succ.nextInt() ) != -1; ) if ( s == v ) self++;
return graph.outdegree( v ) + ( transpose.outdegree( v ) - self );
}
示例6: getIncidentEdges
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
@Override
public Collection<Long> getIncidentEdges( final Integer x ) {
final int v = x.intValue();
final long vShifted = (long)v << 32;
final int outdegree = graph.outdegree( v );
final int indegree = transpose.outdegree( v );
final LazyIntIterator succ = graph.successors( v );
final LazyIntIterator pred = transpose.successors( v );
final ObjectArrayList<Long> res = new ObjectArrayList<Long>( outdegree + indegree );
for( int s; ( s = succ.nextInt() ) != -1; ) res.add( Long.valueOf( vShifted | s ) );
// We do not add loops again.
for( int p; ( p = pred.nextInt() ) != -1; ) if ( p != v ) res.add( Long.valueOf( (long)p << 32 | v ) );
return res;
}
示例7: getNeighbors
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
@Override
public Collection<Integer> getNeighbors( final Integer x ) {
final int v = x.intValue();
final int outdegree = graph.outdegree( v );
final int indegree = transpose.outdegree( v );
final LazyIntIterator succ = graph.successors( v );
final LazyIntIterator pred = transpose.successors( v );
final ObjectOpenHashSet<Integer> res = new ObjectOpenHashSet<Integer>( outdegree + indegree );
for( int s; ( s = succ.nextInt() ) != -1; ) res.add( Integer.valueOf( s ) );
for( int p; ( p = pred.nextInt() ) != -1; ) res.add( Integer.valueOf( p ) );
return res;
}
示例8: isNeighbor
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
@Override
public boolean isNeighbor( final Integer x, final Integer y ) {
final int v = x.intValue();
final int w = y.intValue();
final LazyIntIterator succ = graph.successors( v );
for( int s; ( s = succ.nextInt() ) != -1; ) if ( s == w ) return true;
final LazyIntIterator pred = transpose.successors( v );
for( int p; ( p = pred.nextInt() ) != -1; ) if ( p == w ) return true;
return false;
}
示例9: visit
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
/** Visits a node.
*
* @param x the node to visit.
* @return true if <code>x</code> is a bucket.
*/
private boolean visit( final int x ) {
final int[] status = this.status;
if ( pl != null ) pl.lightUpdate();
status[ x ] = ++clock;
stack.push( x );
int d = graph.outdegree( x );
boolean noOlderNodeFound = true, isBucket = d != 0; // If we're dangling we're certainly not a bucket.
if ( d != 0 ) {
final LazyIntIterator successors = graph.successors( x );
while( d-- != 0 ) {
final int s = successors.nextInt();
// If we can reach a non-bucket or another component we are not a bucket.
if ( status[ s ] == 0 && ! visit( s ) || status[ s ] < 0 ) isBucket = false;
if ( status[ s ] > 0 && status[ s ] < status[ x ] ) {
status[ x ] = status[ s ];
noOlderNodeFound = false;
}
}
}
if ( noOlderNodeFound ) {
numberOfComponents++;
int z;
do {
z = stack.popInt();
// Component markers are -c-1, where c is the component number.
status[ z ] = -numberOfComponents;
if ( isBucket && computeBuckets ) buckets.set( z );
} while( z != x );
}
return isBucket;
}
示例10: getSuccessors
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
private static Collection<Integer> getSuccessors( final ImmutableGraph g, final int x ) {
final ObjectArrayList<Integer> list = new ObjectArrayList<Integer>( g.outdegree( x ) );
final LazyIntIterator succ = g.successors( x );
for( int s; ( s = succ.nextInt() ) != -1; ) list.add( Integer.valueOf( s ) );
return list;
}
示例11: isArc
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
public boolean isArc( final int x, final int y ) {
final LazyIntIterator succ = graph.successors( x );
for( int s; ( s = succ.nextInt() ) != -1; ) if ( s == y ) return true;
return false;
}
示例12: call
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
public Void call() {
// We cache frequently used fields.
final int[] distance = this.distance;
final IntArrayFIFOQueue queue = this.queue;
final ImmutableGraph graph = GeometricCentralities.this.graph.copy();
for( ;; ) {
final int curr = nextNode.getAndIncrement();
if ( GeometricCentralities.this.stop || curr >= graph.numNodes() ) return null;
queue.clear();
queue.enqueue( curr );
IntArrays.fill( distance, -1 );
distance[ curr ] = 0;
int reachable = 0;
while( ! queue.isEmpty() ) {
final int node = queue.dequeueInt();
reachable++;
final int d = distance[ node ] + 1;
final double hd = 1. / d;
final LazyIntIterator successors = graph.successors( node );
for( int s; ( s = successors.nextInt() ) != -1; ) {
if ( distance[ s ] == -1 ) {
queue.enqueue( s );
distance[ s ] = d;
closeness[ curr ] += d;
harmonic[ curr ] += hd;
}
}
}
if ( GeometricCentralities.this.pl != null )
synchronized ( GeometricCentralities.this.pl ) {
GeometricCentralities.this.pl.update();
}
if ( closeness[ curr ] == 0 ) lin[ curr ] = 1; // Terminal node
else {
closeness[ curr ] = 1 / closeness[ curr ];
lin[ curr ] = (double)reachable * reachable * closeness[ curr ];
}
GeometricCentralities.this.reachable[ curr ] = reachable;
}
}
示例13: run
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
public void run() {
try {
// We cache frequently used fields.
final AtomicIntegerArray marker = ParallelBreadthFirstVisit.this.marker;
final ImmutableGraph graph = ParallelBreadthFirstVisit.this.graph.copy();
final boolean parent = ParallelBreadthFirstVisit.this.parent;
for(;;) {
barrier.await();
if ( completed ) return;
final IntArrayList out = new IntArrayList();
final int first = cutPoints.getInt( cutPoints.size() - 2 );
final int last = cutPoints.getInt( cutPoints.size() - 1 );
int mark = round;
for(;;) {
// Try to get another piece of work.
final long start = first + nextPosition.getAndAdd( GRANULARITY );
if ( start >= last ) {
nextPosition.getAndAdd( -GRANULARITY );
break;
}
final int end = (int)(Math.min( last, start + GRANULARITY ) );
out.clear();
for( int pos = (int)start; pos < end; pos++ ) {
final int curr = queue.getInt( pos );
if ( parent == true ) mark = curr;
final LazyIntIterator successors = graph.successors( curr );
for( int s; ( s = successors.nextInt() ) != -1; )
if ( marker.compareAndSet( s, -1, mark ) ) out.add( s );
}
progress.addAndGet( end - (int)start );
if ( ! out.isEmpty() ) synchronized( queue ) {
queue.addAll( out );
}
}
}
}
catch( Throwable t ) {
threadThrowable = t;
}
}
示例14: testUnion
import it.unimi.dsi.webgraph.LazyIntIterator; //导入方法依赖的package包/类
@Test
public void testUnion() throws IllegalArgumentException, SecurityException, IOException {
for( int n: SIZES ) {
for( int type = 0; type < 3; type++ ) {
System.err.println( "Testing arc-labelled union type " + type + "..." );
final ImmutableGraph g = type == 0 ? ArrayListMutableGraph.newCompleteGraph( n, false ).immutableView() :
type == 1 ? ArrayListMutableGraph.newCompleteBinaryIntree( n ).immutableView() :
ArrayListMutableGraph.newCompleteBinaryOuttree( n ).immutableView();
// Now split the graph g into two (possibly non-disjoint) graphs
ArrayListMutableGraph g0mut = new ArrayListMutableGraph();
ArrayListMutableGraph g1mut = new ArrayListMutableGraph();
g0mut.addNodes( g.numNodes() ); g1mut.addNodes( g.numNodes() );
NodeIterator nit = g.nodeIterator();
while ( nit.hasNext() ) {
int from = nit.nextInt();
LazyIntIterator succ = nit.successors();
int d = nit.outdegree();
while ( d-- != 0 ) {
int to = succ.nextInt();
if ( Math.random() < .5 ) g0mut.addArc( from, to );
else if ( Math.random() < .5 ) g1mut.addArc( from, to );
else { g0mut.addArc( from, to ); g1mut.addArc( from, to ); }
}
}
ImmutableGraph g0 = g0mut.immutableView();
ImmutableGraph g1 = g1mut.immutableView();
final File basename0 = BVGraphTest.storeTempGraph( g0 );
final File basename1 = BVGraphTest.storeTempGraph( g1 );
// -1 means gamma coding
for( int width: WIDTHS ) {
final String basenameLabel0 = width == -1 ?
createGraphWithGammaLabels( basename0, g0 ) :
width < MAX_WIDTH_FOR_FIXED ? createGraphWithFixedWidthLabels( basename0, g0, width ) :
createGraphWithFixedWidthListLabels( basename0, g0, width - MAX_WIDTH_FOR_FIXED );
final String basenameLabel1 = width == -1 ?
createGraphWithGammaLabels( basename1, g1 ) :
width < MAX_WIDTH_FOR_FIXED ? createGraphWithFixedWidthLabels( basename1, g1, width ) :
createGraphWithFixedWidthListLabels( basename1, g1, width - MAX_WIDTH_FOR_FIXED );
System.err.println( "Testing arc-labelled union sequential..." );
testLabels( (ArcLabelledImmutableGraph) Transform.union( BitStreamArcLabelledImmutableGraph.loadSequential( basenameLabel0 ), BitStreamArcLabelledImmutableGraph.loadSequential( basenameLabel1 ) ), width % MAX_WIDTH_FOR_FIXED );
System.err.println( "Testing arc-labelled union offline..." );
testLabels( (ArcLabelledImmutableGraph) Transform.union( BitStreamArcLabelledImmutableGraph.loadOffline( basenameLabel0 ), BitStreamArcLabelledImmutableGraph.loadOffline( basenameLabel1 ) ), width % MAX_WIDTH_FOR_FIXED );
testLabels( (ArcLabelledImmutableGraph) Transform.union( BitStreamArcLabelledImmutableGraph.load( basenameLabel0 ), BitStreamArcLabelledImmutableGraph.load( basenameLabel1 ) ), width % MAX_WIDTH_FOR_FIXED );
new File( basenameLabel0 + ImmutableGraph.PROPERTIES_EXTENSION ).delete();
new File( basenameLabel0 + BitStreamArcLabelledImmutableGraph.LABELS_EXTENSION ).delete();
new File( basenameLabel0 + BitStreamArcLabelledImmutableGraph.LABEL_OFFSETS_EXTENSION ).delete();
new File( basenameLabel1 + ImmutableGraph.PROPERTIES_EXTENSION ).delete();
new File( basenameLabel1 + BitStreamArcLabelledImmutableGraph.LABELS_EXTENSION ).delete();
new File( basenameLabel1 + BitStreamArcLabelledImmutableGraph.LABEL_OFFSETS_EXTENSION ).delete();
}
basename0.delete();
BVGraphTest.deleteGraph( basename0 );
basename1.delete();
BVGraphTest.deleteGraph( basename1 );
}
}
}