Documentation
¶
Overview ¶
Package idgen provides distributed ID generation without requiring central coordination.
IDs are 64-bit integers with the following structure:
- 41 bits: Timestamp in milliseconds since epoch
- 10 bits: Region ID (supports 1024 regions)
- 12 bits: Sequence number (supports 4096 IDs per millisecond per region)
This design ensures globally unique IDs across multiple regions while maintaining the benefits of integer primary keys (smaller storage, faster indexes, compatibility with existing protocols).
Example usage:
generator := idgen.NewGenerator(1) // Region ID = 1 characterID := generator.NextID() // 7123456789012345678
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator generates globally unique 64-bit IDs for a specific region. It is safe for concurrent use.
func NewGenerator ¶
NewGenerator creates a new ID generator for the specified region. Region ID must be between 0 and 1023 (inclusive).
Click to show internal directories.
Click to hide internal directories.