sliceutils

package
v0.0.0-...-744dbeb Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

The sliceutils package adds helper functions that deal with slices and walks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteCyclesInPlace

func DeleteCyclesInPlace(oldWalk []uint32, newWalk []uint32) []uint32

removes (in place) all elements from newWalk after the first occurrence of a cycle by checking against oldWalk. DeleteCyclesInPlace changes newWalk in the caller. If that's not wanted, use TrimCycles instead.

func Difference

func Difference[S ~[]E, E cmp.Ordered](slice1, slice2 S) S

Difference() returns the difference between slice1 and slice2; in set notation:

- difference = slice1 - slice2

Time complexity O(n * logn + m * logm), where n and m are the lengths of the slices. This function is much faster than converting to sets for sizes (n, m) smaller than ~10^6.

func Partition

func Partition[S ~[]E, E cmp.Ordered](slice1, slice2 S) (removed, common, added S)

Partition() returns removed, commond and added elements, using set notation:

removed = slice1 - slice2 common = slice1 ^ slice2 added = slice2 - slice1

Time complexity O(n * logn + m * logm), where n and m are the lengths of the slices. This function is much faster than converting to sets for sizes (n, m) smaller than ~10^6.

func SortWalks

func SortWalks(walks []models.RandomWalk) []models.RandomWalk

SortWalks() sorts walks lexicographically.

func SplitSlice

func SplitSlice[S ~[]E, E cmp.Ordered](slice S, batchSize int) []S

SplitSlice splits a slice into a slice of slices, each with a maximum size of batchSize

func TrimCycles

func TrimCycles(oldWalk []uint32, newWalk []uint32) []uint32

returns a new slice up to the first occurrence of a cycle by checking against oldWalk. TrimCycles doesn't change newWalk in the caller. If that's wanted, use DeleteCyclesInPlace instead.

func Unique

func Unique[S ~[]E, E cmp.Ordered](slice S) S

Unique() returns a slice of unique elements of the input slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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