idgen

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package idgen provides a lock-free snowflake ID generator for stream writes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

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

Generator produces unique 64-bit snowflake IDs using a lock-free CAS loop. Bit layout: [1-bit sign=0] [46-bit ms timestamp] [7-bit node ID] [10-bit sequence]. The internal state packs lastTime and sequence into a single uint64: state = (lastTime << sequenceBits) | sequence.

func NewGenerator

func NewGenerator(nodeID string, l *logger.Logger) *Generator

NewGenerator creates a Generator whose 7-bit node component is derived by hashing the given nodeID string.

func (*Generator) NextID

func (g *Generator) NextID() uint64

NextID returns the next unique 64-bit ID.

func (*Generator) NodeID

func (g *Generator) NodeID() int64

NodeID returns the 7-bit node component used by this generator.

Jump to

Keyboard shortcuts

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