@algorithm.ts/gcd 3.0.0-alpha.7 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-2022 guanghechen (me.guanghechen@gmail.com)
3
+ Copyright (c) 2020-2023 guanghechen (https://github.com/guanghechen)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/lib/cjs/index.cjs CHANGED
@@ -73,4 +73,3 @@ exports.euclidean = euclidean;
73
73
  exports.euclideanBigint = euclideanBigint;
74
74
  exports.gcd = gcd;
75
75
  exports.gcdBigint = gcdBigint;
76
- //# sourceMappingURL=index.cjs.map
package/lib/esm/index.mjs CHANGED
@@ -68,4 +68,3 @@ function gcdBigint(x, y) {
68
68
  }
69
69
 
70
70
  export { euclidean, euclideanBigint, gcd, gcdBigint };
71
- //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algorithm.ts/gcd",
3
- "version": "3.0.0-alpha.7",
3
+ "version": "3.0.0",
4
4
  "description": "GCD + Euclidean algorithm",
5
5
  "author": {
6
6
  "name": "guanghechen",
@@ -20,20 +20,20 @@
20
20
  "type": "module",
21
21
  "exports": {
22
22
  "types": "./lib/types/index.d.ts",
23
- "require": "./lib/cjs/index.cjs",
24
- "import": "./lib/esm/index.mjs"
23
+ "import": "./lib/esm/index.mjs",
24
+ "require": "./lib/cjs/index.cjs"
25
25
  },
26
+ "source": "./src/index.ts",
26
27
  "types": "./lib/types/index.d.ts",
27
28
  "main": "./lib/cjs/index.cjs",
28
29
  "module": "./lib/esm/index.mjs",
29
- "source": "./src/index.ts",
30
30
  "license": "MIT",
31
31
  "engines": {
32
32
  "node": ">= 16.0.0"
33
33
  },
34
34
  "files": [
35
35
  "lib/",
36
- "src/",
36
+ "!lib/**/*.map",
37
37
  "package.json",
38
38
  "CHANGELOG.md",
39
39
  "LICENSE",
@@ -45,12 +45,13 @@
45
45
  "test": "cross-env TS_NODE_FILES=true NODE_OPTIONS=--experimental-vm-modules jest --config ../../jest.config.mjs --rootDir ."
46
46
  },
47
47
  "dependencies": {
48
- "@algorithm.ts/constant": "^3.0.0-alpha.7"
48
+ "@algorithm.ts/constant": "^3.0.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "cross-env": "^7.0.3",
52
- "rimraf": "^3.0.2",
53
- "rollup": "^3.9.1"
52
+ "jest": "^29.5.0",
53
+ "rimraf": "^4.4.1",
54
+ "rollup": "^3.20.2"
54
55
  },
55
- "gitHead": "336c4da3b92a49804c60d0a6dfb783b14712ce0a"
56
+ "gitHead": "9bb1f3515444890907c8e811b989f17073f39591"
56
57
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../constant/lib/esm/index.mjs","../../src/euclidean.ts","../../src/gcd.ts"],"sourcesContent":["const BIGINT_ZERO = BigInt(0);\nconst BIGINT_ONE = BigInt(1);\nconst CODEPOINT_DIGIT_0 = '0'.codePointAt(0);\nconst CODEPOINT_DIGIT_9 = '9'.codePointAt(0);\nconst CODEPOINT_UPPER_A = 'A'.codePointAt(0);\nconst CODEPOINT_UPPER_Z = 'Z'.codePointAt(0);\nconst CODEPOINT_LOWER_A = 'a'.codePointAt(0);\nconst CODEPOINT_LOWER_Z = 'z'.codePointAt(0);\n\nexport { BIGINT_ONE, BIGINT_ZERO, CODEPOINT_DIGIT_0, CODEPOINT_DIGIT_9, CODEPOINT_LOWER_A, CODEPOINT_LOWER_Z, CODEPOINT_UPPER_A, CODEPOINT_UPPER_Z };\n//# sourceMappingURL=index.mjs.map\n",null,null],"names":[],"mappings":";;AAAA,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAC9B,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC;;ACUZ,SAAA,SAAS,CA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AAE,CAAA;AACP,SAAA;AAAM,aAAA;AACL,YAAA,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAA;YACjB,MAAM,CAAC,GAAG,EAAE,CAAA;AACZ,YAAA,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YAEX,MAAM,CAAC,GAAG,CAAC,CAAA;YACX,MAAM,CAAC,GAAG,CAAC,CAAA;YAEX,CAAC,GAAG,CAAC,CAAA;YACL,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;AACtB,SAAA;KACF;AACH;;AC5DgB,SAAA,GAAG,CAAC,CAAS,EAAE,CAAS,EAAA;IACtC,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAI;QACzB,MAAM,CAAC,GAAG,CAAC,CAAA;QACX,CAAC,GAAG,CAAC,CAAA;AACL,QAAA,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACV,KAAA;AACD,IAAA,OAAO,CAAC,CAAA;AACV,CAAC;AASe,SAAA,SAAS,CAAC,CAAS,EAAE,CAAS,EAAA;IAC5C,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,WAAW,GAAI;QACnC,MAAM,CAAC,GAAG,CAAC,CAAA;QACX,CAAC,GAAG,CAAC,CAAA;AACL,QAAA,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACV,KAAA;AACD,IAAA,OAAO,CAAC,CAAA;AACV;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../constant/lib/esm/index.mjs","../../src/euclidean.ts","../../src/gcd.ts"],"sourcesContent":["const BIGINT_ZERO = BigInt(0);\nconst BIGINT_ONE = BigInt(1);\nconst CODEPOINT_DIGIT_0 = '0'.codePointAt(0);\nconst CODEPOINT_DIGIT_9 = '9'.codePointAt(0);\nconst CODEPOINT_UPPER_A = 'A'.codePointAt(0);\nconst CODEPOINT_UPPER_Z = 'Z'.codePointAt(0);\nconst CODEPOINT_LOWER_A = 'a'.codePointAt(0);\nconst CODEPOINT_LOWER_Z = 'z'.codePointAt(0);\n\nexport { BIGINT_ONE, BIGINT_ZERO, CODEPOINT_DIGIT_0, CODEPOINT_DIGIT_9, CODEPOINT_LOWER_A, CODEPOINT_LOWER_Z, CODEPOINT_UPPER_A, CODEPOINT_UPPER_Z };\n//# sourceMappingURL=index.mjs.map\n",null,null],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAC9B,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC;;ACUZ,SAAA,SAAS,CAAC,CAAS,EAAE,CAAS,EAAA;AAC5C,IAAA,IAAI,CAAS,CAAA;AACb,IAAA,IAAI,CAAS,CAAA;AACb,IAAA,IAAI,CAAS,CAAA;AACb,IAAA,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACX,IAAA,OAAO,CAAC,CAAE,EAAE,CAAE,EAAE,CAAE,CAAC,CAAA;AAEnB,IAAA,SAAS,KAAK,CAAC,EAAU,EAAE,EAAU,EAAA;QACnC,IAAI,EAAE,KAAK,CAAC,EAAE;YACZ,CAAC,GAAG,CAAC,CAAA;YACL,CAAC,GAAG,CAAC,CAAA;YACL,CAAC,GAAG,EAAE,CAAA;AACP,SAAA;AAAM,aAAA;AACL,YAAA,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAA;YACjB,MAAM,CAAC,GAAG,EAAE,CAAA;AACZ,YAAA,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YAEX,MAAM,CAAC,GAAG,CAAC,CAAA;YACX,MAAM,CAAC,GAAG,CAAC,CAAA;YAEX,CAAC,GAAG,CAAC,CAAA;AACL,YAAA,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,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GAAG,CAAC,CAAA;IACT,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,WAAW,GAAI;QACnC,MAAM,CAAC,GAAG,CAAC,CAAA;QACX,CAAC,GAAG,CAAC,CAAA;AACL,QAAA,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACV,KAAA;AACD,IAAA,OAAO,CAAC,CAAA;AACV;;;;"}
package/src/euclidean.ts DELETED
@@ -1,70 +0,0 @@
1
- import { BIGINT_ONE, BIGINT_ZERO } from '@algorithm.ts/constant'
2
-
3
- /**
4
- * Extended Euclidean algorithm for solving the smallest
5
- * integer solution (|x| + |y| smallest) of the equation `Ax + By = gcd(x,y)`.
6
- *
7
- * @param a
8
- * @param b
9
- * @returns
10
- * @see https://me.guanghechen.com/post/math/number-theory/%E6%A8%A1%E6%96%B9%E7%A8%8B/basic/
11
- */
12
- export function euclidean(a: number, b: number): [number, number, number] {
13
- let x: number
14
- let y: number
15
- let d: number
16
- solve(a, b)
17
- return [x!, y!, d!]
18
-
19
- function solve(_a: number, _b: number): void {
20
- if (_b === 0) {
21
- x = 1
22
- y = 0
23
- d = _a
24
- } else {
25
- const A = _a % _b
26
- const B = _b
27
- solve(B, A)
28
-
29
- const X = y
30
- const Y = x
31
-
32
- x = X
33
- y = Y - Math.floor(_a / _b) * X
34
- }
35
- }
36
- }
37
-
38
- /**
39
- * Bigint version.
40
- *
41
- * @param a
42
- * @param b
43
- * @returns
44
- * @see https://me.guanghechen.com/post/math/number-theory/%E6%A8%A1%E6%96%B9%E7%A8%8B/basic/
45
- */
46
- export function euclideanBigint(a: bigint, b: bigint): [bigint, bigint, bigint] {
47
- let x: bigint
48
- let y: bigint
49
- let d: bigint
50
- solve(a, b)
51
- return [x!, y!, d!]
52
-
53
- function solve(_a: bigint, _b: bigint): void {
54
- if (_b === BIGINT_ZERO) {
55
- x = BIGINT_ONE
56
- y = BIGINT_ZERO
57
- d = _a
58
- } else {
59
- const A = _a % _b
60
- const B = _b
61
- solve(B, A)
62
-
63
- const X = y
64
- const Y = x
65
-
66
- x = X
67
- y = Y - (_a / _b) * X
68
- }
69
- }
70
- }
package/src/gcd.ts DELETED
@@ -1,35 +0,0 @@
1
- import { BIGINT_ZERO } from '@algorithm.ts/constant'
2
-
3
- /**
4
- * Find the greatest common divisor of x and y
5
- *
6
- * @param x
7
- * @param y
8
- * @returns
9
- */
10
- export function gcd(x: number, y: number): number {
11
- let i = x
12
- for (let j = y; j !== 0; ) {
13
- const t = i
14
- i = j
15
- j = t % i
16
- }
17
- return i
18
- }
19
-
20
- /**
21
- * Bigint version.
22
- *
23
- * @param x
24
- * @param y
25
- * @returns
26
- */
27
- export function gcdBigint(x: bigint, y: bigint): bigint {
28
- let i = x
29
- for (let j = y; j !== BIGINT_ZERO; ) {
30
- const t = i
31
- i = j
32
- j = t % i
33
- }
34
- return i
35
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './euclidean'
2
- export * from './gcd'