/// <summary> /// 构造一个 <see cref="SnowflakeIdGenerator"/>。 /// </summary> /// <param name="snowflakes">给定的 <see cref="SnowflakeIdOptions"/>。</param> /// <param name="options">给定的 <see cref="IdGenerationOptions"/>。</param> /// <param name="clock">给定的 <see cref="IClockBootstrap"/>。</param> public SnowflakeIdGenerator(SnowflakeIdOptions snowflakes, IdGenerationOptions options, IClockBootstrap clock) : base(options, clock) { Snowflakes = snowflakes; if (options.MachineId >= 0) { _machineId = options.MachineId.NotGreater(Snowflakes.GetMaxMachineId()); } else { _machineId = Snowflakes.MachineBits; } if (options.DataCenterId >= 0) { _dataCenterId = options.DataCenterId.NotGreater(Snowflakes.GetMaxDataCenterId()); } else { _dataCenterId = Snowflakes.DataCenterBits; } }
/// <summary> /// 使用内置的 <see cref="Bootstrapper.GetClock()"/> 构造一个 <see cref="SnowflakeIdGenerator"/>。 /// </summary> /// <param name="snowflakes">给定的 <see cref="SnowflakeIdOptions"/>。</param> /// <param name="options">给定的 <see cref="IdGenerationOptions"/>。</param> public SnowflakeIdGenerator(SnowflakeIdOptions snowflakes, IdGenerationOptions options) : this(snowflakes, options, Bootstrapper.GetClock()) { }