sliceutils

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 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 Intersect

func Intersect(slice1, slice2 []int) []int

This function returns the intersection of two slices of ints, considered as sets (i.e. it is the slice of the values that are present in both slices)

func Jacquard

func Jacquard(slice1, slice2 []int) float64

This function returns the jacquard similarity between two slices of ints, considered as sets (i.e. it is the size of the intersection divided by the size of the union)

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 SortIndicesByValues

func SortIndicesByValues(values []float64) []int

sortIndicesByValues returns indices sorted by their corresponding values in ascending order

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.

func Union

func Union(slice1, slice2 []int) []int

This function returns the union of two slices of ints, considered as sets (i.e. it is the slice of the values that are present in at least one of the slices)

func UnionStr

func UnionStr(slice1, slice2 []string) []string

This function returns the union of two slices of ints, considered as sets (i.e. it is the slice of the values that are present in at least one of the slices)

Types

This section is empty.

Jump to

Keyboard shortcuts

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