basicallocator

package
v1.17.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicIDAllocator

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

BasicIDAllocator is used for managing a range of identities (unsigned integers) in a very simple way, by allocating specified or random identities, and returning them to the available pool. Concurrency control (mutex locks) is built into IDPool.

func NewBasicIDAllocator

func NewBasicIDAllocator(minIDValue, maxIDValue idpool.ID) *BasicIDAllocator

NewBasicIDAllocator creates a new BasicIDAllocator for ID values between the provided minIDValue and maxIDValue.

func (*BasicIDAllocator) Allocate

func (b *BasicIDAllocator) Allocate(id idpool.ID) error

Allocate attempts to allocate the specified ID from the pool. It first verifies that the ID falls within the allowed range of the pool. If the ID is invalid or not present in the pool, an error is returned.

func (*BasicIDAllocator) AllocateRandom

func (b *BasicIDAllocator) AllocateRandom() (idpool.ID, error)

AllocateRandom attempts to allocate a random ID from the managed pool. If the pool is exhausted or an error occurs, it returns idpool.NoID with an error message.

func (*BasicIDAllocator) IsInPoolRange

func (b *BasicIDAllocator) IsInPoolRange(id idpool.ID) bool

IsInPoolRange checks if a given ID is within the valid range of IDs that the allocator can handle.

func (*BasicIDAllocator) ReturnToAvailablePool

func (b *BasicIDAllocator) ReturnToAvailablePool(id idpool.ID) error

ReturnToAvailablePool attempts to return the given ID back to the available pool of IDs. It checks if the ID is within the valid range of the allocator's pool. If the ID is invalid or already exists in the pool, an error is returned.

func (*BasicIDAllocator) ValidateIDString

func (b *BasicIDAllocator) ValidateIDString(idStr string) (int64, error)

ValidateIDString validates an ID provided in string format. It converts the string to an integer and ensures it falls within the range of IDs managed by the allocator.

Jump to

Keyboard shortcuts

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