para

package
v0.0.0-...-9687f63 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package para implements parallel versions of some things in algo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Divvy

func Divvy[S ~[]E, E any](in S, n int) []S

Divvy divides a slice into up to n subslices of approximately equal size.

func Do

func Do[S ~[]E, E any](in S, f func(E))

Do calls f with each element of in. It does this in parallel, using up to GOMAXPROCS goroutines.

func Map

func Map[S ~[]X, X, Y any](in S, f func(X) Y) []Y

Map calls f with each element of in, to build the output slice. It does the mapping in parallel, using up to GOMAXPROCS goroutines.

func Reduce

func Reduce[S ~[]E, E any](in S, f func(E, E) E) E

Reduce reduces a slice to a single value. For consistent results, f should be associative and the zero value for E should be an identity element. It does the reduction in parallel, using up to GOMAXPROCS goroutines.

Types

type Queue

type Queue[E any] struct {
	// contains filtered or unexported fields
}

Queue implements a goroutine-safe queue of items based on a channel.

func NewQueue

func NewQueue[E any](items ...E) *Queue[E]

NewQueue returns a new queue with an initial list of items.

func (*Queue[E]) Process

func (q *Queue[E]) Process(f func(E))

Process calls f on each item in the queue in parallel (with GOMAXPROCS goroutines). f can enqueue more items by calling q.Push. It blocks until the queue is empty and all items have been processed.

func (*Queue[E]) Push

func (q *Queue[E]) Push(items ...E)

Push appends to the end of the queue.

Jump to

Keyboard shortcuts

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