本文整理汇总了Java中it.unimi.dsi.fastutil.ints.IntArrays类的典型用法代码示例。如果您正苦于以下问题:Java IntArrays类的具体用法?Java IntArrays怎么用?Java IntArrays使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IntArrays类属于it.unimi.dsi.fastutil.ints包,在下文中一共展示了IntArrays类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HdfsBVGraphNodeIterator
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
private HdfsBVGraphNodeIterator( final int from, final int upperBound, final InputBitStream ibs, final int[][] window, final int[] outd ) throws IOException {
if ( from < 0 || from > n ) throw new IllegalArgumentException( "Node index out of range: " + from );
this.from = from;
this.ibs = ibs == null ? new InputBitStream(openFile(basename + GRAPH_EXTENSION), 0 ) : ibs;
if ( window != null ) {
for ( int i = 0; i < window.length; i++ ) System.arraycopy( window[ i ], 0, this.window[ i ] = IntArrays.grow( this.window[ i ], outd[ i ], 0 ), 0, outd[ i ] );
System.arraycopy( outd, 0, this.outd, 0, outd.length );
} else if ( from != 0 ) {
int pos;
for( int i = 1; i < Math.min( from + 1, cyclicBufferSize ); i++ ) {
pos = ( from - i + cyclicBufferSize ) % cyclicBufferSize;
this.outd[ pos ] = HdfsBVGraph.this.outdegreeInternal( from - i );
System.arraycopy( successorArray( from - i ), 0, this.window[ pos ] = IntArrays.grow( this.window[ pos ], this.outd[ pos ], 0 ), 0, this.outd[ pos ] );
}
this.ibs.position( offsets.getLong( from ) ); // We must fix the bit stream position so that we are *before* the outdegree.
}
curr = from - 1;
this.upperBound = upperBound;
}
示例2: testBlocking
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
@Test
public void testBlocking() throws InterruptedException {
for(final int size: new int[] { 10, 100, 128, 256 }) {
for(final int d: new int[] { 1, 2, 3, 4 }) {
final ReorderingBlockingQueue<Integer> q = new ReorderingBlockingQueue<>(size / d);
final int[] perm = Util.identity(size);
IntArrays.shuffle(perm, new XoRoShiRo128PlusRandom());
for(int i = perm.length; i-- != 0;) {
final int t = perm[i];
new Thread() {
@Override
public void run() {
try {
q.put(Integer.valueOf(t), t);
}
catch (final InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}.start();
}
for(int i = 0; i < perm.length; i++) assertEquals(i, q.take().intValue());
assertEquals(0, q.size());
}
}
}
示例3: prep_uncovered_zeros
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
private List<ME> prep_uncovered_zeros(int[] col_indexes, int[] row_indexes) {
for(int i = 0; i < col_indexes.length; i++) {
col_indexes[i] = i;
}
for(int i = 0; i < row_indexes.length; i++) {
row_indexes[i] = i;
}
IntArrays.quickSort(row_indexes, new Compare(row_mod, 1));
IntArrays.quickSort(col_indexes, new Compare(col_mod, -1));
List<ME> zeros = new ArrayList<>();
for(ME me : matrix.all()) {
if(cost(me) == 0) {
zeros.add(me);
}
}
return zeros;
}
示例4: learnNPassShuffled
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
public void learnNPassShuffled(int n) throws ReflectiveOperationException, IOException {
pl.info = classifier.shortStats();
pl.expectedUpdates = graph.numArcs() * 2 * n;
pl.start();
for (int pass = 0; pass < n; pass++) {
LOGGER.info("Starting learning pass #"+(pass+1)+"...");
int[] nodes = MathArrays.natural(numNodes);
nodes = IntArrays.shuffle(nodes, rnd);
for (int node : nodes)
learnNode(node, new IntOpenHashSet(
graph.successorArray(node), 0, graph.outdegree(node)
));
save(pass+1);
}
pl.done();
}
示例5: createTestingSet
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
public int[] createTestingSet(int numOfSamples) {
numOfSamples = Math.min(numOfSamples, numNodes);
if (verbose) LOGGER.info("Creating test set with "+numOfSamples+" nodes...");
if (numOfSamples >= (numNodes/2)) {
final Random rnd = RandomSingleton.get();
int[] samples = MathArrays.natural(numNodes);
IntArrays.shuffle(samples, rnd);
return IntArrays.trim(samples, numOfSamples);
} else {
IntSet set = new IntOpenHashSet();
while (set.size() < numOfSamples) {
set.add(rnd.nextInt(numNodes));
}
int[] r = set.toIntArray();
return r;
}
}
示例6: indirectSort
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
/**
* Indirect sort descendingly.
*
* @param cnt Count array
* @return Permutation, largest first
*/
private static int[] indirectSort(long[] cnt) {
int[] tmp = new int[cnt.length];
for(int i = 0; i < tmp.length; i++) {
tmp[i] = i;
}
// Indirect sort, descending (no need to sort 0):
IntArrays.quickSort(tmp, 1, tmp.length, new AbstractIntComparator() {
private static final long serialVersionUID = 1L;
@Override
public int compare(int k1, int k2) {
return Long.compare(cnt[k2], cnt[k1]);
}
});
return tmp;
}
示例7: 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;
}
示例8: BVGraphNodeIterator
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
public BVGraphNodeIterator( final InputBitStream ibs, final int from ) throws IOException {
if ( from < 0 || from > n ) throw new IllegalArgumentException( "Node index out of range: " + from );
this.from = from;
this.ibs = ibs;
if ( from != 0 ) {
if ( offsetType <= 0 ) throw new IllegalStateException( "You cannot iterate from a chosen node without offsets" );
int pos;
for( int i = 1; i < Math.min( from + 1, cyclicBufferSize ); i++ ) {
pos = ( from - i + cyclicBufferSize ) % cyclicBufferSize;
outd[ pos ] = BVGraph.this.outdegreeInternal( from - i );
System.arraycopy( BVGraph.this.successorArray( from - i ), 0, window[ pos ] = IntArrays.grow( window[ pos ], outd[ pos ], 0 ), 0, outd[ pos ] );
}
ibs.position( offsets.getLong( from ) ); // We must fix the bit stream position so that we are *before* the outdegree.
}
curr = from - 1;
}
示例9: distancesFrom
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的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;
}
示例10: BottomSketch
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
public BottomSketch(String str, int nGramSize, int k, boolean doReverseCompliment)
{
int[] hashes = HashUtils.computeSequenceHashes(str, nGramSize, doReverseCompliment);
k = Math.min(k, hashes.length);
int[] perm = new int[hashes.length];
for (int iter=0; iter<hashes.length; iter++)
perm[iter] = iter;
//sort the array
IntArrays.radixSortIndirect(perm, hashes, true);
hashPositions = new int[k];
for (int iter=0; iter<k; iter++)
{
int index = perm[iter];
hashPositions[iter] = hashes[index];
}
}
示例11: visitDictionary
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
private void visitDictionary(Visitor<Text> visitor, VisitorContextImpl context
) throws IOException {
int[] keysArray = null;
if (sortKeys) {
keysArray = new int[numElements];
for (int idx = 0; idx < numElements; idx++) {
keysArray[idx] = idx + 1;
}
IntArrays.quickSort(keysArray, new TextPositionComparator());
}
for (int pos = 0; pos < numElements; pos++) {
context.setOriginalPosition(keysArray == null? pos + 1: keysArray[pos]);
visitor.visit(context);
}
keysArray = null;
}
示例12: sort
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
/**
* Given an IntArrayList object, sort it, and return an integer array, containing the sorted elements
* @param intList: the input list to be sorted
* @return a sorted integer array
*/
public static int [] sort(IntArrayList intList){
// Sort the indices and return them
int [] sorted = new int[intList.size()];
for (int i = 0; i < intList.size(); i++){
sorted[i] = intList.getInt(i);
}
IntArrays.quickSort(sorted);
return sorted;
}
示例13: testNoBlocking
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
@Test
public void testNoBlocking() throws InterruptedException {
for(final int size: new int[] { 1, 10, 100, 128, 256 }) {
final ReorderingBlockingQueue<Integer> q = new ReorderingBlockingQueue<>(size);
final int[] perm = Util.identity(size);
IntArrays.shuffle(perm, new XoRoShiRo128PlusRandom());
for(int i = perm.length; i-- != 0;) q.put(Integer.valueOf(perm[i]), perm[i]);
for(int i = 0; i < perm.length; i++) assertEquals(i, q.take().intValue());
assertEquals(0, q.size());
}
}
示例14: sortOn
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
/**
* Returns a copy of this table sorted using the given comparator
*/
public Table sortOn(IntComparator rowComparator) {
Table newTable = emptyCopy(rowCount());
int[] newRows = rows();
IntArrays.parallelQuickSort(newRows, rowComparator);
Rows.copyRowsToTable(IntArrayList.wrap(newRows), this, newTable);
return newTable;
}
示例15: HittingDistanceMinimizer
import it.unimi.dsi.fastutil.ints.IntArrays; //导入依赖的package包/类
@CommandLine(argNames={"graph", "milestones"})
public HittingDistanceMinimizer(ImmutableGraph graph, IntSet milestones) {
this.graph = Transform.transpose(graph);
this.milestones = milestones;
minMilestoneDistance = new int[graph.numNodes()];
IntArrays.fill(minMilestoneDistance, Integer.MAX_VALUE);
closestMilestone = new int[graph.numNodes()];
IntArrays.fill(closestMilestone, -1);
milestoneQueue = new IntArrayPriorityQueue(milestones.toIntArray());
runningVisitors = new ObjectOpenHashSet<Visitor>();
pl = new ProgressLogger(LOGGER, "milestones");
pl.expectedUpdates = milestones.size();
}