Created
November 28, 2017 16:43
-
-
Save flashpixx/cb237d2251382acd3d5b64ac8d93041d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.annotation.Nonnull; | |
import java.util.AbstractMap; | |
import java.util.Collections; | |
import java.util.Comparator; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
/** | |
* common functions | |
*/ | |
public final class ValueIndexSort | |
{ | |
/** | |
* defines ranking index of number | |
* | |
* @param p_data any number array | |
* @return unmodifyable index list (first index, defines the lowest element) | |
*/ | |
public static List<Integer> rankindex( @Nonnull final double[] p_data ) | |
{ | |
return Collections.unmodifiableList( | |
IntStream.range( 0, p_data.length ) | |
.parallel() | |
.boxed() | |
.map( i -> new AbstractMap.SimpleImmutableEntry<>( i, p_data[i] ) ) | |
.collect( Collectors.toList() ) | |
.parallelStream() | |
.sorted( Comparator.comparingDouble( AbstractMap.SimpleImmutableEntry::getValue ) ) | |
.map( AbstractMap.SimpleImmutableEntry::getKey ) | |
.collect( Collectors.toList() ) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment