Documentation
¶
Index ¶
Constants ¶
const ( // DefaultMaxDescriptors is the default maximum number of descriptors. DefaultMaxDescriptors = 50 // DefaultMaxSize is the default maximum size of a descriptor in bytes. DefaultMaxSize = 5e8 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Allocator ¶
type Allocator[K, D comparable, I Item[K]] interface { // Allocate allocates itemDescriptors of a given size to descriptors. Returns a slice of descriptor keys. Allocate(items ...I) []D }
Allocator is used to allocate items to a set of descriptors. A descriptor can represent a file, buffer (essentially anything assigned with a maximum size).
Type Arguments:
K - The type of the items key. D - The type of the descriptors key.
Implementation Details:
The implementation of Allocator provided in this package optimizes for: sequential allocation of items with the same key (i.e. all items with the key "hello" go to their own file (if possible)). It uses a simple set of rules:
- Allocate the item to the descriptor it was allocated to previously.
- If the item is not allocated OR the size of the descriptor exceeds the size set in Config.MaxSize, then allocate the item to the next AVAILABLE descriptor.
Available Means:
A. A completely NEW descriptor if config.MaxDescriptors has not been reached. OR B. The descriptor with the lowest size if config.MaxDescriptors has been reached.
func New ¶
func New[K, D comparable, I Item[K]](nd NextDescriptor[D], config Config) Allocator[K, D, I]
type Config ¶
type Config struct { // MaxDescriptors is the maximum number of concurrent descriptors that can be allocated at once. // If this value is 0, the default value of DefaultMaxDescriptors is used. MaxDescriptors int // MaxSize is the maximum size of a descriptor in bytes. If this value is 0, the default value of // DefaultMaxSize is used. MaxSize telem.Size // Experiment is the experiment that Allocate will use to record its metrics. Experiment alamos.Experiment }
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default configuration for the Allocator.
type Item ¶
type Item[K comparable] interface { // Key returns the key of the item. Key() K // Size returns the size of the item. Size() telem.Size }
type NextDescriptor ¶
type NextDescriptor[D comparable] interface { Next() D }
NextDescriptor returns a unique descriptor key that represents the next descriptor.
type NextDescriptorInt ¶
type NextDescriptorInt struct {
// contains filtered or unexported fields
}
func (*NextDescriptorInt) Next ¶
func (n *NextDescriptorInt) Next() int