MCPcopy Index your code
hub / github.com/beinan/fastid

github.com/beinan/fastid @1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.0.0 ↗ · + Follow
16 symbols 38 edges 2 files 6 documented · 38%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

FastID -- Snowflake ID generating in Go

Godoc Go Report Card Build Status codecov

FastID is a pluggable unique ID generator in Go.

  • Under 64 bits (Long Integer)
  • K-Ordered
  • Lock-free (using atomic CAS)
  • Decentralized

Installation

go get github.com/beinan/fastid

Quick Start

Generate an ID


import (
  "fmt"
  "github.com/beinan/fastid"
)

func ExampleGenInt64ID() {
  id := fastid.CommonConfig.GenInt64ID()
  fmt.Printf("id generated: %v", id)
}

Recommended Settings

  • 40 bits timestamp (34 years from 2018-06-01)
  • 16 bits machine ID (using lower 16 bits of IP v4 addr as default)
  • 7 bits sequence number

With this setting, FastID is able to generate 128(2^7) unique IDs per millisecond (1.048576 millisecond, 2^10 nanosecond).

Customized Settings

See the examples in GoDoc

Benchmarks

Benchmark Settings

  • 40 bits timestamp (34 years from 2018-06-01)
  • 8 bits machine ID
  • 15 bits sequence number
go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/beinan/fastid
BenchmarkGenID-4        20000000                79.7 ns/op
BenchmarkGenIDP-4       20000000               141 ns/op
PASS
ok      github.com/beinan/fastid        4.779s

Core symbols most depended-on inside this repo

GenInt64ID
called by 5
fastid.go
ConstructConfig
called by 2
fastid.go
ConstructConfigWithMachineID
called by 2
fastid.go
getCurrentTimestamp
called by 1
fastid.go
GetSeqFromID
called by 1
fastid.go
GetTimeFromID
called by 1
fastid.go
getMachineID
called by 1
fastid.go
getStartEpochFromEnv
called by 1
fastid.go

Shape

Function 11
Method 4
Struct 1

Languages

Go100%

Modules by API surface

fastid.go11 symbols
fastid_test.go5 symbols

For agents

$ claude mcp add fastid \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact