allocator

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound the number was never allocated
	ErrNotFound = errors.New("number not allocated")
	// ErrConflict the number was already allocated
	ErrConflict = errors.New("number already allocated")
	// ErrInvalidRange the range is invalid
	ErrInvalidRange = errors.New("invalid range")
	// ErrOutOfRange the number is out of range
	ErrOutOfRange = errors.New("out of range")
	// ErrRangeFull the range is full
	ErrRangeFull = errors.New("range full")
	// ErrInternal something is wrong internally
	ErrInternal = errors.New("internal error")
)

Functions

This section is empty.

Types

type MinMaxAllocator

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

MinMaxAllocator is an allocator over a range [min-max]

func NewMinMaxAllocator

func NewMinMaxAllocator(min, max int) (*MinMaxAllocator, error)

NewMinMaxAllocator creates a new MinMaxAllocator

func (*MinMaxAllocator) Allocate

func (a *MinMaxAllocator) Allocate(i int) (bool, error)

Allocate allocates a given number

func (*MinMaxAllocator) AllocateNext

func (a *MinMaxAllocator) AllocateNext() (int, bool, error)

AllocateNext allocates the first free number

func (*MinMaxAllocator) Free

func (a *MinMaxAllocator) Free() int

Free returns the next free number

func (*MinMaxAllocator) Has

func (a *MinMaxAllocator) Has(i int) bool

Has returns whether the allocator has the given number

func (*MinMaxAllocator) Release

func (a *MinMaxAllocator) Release(i int) error

Release releases the given number

func (*MinMaxAllocator) SetRange

func (a *MinMaxAllocator) SetRange(min, max int) error

SetRange sets the range of the MinMaxAllocator

type Rangeable

type Rangeable interface {
	Allocate(int) (bool, error)
	AllocateNext() (int, bool, error)
	Release(int) error
	Has(int) bool
	Free() int
	SetRange(min, max int) error
}

Rangeable is an Interface that can adjust its min/max range. Rangeable should be threadsafe

Jump to

Keyboard shortcuts

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