Skip to content

Commit 092cb76

Browse files
committed
Update README.md
1 parent 974f4e2 commit 092cb76

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,43 +46,46 @@ A variant of Snowflake-SI algorithm.
4646
```ts
4747
import * as libuuid from "@litert/uuid";
4848

49-
const makeUUID = libuuid.SnowflakeSI.createGenerateor({
49+
const factory = UUID.SnowflakeBI.createFactory();
50+
51+
const makeUUID = factory.create({
5052

5153
/**
5254
* The machine ID.
5355
*
54-
* By default the uinWidth is 8, and the rest 5 bits is left to MID, so
56+
* By default the uinBitWidth is 8, and the rest 5 bits is left to MID, so
5557
* that the mid must be between 0 and 31.
5658
*/
57-
"mid": 1,
59+
"machineId": 1,
5860

5961
/**
6062
* The base-clock of generator. Is unchangeable once setup.
6163
*
62-
* And it cannot be earlier than 2003-03-18T07:20:20Z
64+
* And it cannot be earlier than 2003-03-18T07:20:19.225Z.
6365
*/
6466
"baseClock": new Date(2004, 0, 1, 0, 0, 0, 0).getTime(),
65-
6667
});
6768

68-
console.log(makeUUID()); // Generate a UUIN
69-
console.log(makeUUID()); // Generate a UUIN
70-
console.log(makeUUID.MS_CAPACITY); // See the capacity of UUIDs in 1ms
71-
console.log(makeUUID.MACHINE_ID); // See the machine ID.
72-
console.log(new Date(makeUUID.BASE_CLOCK)); // See the base-clock
69+
console.log(makeUUID()); // Generate a UUID
70+
console.log(makeUUID()); // Generate a UUID
71+
console.log(makeUUID.uinCapacity); // See the capacity of UUIDs in 1ms
72+
console.log(makeUUID.machineId); // See the machine ID.
73+
console.log(new Date(makeUUID.baseClock)); // See the base-clock
7374
```
7475

7576
### Snowflake-SI Adjustment
7677

7778
```ts
7879
import * as libuuid from "@litert/uuid";
7980

80-
const makeUUID = libuuid.SnowflakeSI.createGenerateor({
81+
const factory = UUID.SnowflakeBI.createFactory();
82+
83+
const makeUUID = factory.create({
8184

8285
/**
8386
* The machine ID.
8487
*
85-
* Now the uinWidth has been set to 12, and only 1 bit is left to MID, so
88+
* Now the uinBitWidth has been set to 12, and only 1 bit is left to MID, so
8689
* that the mid can be either 1 or 0.
8790
*/
8891
"mid": 1,
@@ -97,14 +100,14 @@ const makeUUID = libuuid.SnowflakeSI.createGenerateor({
97100
/**
98101
* The bit-width of UIN.
99102
*/
100-
"uinWidth": 12
103+
"uinBitWidth": 12
101104
});
102105

103-
console.log(makeUUID()); // Generate a UUIN
104-
console.log(makeUUID()); // Generate a UUIN
105-
console.log(makeUUID.MS_CAPACITY); // See the capacity of UUIDs in 1ms
106-
console.log(makeUUID.MACHINE_ID); // See the machine ID.
107-
console.log(new Date(makeUUID.BASE_CLOCK)); // See the base-clock
106+
console.log(makeUUID()); // Generate a UUID
107+
console.log(makeUUID()); // Generate a UUID
108+
console.log(makeUUID.uinCapacity); // See the capacity of UUIDs in 1ms
109+
console.log(makeUUID.machineId); // See the machine ID.
110+
console.log(new Date(makeUUID.baseClock)); // See the base-clock
108111
```
109112

110113
### Snowflake-SI-vA Usage

README_zh.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,61 +45,65 @@ Snowflake-SI-vA 是 Snowflake-SI 算法的一个变种。
4545
```ts
4646
import * as libuuid from "@litert/uuid";
4747

48-
const makeUUID = libuuid.SnowflakeSI.createGenerateor({
48+
const factory = UUID.SnowflakeBI.createFactory();
49+
50+
const makeUUID = factory.create({
4951

5052
/**
5153
* 机器序号,默认可以取值 0 ~ 31。
5254
*
53-
* 取值范围会根据 uinWidth 变化而变化。
55+
* 取值范围会根据 uinBitWidth 变化而变化。
5456
*/
55-
"mid": 0,
57+
"machineId": 2,
5658

5759
/**
5860
* 业务基准时间,一旦设定绝对不能再修改。
5961
*
60-
* 该时间不能早于 2003-03-18T07:20:20Z
62+
* 该时间不能早于 2003-03-18T07:20:19.225Z.
6163
*/
6264
"baseClock": new Date(2004, 0, 1, 0, 0, 0, 0).getTime()
6365
});
6466

65-
console.log(makeUUID()); // 生成一个 UUID
66-
console.log(makeUUID()); // 再生成一个 UUID
67-
console.log(makeUUID.MS_CAPACITY); // 查看 UUID 生成器的毫秒容量
68-
console.log(makeUUID.MACHINE_ID); // 查看 UUID 生成器的机器序号
69-
console.log(new Date(makeUUID.BASE_CLOCK)); // 查看 UUID 生成器的业务基准时间
67+
console.log(makeUUID()); // 生成一个 UUID
68+
console.log(makeUUID()); // 再生成一个 UUID
69+
console.log(makeUUID.uinCapacity); // 查看 UUID 生成器的毫秒容量
70+
console.log(makeUUID.machineId); // 查看 UUID 生成器的机器序号
71+
console.log(new Date(makeUUID.baseClock)); // 查看 UUID 生成器的业务基准时间
7072
```
7173

7274
### Snowflake-SI 算法微调
7375

7476
```ts
7577
import * as libuuid from "@litert/uuid";
7678

77-
const makeUUID = libuuid.SnowflakeSI.createGenerateor({
79+
const factory = UUID.SnowflakeBI.createFactory();
80+
81+
const makeUUID = factory.create({
7882

7983
/**
80-
* 机器序号,由于 uinWidth 被设置为 12,因此 MID 只有一个比特,只能是 1 或者 0。
84+
* 机器序号,由于 uinBitWidth 被设置为 12,因此 MID 只有一个比特,只能是 1 或者 0。
8185
*/
8286
"mid": 1,
8387

8488
/**
8589
* 业务基准时间,一旦设定绝对不能再修改。
8690
*
87-
* 该时间不能早于 2003-03-18T07:20:20Z
91+
* 该时间不能早于 2003-03-18T07:20:19.225Z.
8892
*/
8993
"baseClock": new Date(2004, 0, 1, 0, 0, 0, 0).getTime(),
9094

9195
/**
9296
* UIN 所占的位宽,此处设置为 12,即只留一位给 MID。
9397
* 因此每毫秒可以容纳 2 ^ 12 == 4096 个 UUID。
9498
*/
95-
"uinWidth": 12
99+
"uinBitWidth": 12
96100
});
97101

98-
console.log(makeUUID()); // 生成一个 UUID
99-
console.log(makeUUID()); // 再生成一个 UUID
100-
console.log(makeUUID.MS_CAPACITY); // 查看 UUID 生成器的毫秒容量
101-
console.log(makeUUID.MACHINE_ID); // 查看 UUID 生成器的机器序号
102-
console.log(new Date(makeUUID.BASE_CLOCK)); // 查看 UUID 生成器的业务基准时间
102+
console.log(makeUUID()); // 生成一个 UUID
103+
console.log(makeUUID()); // 再生成一个 UUID
104+
console.log(makeUUID.uinCapacity); // 查看 UUID 生成器的毫秒容量
105+
console.log(makeUUID.machineId); // 查看 UUID 生成器的机器序号
106+
console.log(new Date(makeUUID.baseClock)); // 查看 UUID 生成器的业务基准时间
103107
```
104108

105109
### Snowflake-SI-vA 基本使用

0 commit comments

Comments
 (0)