Skip to content

Instantly share code, notes, and snippets.

@flashpixx
Created November 28, 2017 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flashpixx/cb237d2251382acd3d5b64ac8d93041d to your computer and use it in GitHub Desktop.
Save flashpixx/cb237d2251382acd3d5b64ac8d93041d to your computer and use it in GitHub Desktop.
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