Documentation ¶
Index ¶
- Variables
- type IDRing
- func (ir *IDRing) Clear()
- func (ir *IDRing) GetID() (uint64, error)
- func (ir *IDRing) GetSpecificID(id uint64) error
- func (ir IDRing) Invert() *IDRing
- func (ir IDRing) IsEmpty() bool
- func (ir *IDRing) ReclaimID(id uint64) error
- func (idRing *IDRing) ReclaimIDNoLock(id uint64) error
- func (ir *IDRing) ReclaimIDs(ids []uint64) (error, []uint64)
- func (ir IDRing) String() string
- type Range
Constants ¶
This section is empty.
Variables ¶
var (
IDRingOverflowError = common.NewError("No more available IDs")
)
Functions ¶
This section is empty.
Types ¶
type IDRing ¶
type IDRing struct { // Ranges is an ordered set of ranges from which we allocate IDs. // Initially this should include a single Range. // When this is nil, it means that we have exhausted the entire // range from OrigMin to OrigMax, and, unless an ID is reclaimed, no more // IDs can be given out. // TODO this implementation is probably better (memory-wise) for a lot of allocations, with few // reclaimed IDs, as is often the case. But if there are intended to be relatively // few allocations and lots of reuse, a faster (less memory-efficient, which doesn't matter // at small sizes) would be better. Thus it may make sense to extract // an interface and split implementation into 2: intended for mostly allocations and few // reclamations, and intended for few allocations with a lot of reclamations. Ranges []Range OrigMin uint64 OrigMax uint64 // contains filtered or unexported fields }
IDRing is responsible for allocating first available ID. Initially the available range is from OrigMin to OrigMax as provided in the creation. As IDs are allocated (see GetID), the range shrinks. IDs can be returned to the Ring (see ReclaimID). An instance of this SHOULD NOT be created directly, use NewIDRing() to create it.
func NewIDRing ¶
NewIDRing constructs a new IDRing instance with a single range for provided min and max
func (*IDRing) Clear ¶
func (ir *IDRing) Clear()
Clear clears out the ring (reverts it to what it was when originally constructed)
func (*IDRing) GetID ¶
GetID returns the first available ID, starting with OrigMin. It will return an IDRingOverflowError if no more IDs can be returned.
func (*IDRing) GetSpecificID ¶
GetSpecificID attempts to return a specific ID from the ring. Returns error if impossible.
func (IDRing) Invert ¶
Invert() returns an IDRing that is the inverse of this IDRing (that is, containing Ranges that are ranges not of available, but of taken IDs).
func (*IDRing) ReclaimIDNoLock ¶
ReclaimIDNoLock returns the provided ID into the pool, so it can be returned again upon some future call to GetID.
func (*IDRing) ReclaimIDs ¶
ReclaimIDs reclaims a list of IDs. If an error occurs, what additionally a list of IDs that could not be reclaimed is returned.