本文整理了Java中it.unimi.dsi.Util.identity()
方法的一些代码示例,展示了Util.identity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.identity()
方法的具体详情如下:
包路径:it.unimi.dsi.Util
类名称:Util
方法名:identity
[英]Stores the identity permutation in a new array of given length.
[中]将身份置换存储在给定长度的新数组中。
代码示例来源:origin: it.unimi.dsi/dsiutils
/** Stores the identity permutation in a new array of given length.
*
* @param n the size of the array.
* @return a new array of length <code>n</code>, filled with the identity permutation.
*/
public static int[] identity(int n) {
return identity(new int[n]);
}
代码示例来源:origin: it.unimi.dsi/dsiutils
/** Stores the identity permutation in a new big array of given length.
*
* @param n the size of the array.
* @return a new array of length <code>n</code>, filled with the identity permutation.
*/
public static long[][] identity(long n) {
return identity(LongBigArrays.newBigArray(n));
}
}
代码示例来源:origin: it.unimi.dsi/webgraph
/** Returns a random permutation for a given graph.
*
* @param g an immutable graph.
* @param seed for {@link XoRoShiRo128PlusRandom}.
* @return a random permutation for the given graph
*/
public static int[] randomPermutation(final ImmutableGraph g, final long seed) {
return IntArrays.shuffle(Util.identity(g.numNodes()), new XoRoShiRo128PlusRandom(seed));
}
代码示例来源:origin: it.unimi.dsi/sux4j
/** Solves the system using lazy Gaussian elimination.
*
* <p><strong>Warning</strong>: this method is very inefficient, as it
* scans linearly the equations, builds from scratch the {@code var2Eq}
* parameter of {@link #lazyGaussianElimination(Modulo3System, int[][], int[], int[], long[])}
* and finally calls it. It should be used mainly to write unit tests.
*
* @param solution an array where the solution will be written.
* @return true if the system is solvable.
*/
public boolean lazyGaussianElimination(final long[] solution) {
final int[][] var2Eq = new int[numVars][];
final int[] d = new int[numVars];
for(final Modulo3Equation equation: equations)
for(int v = (int) equation.list.size64(); v-- != 0;)
if (equation.list.getLong(v) != 0) d[v]++;
for(int v = numVars; v-- != 0;) var2Eq[v] = new int[d[v]];
Arrays.fill(d, 0);
final long[] c = new long[equations.size()];
for(int e = 0; e < equations.size(); e++) {
c[e] = equations.get(e).c;
final LongBigList list = equations.get(e).list;
for(int v = (int) list.size64(); v-- != 0;)
if (list.getLong(v) != 0) var2Eq[v][d[v]++] = e;
}
return lazyGaussianElimination(this, var2Eq, c, Util.identity(numVars), solution);
}
代码示例来源:origin: it.unimi.dsi/sux4j
/** Solves the system using lazy Gaussian elimination.
*
* <p><strong>Warning</strong>: this method is very inefficient, as it
* scans linearly the equations, builds from scratch the {@code var2Eq}
* parameter of {@link #lazyGaussianElimination(Modulo2System, int[][], long[], int[], long[])},
* and finally calls it. It should be used mainly to write unit tests.
*
* @param solution an array where the solution will be written.
* @return true if the system is solvable.
*/
public boolean lazyGaussianElimination(final long[] solution) {
final int[][] var2Eq = new int[numVars][];
final int[] d = new int[numVars];
for(final Modulo2Equation equation: equations)
for(int v = (int)equation.bitVector.length(); v-- != 0;)
if (equation.bitVector.getBoolean(v)) d[v]++;
for(int v = numVars; v-- != 0;) var2Eq[v] = new int[d[v]];
Arrays.fill(d, 0);
final long[] c = new long[equations.size()];
for(int e = 0; e < equations.size(); e++) {
c[e] = equations.get(e).c;
final LongArrayBitVector bitVector = equations.get(e).bitVector;
for(int v = (int)bitVector.length(); v-- != 0;)
if (bitVector.getBoolean(v)) var2Eq[v][d[v]++] = e;
}
return lazyGaussianElimination(this, var2Eq, c, Util.identity(numVars), solution);
}
代码示例来源:origin: it.unimi.dsi/webgraph
/** Renumbers by decreasing size the components of this set.
*
* <p>After a call to this method, both the internal status of this class and the argument
* array are permuted so that the sizes of strongly connected components are decreasing
* in the component index.
*
* @param size the components sizes, as returned by {@link #computeSizes()}.
*/
public void sortBySize(final int[] size) {
final int[] perm = Util.identity(size.length);
IntArrays.parallelRadixSortIndirect(perm, size, false);
IntArrays.reverse(perm);
final int[] copy = size.clone();
for (int i = size.length; i-- != 0;) size[i] = copy[perm[i]];
Util.invertPermutationInPlace(perm);
for(int i = component.length; i-- != 0;) component[i] = perm[component[i]];
}
代码示例来源:origin: it.unimi.dsi/webgraph
/**
* Renumbers by decreasing size the components of this set.
*
* <p>After a call to this method, both the internal status of this class and the argument array
* are permuted so that the sizes of connected components are decreasing in the component index.
*
* @param size the components sizes, as returned by {@link #computeSizes()}.
*/
public void sortBySize(final int[] size) {
final int[] perm = Util.identity(size.length);
IntArrays.parallelRadixSortIndirect(perm, size, false);
IntArrays.reverse(perm);
final int[] copy = size.clone();
for (int i = size.length; i-- != 0;)
size[i] = copy[perm[i]];
Util.invertPermutationInPlace(perm);
for (int i = component.length; i-- != 0;)
component[i] = perm[component[i]];
}
代码示例来源:origin: it.unimi.dsi/sux4j
if (! Modulo2System.lazyGaussianElimination(vertex2Edge, c, Util.identity(numVertices), solution)) {
unsolvable++;
if (LOGGER.isDebugEnabled()) LOGGER.debug("System is unsolvable");
代码示例来源:origin: it.unimi.di/mg4j
/** Creates an object ready for solving queries.
*
* @param parser the parser to be used when solving queries.
* @param indexMap the map from index alias to indices.
* @param graph the graph whence we are going to extract subgraphs.
* @param grapht the transpose graph, only needed if <code>maxIn</code> or <code>maxOut</code> are positive and finite.
* @param maxIn how many nodes should be taken (at most) from the in-neighborhood.
* @param maxOut how many nodes should be taken (at most) from the out-neighborhood.
* @param random the random number generator to be used for selecting neighbors.
*/
public GraphFromQuery( final SimpleParser parser, final Object2ReferenceLinkedOpenHashMap<String,Index> indexMap,
final ImmutableGraph graph, final ImmutableGraph grapht,
final int maxIn, final int maxOut, final Random random ) {
this.parser = parser;
this.graph = graph;
this.grapht = grapht;
this.maxIn = maxIn;
this.maxOut = maxOut;
int n = graph.numNodes();
if ( maxIn > 0 && maxIn < Integer.MAX_VALUE || maxOut > 0 && maxOut < Integer.MAX_VALUE ) {
nodePermutation = Util.identity( n );
IntArrays.shuffle( nodePermutation, random );
} else nodePermutation = null;
documentIteratorBuilderVisitor = new DocumentIteratorBuilderVisitor( indexMap, indexMap.get( parser.defaultIndex ), Integer.MAX_VALUE );
}
代码示例来源:origin: it.unimi.dsi/sux4j
if (! Modulo2System.lazyGaussianElimination(vertex2Edge, c, Util.identity(numVertices), solution)) {
unsolvable++;
if (LOGGER.isDebugEnabled()) LOGGER.debug("System is unsolvable");
代码示例来源:origin: it.unimi.dsi/sux4j
if (!Modulo2System.lazyGaussianElimination(vertex2Edge, c.clone(), Util.identity(maxNumVar), solution)) {
unsolvable++;
if (LOGGER.isDebugEnabled()) LOGGER.debug("System is unsolvable");
代码示例来源:origin: it.unimi.dsi/sux4j
if (! Modulo2System.lazyGaussianElimination(vertex2Edge, c, Util.identity(numVertices), solution)) {
unsolvable++;
if (LOGGER.isDebugEnabled()) LOGGER.debug("System is unsolvable");
代码示例来源:origin: it.unimi.dsi/sux4j
final int[] t = Util.identity(numVars);
final int[] u = new int[t.length];
final int[] count = new int[numEquations + 1]; // CountSort
代码示例来源:origin: it.unimi.dsi/sux4j
final int[] perm = Util.identity(bucket.length);
IntArrays.quickSort(perm, (a0, a1) -> Integer.compare(bucket[a1].size(), bucket[a0].size()));
内容来源于网络,如有侵权,请联系作者删除!