idalloc

package
v0.0.0-...-21cfbab Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("release of unknown ID")

Functions

This section is empty.

Types

type ByMaxIndex

type ByMaxIndex []IndexRange

ByMaxIndex sorts collections of IndexRange structs in order of their starting/lower index

func (ByMaxIndex) Len

func (i ByMaxIndex) Len() int

Len is the number of indexranges in the collection

func (ByMaxIndex) Less

func (i ByMaxIndex) Less(a, b int) bool

Less reports whether the element with index a must sort before the element with index b.

func (ByMaxIndex) Swap

func (i ByMaxIndex) Swap(a, b int)

Swap swaps the elements with indexes a and b.

type IDAllocator

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

IPSetIDAllocator allocates unique 64-bit IDs for the given string IDs. It ensures uniqueness by tracking allocations in a map. To minimise churn over restart, IDs are chosen by iterated hashing with collision detection. No-longer needed IDs must be released via the Release method or they will be leaked.

func New

func New() *IDAllocator

func (*IDAllocator) GetAndRelease

func (a *IDAllocator) GetAndRelease(id string) uint64

GetAndRelease releases the given IP set ID allocation and returns the old value, or 0 if the ID was not known.

func (*IDAllocator) GetNoAlloc

func (a *IDAllocator) GetNoAlloc(id string) uint64

func (*IDAllocator) GetOrAlloc

func (a *IDAllocator) GetOrAlloc(id string) uint64

GetOrAlloc returns the existing allocation for the given ID (if there is one), or allocates one if not.

func (*IDAllocator) ReleaseUintID

func (a *IDAllocator) ReleaseUintID(id uint64) error

func (*IDAllocator) ReserveWellKnownID

func (a *IDAllocator) ReserveWellKnownID(id string, n uint64)

func (*IDAllocator) TrialHash

func (a *IDAllocator) TrialHash(id string, n uint64) uint64

type IndexAllocator

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

func NewIndexAllocator

func NewIndexAllocator(indexRanges []IndexRange, exclusions []IndexRange) *IndexAllocator

NewIndexAllocator returns an index allocator from the provided indexRanges any indices falling within the specified exclusions will not be returned, even if designated by indexRanges

func (*IndexAllocator) GrabBlock

func (r *IndexAllocator) GrabBlock(len int) (set.Set[int], error)

GrabBlock tries to grab a contiguous block of indices from the stack

func (*IndexAllocator) GrabIndex

func (r *IndexAllocator) GrabIndex() (int, error)

func (*IndexAllocator) ReleaseIndex

func (r *IndexAllocator) ReleaseIndex(index int)

type IndexRange

type IndexRange struct {
	Min, Max int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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