util

package module
v0.76.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package util contains helper functions for orchestrator check

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkPayloadsBySizeAndWeight

func ChunkPayloadsBySizeAndWeight[T any, P any](l *PayloadList[P], a *ChunkAllocator[T, P], maxChunkSize int, maxChunkWeight int)

ChunkPayloadsBySizeAndWeight allocates chunks of payloads taking max allowed size and max allowed weight algorithm in the nutshell: - iterate through payloads in the `payloadList` - keep track of size and weight available for allocation (`TakenSize` and `TakenWeight`) - create a new chunk once we exceed these limits - consider case when the current item exceeds the max allowed weight and create a new chunk at the end (`Append`) this implementation allows for multiple passes through the chunks, which can be useful in cases with different payload types being allocated within chunks See PayloadList and ChunkAllocator for a description of the type params.

Types

type AppendToChunk

type AppendToChunk[T any, P any] func(t *T, ps []P)

type ChunkAllocator

type ChunkAllocator[T any, P any] struct {

	// A function which adds the group of payloads to the chunk
	AppendToChunk AppendToChunk[T, P]
	// An optional callback that allows for manipulation the chunk when a payload is added
	OnAccept OnAccept[T]
	// contains filtered or unexported fields
}

ChunkAllocator manages operations for chunk allocation. The type T is the type of the chunk, and the type P is the type of the payload.

func (*ChunkAllocator[T, P]) Accept

func (c *ChunkAllocator[T, P]) Accept(ps []P, weight int)

Accept accepts a group of payloads into the current chunk

func (*ChunkAllocator[T, P]) Append

func (c *ChunkAllocator[T, P]) Append()

Append creates a new chunk at the end (cases when it is known any previously allocated chunks cannot fit the payload)

func (*ChunkAllocator[T, P]) GetChunks

func (c *ChunkAllocator[T, P]) GetChunks() *[]T

func (*ChunkAllocator[T, P]) Next

func (c *ChunkAllocator[T, P]) Next()

Next moves to the next chunk or allocates a new chunk if the current chunk is the last

func (*ChunkAllocator[T, P]) SetActiveChunk

func (c *ChunkAllocator[T, P]) SetActiveChunk(i int)

SetActiveChunk allows for rewinding in the case of multiple runs

func (*ChunkAllocator[T, P]) SetLastChunk

func (c *ChunkAllocator[T, P]) SetLastChunk()

SetLastChunk sets the last chunk in case there is space at end across multiple runs

func (*ChunkAllocator[T, P]) TakenSize

func (c *ChunkAllocator[T, P]) TakenSize() int

TakenSize returns the size allocated to the current chunk

func (*ChunkAllocator[T, P]) TakenWeight

func (c *ChunkAllocator[T, P]) TakenWeight() int

TakenWeight returns the weight allocated to the current chunk

type OnAccept

type OnAccept[T any] func(t *T)

type PayloadList

type PayloadList[T any] struct {
	// The items to chunk
	Items []T
	// A function which returns the weight of an item at the given index
	WeightAt WeightAt
}

PayloadList is a wrapper for payloads subject to chunking

func (*PayloadList[T]) Len

func (l *PayloadList[T]) Len() int

Len returns the number of items in the list

type WeightAt

type WeightAt func(int) int

Jump to

Keyboard shortcuts

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