Documentation
¶
Overview ¶
Package util contains helper functions for orchestrator check
Index ¶
- func ChunkPayloadsBySizeAndWeight[T any, P any](l *PayloadList[P], a *ChunkAllocator[T, P], maxChunkSize int, ...)
- type AppendToChunk
- type ChunkAllocator
- func (c *ChunkAllocator[T, P]) Accept(ps []P, weight int)
- func (c *ChunkAllocator[T, P]) Append()
- func (c *ChunkAllocator[T, P]) GetChunks() *[]T
- func (c *ChunkAllocator[T, P]) Next()
- func (c *ChunkAllocator[T, P]) SetActiveChunk(i int)
- func (c *ChunkAllocator[T, P]) SetLastChunk()
- func (c *ChunkAllocator[T, P]) TakenSize() int
- func (c *ChunkAllocator[T, P]) TakenWeight() int
- type OnAccept
- type PayloadList
- type WeightAt
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 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 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