Documentation ¶
Index ¶
Constants ¶
View Source
const MaxTimestamp int64 = 0x8ffffff_ffffffff
Variables ¶
View Source
var _, ErrDefaultGeneratorCreation = NewGenerator(0)
Functions ¶
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
UID64 generator with generator-id
func NewGenerator ¶
NewGenerator creates new *Generator with generator-id generator-id is IDentifier of Generator, for ditributed usage. It should be 0 <= id <= 3.
type UID ¶
type UID uint64
A UID is a 64 bit (8byte) Unique IDentifier
- 6 byte Unix-Milli Timestamp
- 1 byte Entropy from /dev/urandom
- 1 byte for Counter & GeneratorID (6bit counter & 2bit id)
func InitUID ¶
Initialize UID from timestamp, random uint8, and genID, and counter. For ordinary case, you don't have to call this method, call Generater.Gen()/GenDanger() instead.
func (UID) GeneratorID ¶
GeneratorID returns 2bit generator-id field,
func (UID) Timestamp ¶
Timestamp returns 48 bit timestamp field value as int64, same to time.Unix().Milli.
type UID64Slice ¶
type UID64Slice []UID
Implementation sort.Interface for convinience
func (UID64Slice) Len ¶
func (x UID64Slice) Len() int
func (UID64Slice) Less ¶
func (x UID64Slice) Less(i, j int) bool
func (UID64Slice) Swap ¶
func (x UID64Slice) Swap(i, j int)
Click to show internal directories.
Click to hide internal directories.