1
0
mirror of synced 2025-12-13 00:28:26 +08:00
Files
SnowFlake-IdGenerator/C/source/idgen/IdGenOptions.h
AuroraTea 2da2aa8b4b fix: compatibility of C and C++
// fix: move .h to .c for cpp
// static IdGenerator *_idGenerator = NULL;
2023-01-23 17:35:48 +08:00

47 lines
1.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 版权属于yitter(yitter@126.com)
* 开源地址https://gitee.com/yitter/idgenerator
*/
#pragma once
#include <stdint.h>
typedef struct IdGenOptions {
/// 雪花计算方法,1-漂移算法|2-传统算法默认1
uint8_t Method;
/// 基础时间ms单位不能超过当前系统时间
uint64_t BaseTime;
/// 机器码,必须由外部设定,最大值 2^WorkerIdBitLength-1
uint32_t WorkerId;
/// 机器码位长默认值6取值范围 [1, 15](要求:序列数位长+机器码位长不超过22
uint8_t WorkerIdBitLength;
/// 序列数位长默认值6取值范围 [3, 21](要求:序列数位长+机器码位长不超过22
uint8_t SeqBitLength;
/// 最大序列数(含),设置范围 [MinSeqNumber, 2^SeqBitLength-1]默认值0表示最大序列数取最大值2^SeqBitLength-1]
uint32_t MaxSeqNumber;
/// 最小序列数默认值5取值范围 [5, MaxSeqNumber]每毫秒的前5个序列数对应编号0-4是保留位其中1-4是时间回拨相应预留位0是手工新值预留位
uint32_t MinSeqNumber;
/// 最大漂移次数默认2000推荐范围 500-20000与计算能力有关
uint32_t TopOverCostCount;
} IdGeneratorOptions;
#ifdef __cplusplus
extern "C"
{
#endif
extern IdGeneratorOptions BuildIdGenOptions(uint32_t workerId);
#ifdef __cplusplus
}
#endif