Documentation ¶
Index ¶
- Variables
- type ByMaxIndex
- type IDAllocator
- func (a *IDAllocator) GetAndRelease(id string) uint64
- func (a *IDAllocator) GetNoAlloc(id string) uint64
- func (a *IDAllocator) GetOrAlloc(id string) uint64
- func (a *IDAllocator) ReleaseUintID(id uint64) error
- func (a *IDAllocator) ReserveWellKnownID(id string, n uint64)
- func (a *IDAllocator) TrialHash(id string, n uint64) uint64
- type IndexAllocator
- type IndexRange
Constants ¶
This section is empty.
Variables ¶
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)
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 ¶
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
}