本文整理汇总了Java中it.unimi.dsi.fastutil.ints.IntArrays.grow方法的典型用法代码示例。如果您正苦于以下问题:Java IntArrays.grow方法的具体用法?Java IntArrays.grow怎么用?Java IntArrays.grow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.ints.IntArrays
的用法示例。
在下文中一共展示了IntArrays.grow方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillCache
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
private void fillCache( int x ) {
if ( x == cachedNode ) return;
MergedIntIterator merge = new MergedIntIterator( x < n0? g0.successors( x ) : LazyIntIterators.EMPTY_ITERATOR, x < n1? g1.successors( x ) : LazyIntIterators.EMPTY_ITERATOR );
outdegree = 0;
cache = new int[ INITIAL_ARRAY_SIZE ];
outdegree += LazyIntIterators.unwrap( merge, cache );
int upto, t;
while ( ( t = merge.nextInt() ) != -1 ) {
upto = cache.length;
cache = IntArrays.grow( cache, upto + 1 );
cache[ upto++] = t;
outdegree++;
outdegree += LazyIntIterators.unwrap( merge, cache, upto, cache.length - upto );
}
cachedNode = x;
}
示例2: unwrap
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
/** Unwraps the elements returned by a lazy iterator into a new array.
*
* <p>If you need the resulting array to contain the
* elements returned by <code>lazyIntIterator</code>, but some more elements set to zero
* would cause no harm, consider using {@link #unwrapLoosely(LazyIntIterator)}, which
* usually avoids a final call to {@link IntArrays#trim(int[], int)}.
*
* @param lazyIntIterator a lazy integer iterator.
* @return an array containing the elements returned by <code>lazyIntIterator</code>.
* @see #unwrapLoosely(LazyIntIterator)
*/
public static int[] unwrap( final LazyIntIterator lazyIntIterator ) {
int array[] = new int[ 16 ];
int j = 0, t;
while( ( t = lazyIntIterator.nextInt() ) != -1 ) {
if ( j == array.length ) array = IntArrays.grow( array, j + 1 );
array[ j++ ] = t;
}
return IntArrays.trim( array, j );
}
示例3: nodeIterator
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
public NodeIterator nodeIterator() {
return new NodeIterator() {
private XorShift1024StarRandom random = new XorShift1024StarRandom( seed );
private Binomial bg = new Binomial( n - ( loops ? 0 : 1 ), p, new RandomEngine() {
private static final long serialVersionUID = 1L;
@Override
public int nextInt() {
return random.nextInt();
}
});
private int outdegree;
private int curr = -1;
private IntOpenHashSet successors = new IntOpenHashSet();
private int[] successorArray = new int[ 1024 ];
public boolean hasNext() {
return curr < n - 1;
}
@Override
public int nextInt() {
curr++;
outdegree = bg.nextInt();
successors.clear();
if ( ! loops ) successors.add( curr );
for( int i = 0; i < outdegree; i++ ) while( ! successors.add( random.nextInt( n ) ) );
if ( ! loops ) successors.remove( curr );
successorArray = IntArrays.grow( successorArray, outdegree );
successors.toIntArray( successorArray );
IntArrays.quickSort( successorArray, 0, outdegree );
return curr;
}
@Override
public int outdegree() {
return outdegree;
}
@Override
public int[] successorArray() {
return successorArray;
}
};
}
示例4: generate
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
/** Generates an Erdős–Rényi graph with the specified seed.
*
* <p>This method exists only for backward compatibility.
*
* @param seed the seed for random generation.
* @return the generated graph.
* @deprecated An instance of this class is already an {@link ImmutableSequentialGraph}.
*/
@Deprecated
public ImmutableSequentialGraph generate( final long seed ) {
LOGGER.debug( "Generating with probability " + p );
return new ImmutableSequentialGraph() {
@Override
public int numNodes() {
return n;
}
@Override
public ImmutableSequentialGraph copy() {
return this;
}
public NodeIterator nodeIterator() {
return new NodeIterator() {
private XorShift1024StarRandom random = new XorShift1024StarRandom( seed );
private Binomial bg = new Binomial( n - ( loops ? 0 : 1 ), p, new RandomEngine() {
private static final long serialVersionUID = 1L;
@Override
public int nextInt() {
return random.nextInt();
}
});
private int outdegree;
private int curr = -1;
private IntOpenHashSet successors = new IntOpenHashSet();
private int[] successorArray = new int[ 1024 ];
public boolean hasNext() {
return curr < n - 1;
}
@Override
public int nextInt() {
curr++;
outdegree = bg.nextInt();
successors.clear();
if ( ! loops ) successors.add( curr );
for( int i = 0; i < outdegree; i++ ) while( ! successors.add( random.nextInt( n ) ) );
if ( ! loops ) successors.remove( curr );
successorArray = IntArrays.grow( successorArray, outdegree );
successors.toIntArray( successorArray );
IntArrays.quickSort( successorArray, 0, outdegree );
return curr;
}
@Override
public int outdegree() {
return outdegree;
}
@Override
public int[] successorArray() {
return successorArray;
}
};
}
};
}
示例5: nodeIterator
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
public NodeIterator nodeIterator( final int from ) {
/** The invariant that we are assuming here is the following: at any time, <code>node</code> is the next (subgraph)
* node to be returned by {@link #nextInt()}. This variable contain sensible data
* only when <code>node</code> < <code>subgraphSize</code>. Moreover, if outdegree >= 0 then it is
* the outdegree of <code>node</code>-1, and <code>successorsCache</code> contains the successors. */
// TODO: decide for a strategy. Note that super.nodeIterator is very dangerous, as it uses random access.
return supergraph.randomAccess() && subgraphSize < supergraphNumNodes / 8 ? super.nodeIterator( from ) :
new NodeIterator() {
/** The current node (the next to be returned. */
int node = from;
/** This array caches the successors of the node that was returned last (<code>from</code>-1). */
int[] successorsCache = IntArrays.EMPTY_ARRAY;
/** The outdegree of the node that was returned last (<code>node</code>-1). */
int outdegree = -1;
final NodeIterator supergraphNodeIterator = supergraph.nodeIterator( subgraphNode[ from ] );
public int nextInt() {
if ( ! hasNext() ) throw new java.util.NoSuchElementException();
if ( node != from ) supergraphNodeIterator.skip( subgraphNode[ node ] - subgraphNode[ node - 1 ] );
else supergraphNodeIterator.nextInt();
outdegree = -1;
return node++;
}
public boolean hasNext() {
return ( node < subgraphSize );
}
private void unwrapSuccessors() {
int start = 0, done;
final LazyIntIterator i = ImmutableSubgraph.this.successors( node - 1, supergraphNodeIterator.successors() );
// ALERT: we removed i.hasNext() at the end of this check, but it is not necessary
while( ( done = LazyIntIterators.unwrap( i, successorsCache, start, successorsCache.length - start ) ) == successorsCache.length - start ) {
start = successorsCache.length;
successorsCache = IntArrays.grow( successorsCache, successorsCache.length + 1 );
}
outdegree = start + done;
}
public int[] successorArray() {
if ( node == from ) throw new IllegalStateException();
if ( outdegree == -1 ) unwrapSuccessors();
return successorsCache;
}
public LazyIntIterator successors() {
if ( node == from ) throw new IllegalStateException();
if ( outdegree == -1 ) unwrapSuccessors();
return LazyIntIterators.wrap( successorsCache, outdegree );
}
public int outdegree() {
if ( node == from ) throw new IllegalStateException();
if ( outdegree == -1 ) unwrapSuccessors();
return outdegree;
}
};
}
示例6: nodeIterator
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
public NodeIterator nodeIterator( final int from ) {
return new NodeIterator() {
/** If outdegree is nonnegative, the successors of the current node (this array may be, however, larger). */
@SuppressWarnings("hiding")
private int cache[] = IntArrays.EMPTY_ARRAY;
/** The outdegree of the current node, or -1 if the successor array for the current node has not been computed yet. */
@SuppressWarnings("hiding")
private int outdegree = -1;
private NodeIterator i0 = from < n0? g0.nodeIterator( from ) : null;
private NodeIterator i1 = from < n1? g1.nodeIterator( from ) : null;
public boolean hasNext() {
return i0 != null && i0.hasNext() || i1 != null && i1.hasNext();
}
public int nextInt() {
if ( ! hasNext() ) throw new java.util.NoSuchElementException();
outdegree = -1;
int result = -1;
if ( i0 != null ) {
if ( i0.hasNext() ) result = i0.nextInt();
else i0 = null;
}
if ( i1 != null ) {
if ( i1.hasNext() ) result = i1.nextInt();
else i1 = null;
}
return result;
}
public int[] successorArray() {
if ( outdegree != -1 ) return cache;
if ( i0 == null ) {
outdegree = i1.outdegree();
return cache = i1.successorArray();
}
if ( i1 == null ) {
outdegree = i0.outdegree();
return cache = i0.successorArray();
}
MergedIntIterator merge = new MergedIntIterator( i0.successors(), i1.successors() );
outdegree = LazyIntIterators.unwrap( merge, cache );
int upto, t;
while ( ( t = merge.nextInt() ) != -1 ) {
upto = cache.length;
cache = IntArrays.grow( cache, upto + 1 );
cache[ upto++ ] = t;
outdegree++;
outdegree += LazyIntIterators.unwrap( merge, cache, upto, cache.length - upto );
}
return cache;
}
public int outdegree() {
successorArray(); // So that the cache is filled up
return outdegree;
}
};
}
示例7: unwrapLoosely
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
/** Unwraps the elements returned by a lazy iterator into a new array that can contain additional entries set to zero.
*
* <p>If you need the resulting array to contain <em>exactly</em> the
* elements returned by <code>lazyIntIterator</code>, consider using {@link #unwrap(LazyIntIterator)}, but this
* method avoids a final call to {@link IntArrays#trim(int[], int)}.
*
* @param lazyIntIterator a lazy integer iterator.
* @return an array containing the elements returned by <code>lazyIntIterator</code>; note
* that in general it might contains some final zeroes beyond the elements returned by <code>lazyIntIterator</code>,
* so the number of elements actually written into <code>array</code> must be known externally.
* @see #unwrap(LazyIntIterator)
*/
public static int[] unwrapLoosely( final LazyIntIterator lazyIntIterator ) {
int array[] = new int[ 16 ];
int j = 0, t;
while( ( t = lazyIntIterator.nextInt() ) != -1 ) {
if ( j == array.length ) array = IntArrays.grow( array, j + 1 );
array[ j++ ] = t;
}
return array;
}