parallel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

package parallel contains parallel LoopUntil() and parallel ForEach() plus other concurrency primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEach

func ForEach(length, limit int, body func(i int))

ForEach executes a for loop with a limited number of concurrent goroutines. Each goroutine processes one integer, from 0 to length.

Types

type Hasher

type Hasher struct {
	// contains filtered or unexported fields
}

func NewHashHasher

func NewHashHasher(n int) *Hasher

func NewUint16Hasher

func NewUint16Hasher(n int) *Hasher

func (*Hasher) MustPutHash

func (h *Hasher) MustPutHash(n int, value [32]byte)

func (*Hasher) MustPutUint16

func (h *Hasher) MustPutUint16(n int, value uint16)

func (*Hasher) Sum

func (h *Hasher) Sum() (ret [32]byte)

type Loop

type Loop int

Loop represents the number of goroutines to run.

func (Loop) LoopUntil

func (l Loop) LoopUntil(yield func(i uint32, ender LoopStopper) bool)

LoopUntil starts 'l' goroutines that iterate until one of them stops the loop. Each goroutine processes a unique integer i starting from 0. The loop stops if i reaches math.MaxUint32 or any goroutine's yield returns true.

type LoopStopper

type LoopStopper interface {

	// Load reports true if the loop should stop.
	Load() bool
}

LoopStopper is an interface to check if the loop should stop.

type MoveSet

type MoveSet struct {
	// contains filtered or unexported fields
}

MoveSet is a thread-safe set that tracks unique moves for a specific level. When the level changes, all existing moves are cleared to prevent mixing moves from different levels.

func NewMoveSet

func NewMoveSet() *MoveSet

NewMoveSet initializes and returns a new MoveSet instance. Initial level is 0.

func (*MoveSet) Exists

func (m *MoveSet) Exists(position [32]byte, move int, level byte) bool

Exists checks if a move exists in the set for the current level. Returns false immediately if the provided level doesn't match the set's current level. position: The game position to check. move: The move identifier to check. level: The level to verify against.

func (*MoveSet) Insert

func (m *MoveSet) Insert(position [32]byte, move int, level byte)

Insert adds a move to the set. If the provided level differs from the current level, the set is cleared before adding the new move. This ensures moves are grouped by level. position: The game position represented as a 32-byte array. move: The move identifier to be serialized. level: The current level associated with the move.

Jump to

Keyboard shortcuts

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