Discover Packages
drjosh.dev/exp
para
package
Version:
v0.0.0-...-80cb8e9
Opens a new window with list of versions in this module.
Published: Dec 8, 2024
License: Apache-2.0
Opens a new window with license information.
Imports: 3
Opens a new window with list of imports.
Imported by: 8
Opens a new window with list of known importers.
Documentation
Documentation
¶
Package para implements parallel versions of some things in algo.
func Divvy[S ~[]E, E any](in S, n int) []S
func Do[S ~[]E, E any](in S, f func(E))
func Map[S ~[]X, X, Y any](in S, f func(X) Y) []Y
func Reduce[S ~[]E, E any](in S, f func(E, E) E) E
type Queue
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[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[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[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.
type Queue[E any ] struct {
}
Queue implements a goroutine-safe queue of items based on a channel.
func NewQueue[E any ](items ...E) *Queue [E]
NewQueue returns a new queue with an initial list of items.
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 (q *Queue [E]) Push(items ...E)
Push appends to the end of the queue.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.