License | Apache 2.0 |
---|---|
Maintainer | edofic@gmail.com |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
Data.Snowflake
Description
This generates unique(guaranteed) identifiers build from time stamp,
counter(inside same millisecond) and node id - if you wish to generate
ids across several nodes. Identifiers are convertible to Integer
values which are monotonically increasing with respect to time.
- data SnowflakeConfig = SnowflakeConfig {
- confTimeBits :: !Int
- confCountBits :: !Int
- confNodeBits :: !Int
- data Snowflake
- data SnowflakeGen
- newSnowflakeGen :: SnowflakeConfig -> Integer -> IO SnowflakeGen
- nextSnowflake :: SnowflakeGen -> IO Snowflake
- defaultConfig :: SnowflakeConfig
- snowflakeToInteger :: Snowflake -> Integer
Documentation
data SnowflakeConfig #
Configuration that specifies how much bits are used for each part of the id. There are no limits to total bit sum.
Constructors
SnowflakeConfig | |
Fields
|
Instances
Generated identifier. Can be converted to Integer
.
data SnowflakeGen #
Generator which contains needed state. You should use newSnowflakeGen
to create instances.
newSnowflakeGen :: SnowflakeConfig -> Integer -> IO SnowflakeGen #
Create a new generator. Takes a configuration and node id.
nextSnowflake :: SnowflakeGen -> IO Snowflake #
Generates next id. The bread and butter. See module description for details.
defaultConfig :: SnowflakeConfig #
Default configuration using 40 bits for time, 16 for count and 8 for node id.
snowflakeToInteger :: Snowflake -> Integer #
Converts an identifier to an integer with respect to configuration used to generate it.