arrayOperations

package module
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: MIT Imports: 1 Imported by: 35

README

Build Status Coverage Status Go Report Card GoDoc

arrayOperations

Small library for performing union, intersect, difference and distinct operations on slices in goLang

I don't promise that these are optimized (not even close!), but they work :)

Quickstart

var a = []int{1, 1, 2, 3}
var b = []int{2, 4}

z, ok := Difference(a, b)
if !ok {
	fmt.Println("Cannot find difference")
}

slice, ok := z.Interface().([]int)
if !ok {
	fmt.Println("Cannot convert to slice")
}
fmt.Println(slice, reflect.TypeOf(slice)) // [1, 3, 4] []int

API

Difference
func Difference(arrs ...interface{}) (reflect.Value, bool)

Difference returns a slice of values that are only present in one of the input slices

[1, 2, 2, 4, 6] & [2, 4, 5] >> [1, 5, 6]

[1, 1, 3, 4, 5, 6] >> [1, 3, 4, 5, 6]

// EXAMPLE
var a = []int{1, 1, 2, 3}
var b = []int{2, 4}

z, ok := Difference(a, b)
if !ok {
    fmt.Println("Cannot find difference")
}

slice, ok := z.Interface().([]int)
if !ok {
    fmt.Println("Cannot convert to slice")
}
fmt.Println(slice, reflect.TypeOf(slice)) // [1, 3, 4] []int
Distinct
func Distinct(arr interface{}) (reflect.Value, bool)

Distinct returns the unique vals of a slice

[1, 1, 2, 3] >> [1, 2, 3]

// EXAMPLE
var a = []int{1, 1, 2, 3}

z, ok := Distinct(a)
if !ok {
    fmt.Println("Cannot find distinct")
}

slice, ok := z.Interface().([]int)
if !ok {
    fmt.Println("Cannot convert to slice")
}
fmt.Println(slice, reflect.TypeOf(slice)) // [1, 2, 3] []int
Intersect
func Intersect(arrs ...interface{}) (reflect.Value, bool)

Intersect returns a slice of values that are present in all of the input slices

[1, 1, 3, 4, 5, 6] & [2, 3, 6] >> [3, 6]

[1, 1, 3, 4, 5, 6] >> [1, 3, 4, 5, 6]

// EXAMPLE
var a = []int{1, 1, 2, 3}
var b = []int{2, 4}

z, ok := Intersect(a, b)
if !ok {
    fmt.Println("Cannot find intersect")
}

slice, ok := z.Interface().([]int)
if !ok {
    fmt.Println("Cannot convert to slice")
}
fmt.Println(slice, reflect.TypeOf(slice)) // [2] []int
Union
func Union(arrs ...interface{}) (reflect.Value, bool)

Union returns a slice that contains the unique values of all the input slices

[1, 2, 2, 4, 6] & [2, 4, 5] >> [1, 2, 4, 5, 6]

[1, 1, 3, 4, 5, 6] >> [1, 3, 4, 5, 6]

// EXAMPLE
var a = []int{1, 1, 2, 3}
var b = []int{2, 4}

z, ok := Union(a, b)
if !ok {
    fmt.Println("Cannot find union")
}

slice, ok := z.Interface().([]int)
if !ok {
    fmt.Println("Cannot convert to slice")
}
fmt.Println(slice, reflect.TypeOf(slice)) // [1, 2, 3, 4] []int

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Difference

func Difference(arrs ...interface{}) (reflect.Value, bool)

Difference returns a slice of values that are only present in one of the input slices

[1, 2, 2, 4, 6] & [2, 4, 5] >> [1, 5, 6]

[1, 1, 3, 4, 5, 6] >> [1, 3, 4, 5, 6]

Example
var a = []int{1, 1, 2, 3}
var b = []int{2, 4}

z, ok := Difference(a, b)
if !ok {
	fmt.Println("Cannot find difference")
}

slice, ok := z.Interface().([]int)
if !ok {
	fmt.Println("Cannot convert to slice")
}
fmt.Println(slice, reflect.TypeOf(slice)) // [1, 3] []int

func DifferenceString deprecated

func DifferenceString(args ...[]string) []string

DifferenceString finds the difference of two arrays.

Deprecated: use Difference instead.

func DifferenceStringArr deprecated

func DifferenceStringArr(arr [][]string) []string

DifferenceStringArr finds the difference of two arrays using a multidimensional array as inputs

Deprecated: use Difference instead.

func DifferenceUint64 deprecated

func DifferenceUint64(args ...[]uint64) []uint64

DifferenceUint64 finds the difference of two arrays.

Deprecated: use Difference instead.

func DifferenceUint64Arr deprecated

func DifferenceUint64Arr(arr [][]uint64) []uint64

DifferenceUint64Arr finds the difference of two arrays using a multidimensional array as inputs.

Deprecated: use Difference instead.

func Distinct

func Distinct(arr interface{}) (reflect.Value, bool)

Distinct returns the unique vals of a slice

[1, 1, 2, 3] >> [1, 2, 3]

Example

Examples

var a = []int{1, 1, 2, 3}

z, ok := Distinct(a)
if !ok {
	fmt.Println("Cannot find distinct")
}

slice, ok := z.Interface().([]int)
if !ok {
	fmt.Println("Cannot convert to slice")
}
fmt.Println(slice, reflect.TypeOf(slice)) // [1, 2, 3] []int

func DistinctIntersectUint64 deprecated

func DistinctIntersectUint64(args ...[]uint64) []uint64

DistinctIntersectUint64 finds the intersection of two arrays of distinct vals.

Deprecated: use Intersect instead.

func DistinctIntersectUint64Arr deprecated

func DistinctIntersectUint64Arr(arr [][]uint64) []uint64

DistinctIntersectUint64Arr finds the intersection of two distinct arrays using a multidimensional array as inputs

Deprecated: use Distinct instead.

func DistinctString deprecated

func DistinctString(arg []string) []string

DistinctString removes duplicate values from one array.

Deprecated: use Distinct instead.

func DistinctUint64 deprecated

func DistinctUint64(arg []uint64) []uint64

DistinctUint64 removes duplicate values from one array.

Deprecated: use Distinct instead.

func Intersect

func Intersect(arrs ...interface{}) (reflect.Value, bool)

Intersect returns a slice of values that are present in all of the input slices

[1, 1, 3, 4, 5, 6] & [2, 3, 6] >> [3, 6]

[1, 1, 3, 4, 5, 6] >> [1, 3, 4, 5, 6]

Example
var a = []int{1, 1, 2, 3}
var b = []int{2, 4}

z, ok := Intersect(a, b)
if !ok {
	fmt.Println("Cannot find intersect")
}

slice, ok := z.Interface().([]int)
if !ok {
	fmt.Println("Cannot convert to slice")
}
fmt.Println(slice, reflect.TypeOf(slice)) // [2] []int

func IntersectString deprecated

func IntersectString(args ...[]string) []string

IntersectString finds the intersection of two arrays.

Deprecated: use Intersect instead.

func IntersectStringArr deprecated

func IntersectStringArr(arr [][]string) []string

IntersectStringArr finds the intersection of two arrays using a multidimensional array as inputs

Deprecated: use Intersect instead.

func IntersectUint64 deprecated

func IntersectUint64(args ...[]uint64) []uint64

IntersectUint64 finds the intersection of two arrays.

Deprecated: use Intersect instead.

func IntersectUint64Arr deprecated

func IntersectUint64Arr(arr [][]uint64) []uint64

IntersectUint64Arr finds the intersection of two arrays using a multidimensional array as inputs

Deprecated: use Intersect instead.

func SortedIntersectUint64 deprecated

func SortedIntersectUint64(args ...[]uint64) []uint64

SortedIntersectUint64 finds the intersection of two sorted arrays.

Deprecated: use Intersect instead.

func SortedIntersectUint64Arr deprecated

func SortedIntersectUint64Arr(arr [][]uint64) []uint64

SortedIntersectUint64Arr finds the intersection of two arrays using a multidimensional array as inputs

Deprecated: use Intersect instead.

func Union

func Union(arrs ...interface{}) (reflect.Value, bool)

Union returns a slice that contains the unique values of all the input slices

[1, 2, 2, 4, 6] & [2, 4, 5] >> [1, 2, 4, 5, 6]

[1, 1, 3, 4, 5, 6] >> [1, 3, 4, 5, 6]

Example
var a = []int{1, 1, 2, 3}
var b = []int{2, 4}

z, ok := Union(a, b)
if !ok {
	fmt.Println("Cannot find union")
}

slice, ok := z.Interface().([]int)
if !ok {
	fmt.Println("Cannot convert to slice")
}
fmt.Println(slice, reflect.TypeOf(slice)) // [1, 2, 3, 4] []int

func UnionString deprecated

func UnionString(args ...[]string) []string

UnionString finds the union of two arrays.

Deprecated: use Union instead.

func UnionStringArr deprecated

func UnionStringArr(arr [][]string) []string

UnionStringArr finds the union of two arrays using a multidimensional array as inputs

Deprecated: use Union instead.

func UnionUint64 deprecated

func UnionUint64(args ...[]uint64) []uint64

UnionUint64 finds the union of two arrays.

Deprecated: use Union instead.

func UnionUint64Arr deprecated

func UnionUint64Arr(arr [][]uint64) []uint64

UnionUint64Arr finds the union of two arrays using a multidimensional array as inputs

Deprecated: use Union instead.

Types

This section is empty.

Jump to

Keyboard shortcuts

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