sort

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2020 License: GPL-2.0 Imports: 1 Imported by: 0

Documentation

Overview

This package provides a few functions to sort int arrays.

  • Sort by values of another array
  • Return permutation allowing to sort input array (like R order() function)

Inspired from https://stackoverflow.com/questions/42707252/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OrderInt

func OrderInt(values []int, decreasing bool) []int

Returns reordered indices (permutation) by values (like order() R function). It may be in decreasing order.

Example:

input := []int{10,20,30,80,50}
output := OrderInt(input) // {0,1,2,4,3}
// To iterate over the sorted array :
for _,ord := range output {
    input[ord]
}

func SortIntBy

func SortIntBy(toSort []int, byValues []int, decreasing bool)

Sorts "toSort" array according to "byValues" Array.

  • "toSort" array is modified after the function.
  • "byValues" array is not modified.

The sort may be in decreasing order.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL