1
0
mirror of synced 2025-12-07 13:48:23 +08:00
Files
SnowFlake-IdGenerator/C
2022-08-20 14:52:42 +08:00
..
2022-07-16 00:42:36 +08:00
2022-08-20 14:52:42 +08:00

❄ idgenerator-C

编译说明

1.默认是 Linux 环境,用 CMake。

2.如果是 Windows 环境,要用 Cygwin 或 MinGW。

调用示例C

第1步全局 初始化(应用程序启动时执行一次):

// 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId
IdGeneratorOptions options = BuildIdGenOptions(Your_Worker_Id);
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6支持的 WorkerId 最大值为2^6-1若 WorkerId 超过64可设置更大的 WorkerIdBitLength
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。

// 保存参数(必须的操作,否则以上设置都不能生效):
SetIdGenerator(options);
// 以上初始化过程只需全局一次且必须在第2步之前设置。

第2步生成ID

// 初始化以后即可在任何需要生成ID的地方调用以下方法
long newId = NextId();