sliceutil

package
v0.1.128 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDuplicateValues

func CheckDuplicateValues[T comparable](slices ...[]T) error

CheckDuplicateValues checks for duplicates across multiple slices of type T. Returns an error if at least one value is duplicated across a minimum of two slices or in the same slice.

func RemoveDuplicates

func RemoveDuplicates[T comparable](slice []T) []T

RemoveDuplicates removes duplicates from a slice of any type using generics.

func RemoveSliceElements

func RemoveSliceElements[T comparable](slice1, slice2 []T) []T

RemoveSliceElements removes elements of the second slice from the first slice.

Types

type SliceComparisonResult

type SliceComparisonResult[T comparable] struct {
	DifferenceA []T // Elements in sliceA but not in sliceB.
	DifferenceB []T // Elements in sliceB but not in sliceA.
	Similar     []T // Elements present in both slices.
}

SliceComparisonResult holds the differences and similarities between two slices.

func CompareSlices

func CompareSlices[T comparable](sliceA, sliceB []T) SliceComparisonResult[T]

CompareSlices compares two slices and returns a struct with the differences and similarities.

It works with slices of any comparable type and has a time complexity of O(n + m), where n is the length of sliceA and m is the length of sliceB.

Jump to

Keyboard shortcuts

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