idgen

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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