uniq

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 2 Imported by: 2

README

uniq

Go Reference Build Status codecov Go Report Card GitHub go.mod Go version GitHub tag (latest by date)

Sort and deduplicate data.

Example

package main

import (
	"fmt"
	"sort"

	"github.com/gochore/uniq"
)

func main() {
	ints1 := []int{1, 2, 1, 2, 4, 4, 4, 3, 3}
	ints2 := make([]int, len(ints1))
	copy(ints2, ints1)

	fmt.Println(ints1)
	// [1 2 1 2 4 4 4 3 3]
	sort.Ints(ints1)
	fmt.Println(ints1)
	// [1 1 2 2 3 3 4 4 4]
	ints2 = ints2[:uniq.Ints(ints2)]
	fmt.Println(ints2)
	// [1 2 3 4]

	kvs1 := []KV{{"a", 5}, {"b", 2}, {"a", 5}, {"b", 4}, {"c", 9}}
	less1 := func(i, j int) bool {
		return kvs1[i].K < kvs1[j].K
	}
	kvs2 := make([]KV, len(kvs1))
	copy(kvs2, kvs1)
	less2 := func(i, j int) bool {
		return kvs2[i].K < kvs2[j].K || kvs2[i].K == kvs2[j].K && kvs2[i].V < kvs2[j].V
	}
	fmt.Println(kvs1)
	// [{a 5} {b 2} {a 5} {b 4} {c 9}]
	sort.Slice(kvs1, less1)
	fmt.Println(kvs1)
	// [{a 5} {a 5} {b 2} {b 4} {c 9}]
	kvs2 = kvs2[:uniq.Slice(kvs2, less2)]
	fmt.Println(kvs2)
	// [{a 5} {b 2} {b 4} {c 9}]
}

type KV struct {
	K string
	V int
}

Document

func Float64s
func Float64s(s []float64) int

Float64s sorts and deduplicates a slice of float64s in increasing order (not-a-number values are treated as less than other values).

func Float64sAreSorted
func Float64sAreSorted(a []float64) bool

Float64sAreSorted tests whether a slice of float64s is sorted and deduplicated in increasing order (not-a-number values are treated as less than other values).

func Ints
func Ints(s []int) int

Ints sorts and deduplicates a slice of ints in increasing order.

func IntsAreSorted
func IntsAreSorted(a []int) bool

IntsAreSorted tests whether a slice of ints is sorted and deduplicated in increasing order.

func IsSorted
func IsSorted(data sort.Interface) bool

IsSorted reports if data is sorted and deduplicated.

func Slice
func Slice(slice interface{}, less func(i, j int) bool) int

Slice sorts and deduplicates the provided slice given the provided less function.

func SliceIsSorted
func SliceIsSorted(data interface{}, less func(i, j int) bool) bool

SliceIsSorted reports if slice is sorted and deduplicated.

func SliceStable
func SliceStable(slice interface{}, less func(i, j int) bool) int

SliceStable sorts and deduplicates the provided slice given the provided less function while keeping the original order of equal elements.

func Sort
func Sort(data sort.Interface) int

Sort sorts and deduplicated data.

func Stable
func Stable(data sort.Interface) int

Stable sorts and deduplicates data while keeping the original order of equal elements.

func Strings
func Strings(s []string) int

Strings sorts and deduplicates a slice of strings in increasing order.

func StringsAreSorted
func StringsAreSorted(a []string) bool

StringsAreSorted tests whether a slice of strings is sorted and deduplicated in increasing order.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes added in v1.1.0

func Bytes(s []byte) int

Bytes sorts and deduplicates a slice of byte in increasing order.

func BytesAreSorted added in v1.1.0

func BytesAreSorted(s []byte) bool

Bytes tests whether a slice of byte is sorted and deduplicated in increasing order.

func Float32s added in v1.1.0

func Float32s(s []float32) int

Float32s sorts and deduplicates a slice of float32 in increasing order.

func Float32sAreSorted added in v1.1.0

func Float32sAreSorted(s []float32) bool

Float32s tests whether a slice of float32 is sorted and deduplicated in increasing order.

func Float64s

func Float64s(s []float64) int

Float64s sorts and deduplicates a slice of float64s in increasing order (not-a-number values are treated as less than other values).

func Float64sAreSorted

func Float64sAreSorted(a []float64) bool

Float64sAreSorted tests whether a slice of float64s is sorted and deduplicated in increasing order (not-a-number values are treated as less than other values).

func Int16s added in v1.1.0

func Int16s(s []int16) int

Int16s sorts and deduplicates a slice of int16 in increasing order.

func Int16sAreSorted added in v1.1.0

func Int16sAreSorted(s []int16) bool

Int16s tests whether a slice of int16 is sorted and deduplicated in increasing order.

func Int32s added in v1.1.0

func Int32s(s []int32) int

Int32s sorts and deduplicates a slice of int32 in increasing order.

func Int32sAreSorted added in v1.1.0

func Int32sAreSorted(s []int32) bool

Int32s tests whether a slice of int32 is sorted and deduplicated in increasing order.

func Int64s added in v1.1.0

func Int64s(s []int64) int

Int64s sorts and deduplicates a slice of int64 in increasing order.

func Int64sAreSorted added in v1.1.0

func Int64sAreSorted(s []int64) bool

Int64s tests whether a slice of int64 is sorted and deduplicated in increasing order.

func Int8s added in v1.1.0

func Int8s(s []int8) int

Int8s sorts and deduplicates a slice of int8 in increasing order.

func Int8sAreSorted added in v1.1.0

func Int8sAreSorted(s []int8) bool

Int8s tests whether a slice of int8 is sorted and deduplicated in increasing order.

func Ints

func Ints(s []int) int

Ints sorts and deduplicates a slice of ints in increasing order.

func IntsAreSorted

func IntsAreSorted(a []int) bool

IntsAreSorted tests whether a slice of ints is sorted and deduplicated in increasing order.

func IsSorted

func IsSorted(data sort.Interface) bool

IsSorted reports if data is sorted and deduplicated.

func Runes added in v1.1.0

func Runes(s []rune) int

Runes sorts and deduplicates a slice of rune in increasing order.

func RunesAreSorted added in v1.1.0

func RunesAreSorted(s []rune) bool

Runes tests whether a slice of rune is sorted and deduplicated in increasing order.

func Slice

func Slice(slice interface{}, less func(i, j int) bool) int

Slice sorts and deduplicates the provided slice given the provided less function.

func SliceIsSorted added in v0.2.0

func SliceIsSorted(data interface{}, less func(i, j int) bool) bool

SliceIsSorted reports if slice is sorted and deduplicated.

func SliceStable added in v1.0.0

func SliceStable(slice interface{}, less func(i, j int) bool) int

SliceStable sorts and deduplicates the provided slice given the provided less function while keeping the original order of equal elements.

func Sort

func Sort(data sort.Interface) int

Sort sorts and deduplicated data.

func Stable added in v1.0.0

func Stable(data sort.Interface) int

Stable sorts and deduplicates data while keeping the original order of equal elements.

func Strings

func Strings(s []string) int

Strings sorts and deduplicates a slice of strings in increasing order.

func StringsAreSorted

func StringsAreSorted(a []string) bool

StringsAreSorted tests whether a slice of strings is sorted and deduplicated in increasing order.

func Uint16s added in v1.1.0

func Uint16s(s []uint16) int

Uint16s sorts and deduplicates a slice of uint16 in increasing order.

func Uint16sAreSorted added in v1.1.0

func Uint16sAreSorted(s []uint16) bool

Uint16s tests whether a slice of uint16 is sorted and deduplicated in increasing order.

func Uint32s added in v1.1.0

func Uint32s(s []uint32) int

Uint32s sorts and deduplicates a slice of uint32 in increasing order.

func Uint32sAreSorted added in v1.1.0

func Uint32sAreSorted(s []uint32) bool

Uint32s tests whether a slice of uint32 is sorted and deduplicated in increasing order.

func Uint64s added in v1.1.0

func Uint64s(s []uint64) int

Uint64s sorts and deduplicates a slice of uint64 in increasing order.

func Uint64sAreSorted added in v1.1.0

func Uint64sAreSorted(s []uint64) bool

Uint64s tests whether a slice of uint64 is sorted and deduplicated in increasing order.

func Uint8s added in v1.1.0

func Uint8s(s []uint8) int

Uint8s sorts and deduplicates a slice of uint8 in increasing order.

func Uint8sAreSorted added in v1.1.0

func Uint8sAreSorted(s []uint8) bool

Uint8s tests whether a slice of uint8 is sorted and deduplicated in increasing order.

func Uintptrs added in v1.1.0

func Uintptrs(s []uintptr) int

Uintptrs sorts and deduplicates a slice of uintptr in increasing order.

func UintptrsAreSorted added in v1.1.0

func UintptrsAreSorted(s []uintptr) bool

Uintptrs tests whether a slice of uintptr is sorted and deduplicated in increasing order.

func Uints added in v1.1.0

func Uints(s []uint) int

Uints sorts and deduplicates a slice of uint in increasing order.

func UintsAreSorted added in v1.1.0

func UintsAreSorted(s []uint) bool

Uints tests whether a slice of uint is sorted and deduplicated in increasing order.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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