本文整理了Java中it.unimi.dsi.Util.invertPermutationInPlace()
方法的一些代码示例,展示了Util.invertPermutationInPlace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.invertPermutationInPlace()
方法的具体详情如下:
包路径:it.unimi.dsi.Util
类名称:Util
方法名:invertPermutationInPlace
[英]Computes in place the inverse of a permutation expressed as an array of n distinct integers in [0 .. n).
Warning: if perm
is not a permutation, essentially anything can happen.
[中]在[0..n]中计算置换的逆,置换表示为n个不同整数的数组。
警告:如果perm
不是一个排列,基本上任何事情都可能发生。
代码示例来源: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/dsiutils
public static void main(final String[] arg) throws IOException, ClassNotFoundException, JSAPException {
SimpleJSAP jsap = new SimpleJSAP(PermutedFrontCodedStringList.class.getName(), "Builds a permuted front-coded list of strings using a given front-coded string list and a permutation (either in text or binary format).",
new Parameter[] {
new Switch("invert", 'i', "invert", "Invert permutation before creating the permuted list."),
new Switch("text", 't', "text", "The permutation is a text file."),
new UnflaggedOption("list", JSAP.STRING_PARSER, JSAP.REQUIRED, "A front-coded string list."),
new UnflaggedOption("permutation", JSAP.STRING_PARSER, JSAP.REQUIRED, "A permutation for the indices of the list (in DataInput format, unless you specify --text)."),
new UnflaggedOption("permutedList", JSAP.STRING_PARSER, JSAP.REQUIRED, "A the filename for the resulting permuted list."),
});
JSAPResult jsapResult = jsap.parse(arg);
if (jsap.messagePrinted()) return;
final String permutationFile = jsapResult.getString("permutation");
final int[] permutation = jsapResult.userSpecified("text")
? IntIterators.unwrap(TextIO.asIntIterator(permutationFile))
: BinIO.loadInts(permutationFile);
if (jsapResult.getBoolean("invert")) Util.invertPermutationInPlace(permutation);
BinIO.storeObject(
new PermutedFrontCodedStringList((FrontCodedStringList)BinIO.loadObject(jsapResult.getString("list")), permutation),
jsapResult.getString("permutedList")
);
}
}
内容来源于网络,如有侵权,请联系作者删除!