localid

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 2 Imported by: 0

README

localid

Local ID will give you integers on demand that are not currently in use from the generator. This works by keeping an internal counter of the highest ID it's generated, storing "returned" IDs in a queue, and simply generating more as required.

This means that IDs may be reused from this generator, if you use ReturnIDs().

The benefit of this approach compared to just constantly incrementing an integer is that your ID space stays relatively small, and works well for long-running applications that need to frequently have a cheap way to identify an object, but don't want to generate unnecessarily large IDs, or deal with potential integer overflows (assuming they return IDs frequently enough).

This is used in Fossabot to uniquely identify tasks within the distributed scheduler processes.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator interface {
	// ID returns a new ID
	ID() int
	// ReturnIDs adds new IDs back to the queue.
	ReturnIDs(...int)
}

Generator implements the local id generator

func NewGenerator

func NewGenerator() Generator

NewGenerator creates a new Generator instance

type GeneratorImpl

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

GeneratorImpl is the struct that implements Generator

func (*GeneratorImpl) ID

func (g *GeneratorImpl) ID() int

func (*GeneratorImpl) ReturnIDs

func (g *GeneratorImpl) ReturnIDs(items ...int)

ReturnIDs adds new IDs back to the queue.

Jump to

Keyboard shortcuts

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