Skip to content

norlen/flake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Library to generate Snowflake ids. Uses the discord format for the generated ids.

ID format

The number of bits are the same as discord's. The timestamp is based off a configurable custom epoch.

Timestamp Datacenter ID Machine ID Sequence
42 bits 5 bits 5 bits 12 bits

Timestamp holds 42 bits, which allows for 2^42 = 4 398 046 511 104 millis ≈ 139 years.

The sequence supports up to a maximum of 2^12 = 4096 ids per millisecond. If that limit it hit it generates ids for the next millisecond, this allows for a short burst above 4096 ids per millisecond, but it should not be sustained.

Benchmark

Run cargo bench for results, on my machine it results in approximately 92 ns for each id, so more than 10 million ids per second. When more than 2^12 = 4096 ids are generated per second, it takes ids off the next millisecond.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

No description, website, or topics provided.

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages