Documentation
¶
Index ¶
- type BasicIDAllocator
- func (b *BasicIDAllocator) Allocate(id idpool.ID) error
- func (b *BasicIDAllocator) AllocateRandom() (idpool.ID, error)
- func (b *BasicIDAllocator) IsInPoolRange(id idpool.ID) bool
- func (b *BasicIDAllocator) ReturnToAvailablePool(id idpool.ID) error
- func (b *BasicIDAllocator) ValidateIDString(idStr string) (int64, error)
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.