Skip to content

Commit dd57d3f

Browse files
committed
🎨 style: set print width to 100 (old is 80)
1 parent 46da4bc commit dd57d3f

File tree

26 files changed

+50
-172
lines changed

26 files changed

+50
-172
lines changed

Diff for: .eslintrc

+1-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@
3131
},
3232
{
3333
"files": ["**/__test__/*.spec.ts", "jest.setup.ts"],
34-
"extends": [
35-
"@guanghechen",
36-
"@guanghechen/ts",
37-
"plugin:jest/recommended",
38-
"prettier"
39-
],
34+
"extends": ["@guanghechen", "@guanghechen/ts", "plugin:jest/recommended", "prettier"],
4035
"rules": {
4136
"import/no-extraneous-dependencies": 0,
4237
"jest/expect-expect": 0

Diff for: .prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ endOfLine: lf
55
htmlWhitespaceSensitivity: strict
66
jsxBracketSameLine: false
77
jsxSingleQuote: false
8-
printWidth: 80
8+
printWidth: 100
99
proseWrap: always
1010
quoteProps: as-needed
1111
semi: false

Diff for: jest.setup.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ export const loadFixtures = (...p: string[]): string =>
2424
* Remove filepaths
2525
* @param filepaths
2626
*/
27-
export const unlinkSync = (
28-
...filepaths: Array<string | null | undefined | string[]>
29-
): void => {
27+
export const unlinkSync = (...filepaths: Array<string | null | undefined | string[]>): void => {
3028
for (let filepath of filepaths) {
3129
if (filepath == null) continue
3230
if (!Array.isArray(filepath)) filepath = [filepath]

Diff for: packages/binary-index-tree/__test__/binary-saerch-tree.spec.ts

+8-24
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ describe('tree1', function () {
1414
const bit = createBinaryIndexTree1<number>(0)
1515
bit.init(MAX_N)
1616

17-
const A: number[] = new Array(MAX_N)
18-
.fill(0)
19-
.map((_x, i) => randomInt(MAX_N) + 17)
17+
const A: number[] = new Array(MAX_N).fill(0).map((_x, i) => randomInt(MAX_N) + 17)
2018
for (let x = 0; x < MAX_N; ++x) bit.add(x + 1, A[x])
2119

2220
const getSum = (x: number): number => {
@@ -45,9 +43,7 @@ describe('tree1', function () {
4543
const bit = createBinaryIndexTree1<bigint>(0n)
4644
bit.init(MAX_N)
4745

48-
const A: bigint[] = new Array(MAX_N)
49-
.fill(0)
50-
.map((_x, i) => BigInt(randomInt(MAX_N) + 17))
46+
const A: bigint[] = new Array(MAX_N).fill(0).map((_x, i) => BigInt(randomInt(MAX_N) + 17))
5147
for (let x = 0; x < MAX_N; ++x) bit.add(x + 1, A[x])
5248

5349
const getSum = (x: number): bigint => {
@@ -81,9 +77,7 @@ describe('tree2', function () {
8177
bit.init(MAX_N)
8278

8379
// Initialize
84-
const A: number[] = new Array(MAX_N)
85-
.fill(0)
86-
.map((_x, i) => randomInt(MAX_N) + 17)
80+
const A: number[] = new Array(MAX_N).fill(0).map((_x, i) => randomInt(MAX_N) + 17)
8781
for (let x = 0; x < MAX_N; ++x) {
8882
bit.add(x, -A[x])
8983
bit.add(x + 1, A[x])
@@ -117,9 +111,7 @@ describe('tree2', function () {
117111
bit.init(MAX_N)
118112

119113
// Initialize
120-
const A: bigint[] = new Array(MAX_N)
121-
.fill(0)
122-
.map((_x, i) => BigInt(randomInt(MAX_N) + 17))
114+
const A: bigint[] = new Array(MAX_N).fill(0).map((_x, i) => BigInt(randomInt(MAX_N) + 17))
123115
for (let x = 0; x < MAX_N; ++x) {
124116
bit.add(x, -A[x])
125117
bit.add(x + 1, A[x])
@@ -157,9 +149,7 @@ describe('tree1-mod', function () {
157149
const bit = createBinaryIndexTree1Mod<number>(0, MOD)
158150
bit.init(MAX_N)
159151

160-
const A: number[] = new Array(MAX_N)
161-
.fill(0)
162-
.map((_x, i) => randomInt(MOD - 1))
152+
const A: number[] = new Array(MAX_N).fill(0).map((_x, i) => randomInt(MOD - 1))
163153
for (let x = 0; x < MAX_N; ++x) bit.add(x + 1, A[x])
164154

165155
const getSum = (x: number): number => {
@@ -188,9 +178,7 @@ describe('tree1-mod', function () {
188178
const bit = createBinaryIndexTree1Mod<bigint>(0n, BigInt(MOD))
189179
bit.init(MAX_N)
190180

191-
const A: bigint[] = new Array(MAX_N)
192-
.fill(0)
193-
.map((_x, i) => BigInt(randomInt(MOD)))
181+
const A: bigint[] = new Array(MAX_N).fill(0).map((_x, i) => BigInt(randomInt(MOD)))
194182
for (let x = 0; x < MAX_N; ++x) bit.add(x + 1, A[x])
195183

196184
const getSum = (x: number): bigint => {
@@ -225,9 +213,7 @@ describe('tree2-mod', function () {
225213
bit.init(MAX_N)
226214

227215
// Initialize
228-
const A: number[] = new Array(MAX_N)
229-
.fill(0)
230-
.map((_x, i) => randomInt(MOD - 1))
216+
const A: number[] = new Array(MAX_N).fill(0).map((_x, i) => randomInt(MOD - 1))
231217
for (let x = 0; x < MAX_N; ++x) {
232218
bit.add(x, -A[x])
233219
bit.add(x + 1, A[x])
@@ -261,9 +247,7 @@ describe('tree2-mod', function () {
261247
bit.init(MAX_N)
262248

263249
// Initialize
264-
const A: bigint[] = new Array(MAX_N)
265-
.fill(0)
266-
.map((_x, i) => BigInt(randomInt(MOD - 1)))
250+
const A: bigint[] = new Array(MAX_N).fill(0).map((_x, i) => BigInt(randomInt(MOD - 1)))
267251
for (let x = 0; x < MAX_N; ++x) {
268252
bit.add(x, -A[x])
269253
bit.add(x + 1, A[x])

Diff for: packages/binary-index-tree/src/tree1.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import { lowbit } from './util'
99
* @param ZERO 0 for number, 0n for bigint.
1010
* @returns
1111
*/
12-
export function createBinaryIndexTree1<T extends number | bigint>(
13-
ZERO: T,
14-
): BinaryIndexTree<T> {
12+
export function createBinaryIndexTree1<T extends number | bigint>(ZERO: T): BinaryIndexTree<T> {
1513
let _size = 0
1614
const _nodes: T[] = [ZERO]
1715
return { init, add, query }

Diff for: packages/binary-index-tree/src/tree2.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import { lowbit } from './util'
99
* @param ZERO 0 for number, 0n for bigint.
1010
* @returns
1111
*/
12-
export function createBinaryIndexTree2<T extends number | bigint>(
13-
ZERO: T,
14-
): BinaryIndexTree<T> {
12+
export function createBinaryIndexTree2<T extends number | bigint>(ZERO: T): BinaryIndexTree<T> {
1513
let _size = 0
1614
const _nodes: T[] = [ZERO]
1715

Diff for: packages/calculate/src/calculate.ts

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { TokenSymbol, idx, ll1Table, sddTable } from './constant'
22
import type { Operations } from './operations'
3-
import {
4-
bigintOperations,
5-
decimalOperations,
6-
integerOperations,
7-
} from './operations'
3+
import { bigintOperations, decimalOperations, integerOperations } from './operations'
84

95
export type Calculate<T extends number | bigint> = (expression: string) => T
106

@@ -14,10 +10,7 @@ export function createCalculate<T extends number | bigint>(
1410
): Calculate<T> {
1511
const { ZERO, parse, add, subtract, multiply, divide } = operations
1612
return function (rawExpression: string): T {
17-
const expression =
18-
resolveExpression == null
19-
? rawExpression
20-
: resolveExpression(rawExpression)
13+
const expression = resolveExpression == null ? rawExpression : resolveExpression(rawExpression)
2114

2215
let cur = 0
2316
const result: T = execute(idx('A'), ZERO, ZERO)
@@ -143,19 +136,16 @@ export function createCalculate<T extends number | bigint>(
143136
}
144137

145138
// Integer calculate.
146-
export const calculate: Calculate<number> = createCalculate<number>(
147-
integerOperations,
148-
s => s.replace(/[\s]+/g, ''),
139+
export const calculate: Calculate<number> = createCalculate<number>(integerOperations, s =>
140+
s.replace(/[\s]+/g, ''),
149141
)
150142

151143
// Decimal calculate.
152-
export const decimalCalculate: Calculate<number> = createCalculate<number>(
153-
decimalOperations,
154-
s => s.replace(/[\s]+/g, '').replace(/(^|[^\d.])\./g, '$10.'),
144+
export const decimalCalculate: Calculate<number> = createCalculate<number>(decimalOperations, s =>
145+
s.replace(/[\s]+/g, '').replace(/(^|[^\d.])\./g, '$10.'),
155146
)
156147

157148
// Bigint calculate.
158-
export const bigintCalculate: Calculate<bigint> = createCalculate<bigint>(
159-
bigintOperations,
160-
s => s.replace(/[\s]+/g, ''),
149+
export const bigintCalculate: Calculate<bigint> = createCalculate<bigint>(bigintOperations, s =>
150+
s.replace(/[\s]+/g, ''),
161151
)

Diff for: packages/dijkstra/src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export function dijkstra<T extends number | bigint>(
3131
INF: T,
3232
): T[] {
3333
const dist: T[] = new Array(N).fill(INF)
34-
const Q = createPriorityQueue<{ pos: number; cost: T }>(
35-
(x, y) => y.cost - x.cost,
36-
)
34+
const Q = createPriorityQueue<{ pos: number; cost: T }>((x, y) => y.cost - x.cost)
3735

3836
// eslint-disable-next-line no-param-reassign
3937
dist[source] = ZERO

Diff for: packages/dlx/__test__/sudoku3x3.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ export enum SudokuConstraint {
1313
SUB = 3, // Sub(a, b): a-th sub-square matrix must have the number b
1414
}
1515

16-
export function solveSudoku(
17-
puzzle: ReadonlyArray<number[]>,
18-
solution: number[][],
19-
): boolean {
20-
const encode = (a: number, b: number, c: number): number =>
21-
a * 81 + b * 9 + c + 1
16+
export function solveSudoku(puzzle: ReadonlyArray<number[]>, solution: number[][]): boolean {
17+
const encode = (a: number, b: number, c: number): number => a * 81 + b * 9 + c + 1
2218

2319
dlx.init(DL_TOTAL_COLUMNS)
2420
const columns: number[] = new Array<number>(4)

Diff for: packages/findset/__test__/findset.spec.ts

+5-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
/* eslint-disable no-param-reassign */
22
import { randomInt } from '@algorithm.ts/knuth-shuffle'
33
import type { EnhancedFindset } from '../src'
4-
import {
5-
createEnhancedFindset,
6-
createFindset,
7-
createHeuristicFindset,
8-
} from '../src'
4+
import { createEnhancedFindset, createFindset, createHeuristicFindset } from '../src'
95

106
describe('createfindset', function () {
117
const MAX_N = 1000
@@ -48,9 +44,7 @@ describe('createfindset', function () {
4844

4945
for (let i = 1; i <= MAX_N; ++i) expect(findset.root(i)).toBe(i)
5046

51-
expect(() => findset.init(0)).toThrow(
52-
/Invalid value, expect an integer in the range of/,
53-
)
47+
expect(() => findset.init(0)).toThrow(/Invalid value, expect an integer in the range of/)
5448
expect(() => findset.init(1)).not.toThrow()
5549
expect(() => findset.init(MAX_N)).not.toThrow()
5650
expect(() => findset.init(MAX_N + 1)).toThrow(
@@ -102,9 +96,7 @@ describe('createHeuristicfindset', function () {
10296

10397
for (let i = 1; i <= MAX_N; ++i) expect(findset.root(i)).toBe(i)
10498

105-
expect(() => findset.init(0)).toThrow(
106-
/Invalid value, expect an integer in the range of/,
107-
)
99+
expect(() => findset.init(0)).toThrow(/Invalid value, expect an integer in the range of/)
108100
expect(() => findset.init(1)).not.toThrow()
109101
expect(() => findset.init(MAX_N)).not.toThrow()
110102
expect(() => findset.init(MAX_N + 1)).toThrow(
@@ -172,9 +164,7 @@ describe('enhanced-findset', function () {
172164

173165
for (let i = 1; i <= MAX_N; ++i) expect(findset.root(i)).toBe(i)
174166

175-
expect(() => findset.init(0)).toThrow(
176-
/Invalid value, expect an integer in the range of/,
177-
)
167+
expect(() => findset.init(0)).toThrow(/Invalid value, expect an integer in the range of/)
178168
expect(() => findset.init(1)).not.toThrow()
179169
expect(() => findset.init(MAX_N)).not.toThrow()
180170
expect(() => findset.init(MAX_N + 1)).toThrow(
@@ -241,11 +231,7 @@ describe('leetcode', function () {
241231
expect(solve(N, meetings, firstPerson)).toEqual(kase.answer)
242232
}
243233

244-
function createSolve(): (
245-
N: number,
246-
meetings: number[][],
247-
firstPerson: number,
248-
) => number[] {
234+
function createSolve(): (N: number, meetings: number[][], firstPerson: number) => number[] {
249235
const MAX_N = 1e5 + 10
250236
const answer: Set<number> = new Set()
251237
const nodes: Set<number> = new Set()

Diff for: packages/findset/src/enhanced.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ export function createEnhancedFindset(MAX_N: number): EnhancedFindset {
4848
}
4949

5050
function root(x: number): number {
51-
if (x < 1 || x > MAX_N)
52-
throw new RangeError(`Out of boundary [1, ${MAX_N}]. x: ${x}`)
51+
if (x < 1 || x > MAX_N) throw new RangeError(`Out of boundary [1, ${MAX_N}]. x: ${x}`)
5352
return _root(x)
5453
}
5554

Diff for: packages/findset/src/heuristic.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export function createHeuristicFindset(MAX_N: number): HeuristicFindset {
4242
}
4343

4444
function root(x: number): number {
45-
if (x < 1 || x > MAX_N)
46-
throw new RangeError(`Out of boundary [1, ${MAX_N}]. x: ${x}`)
45+
if (x < 1 || x > MAX_N) throw new RangeError(`Out of boundary [1, ${MAX_N}]. x: ${x}`)
4746
return _root(x)
4847
}
4948

Diff for: packages/findset/src/ordinary.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export function createFindset(MAX_N: number): Findset {
6060
}
6161

6262
function root(x: number): number {
63-
if (x < 1 || x > MAX_N)
64-
throw new RangeError(`Out of boundary [1, ${MAX_N}]. x: ${x}`)
63+
if (x < 1 || x > MAX_N) throw new RangeError(`Out of boundary [1, ${MAX_N}]. x: ${x}`)
6564
return _root(x)
6665
}
6766

Diff for: packages/gcd/src/euclidean.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ export function euclidean(a: number, b: number): [number, number, number] {
4141
* @returns
4242
* @see https://me.guanghechen.com/post/math/number-theory/%E6%A8%A1%E6%96%B9%E7%A8%8B/basic/
4343
*/
44-
export function euclideanBigint(
45-
a: bigint,
46-
b: bigint,
47-
): [bigint, bigint, bigint] {
44+
export function euclideanBigint(a: bigint, b: bigint): [bigint, bigint, bigint] {
4845
let x: bigint
4946
let y: bigint
5047
let d: bigint

Diff for: packages/lower-bound/__test__/lower-bound.spec.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,5 @@ test('upper-bound', function () {
1717
})
1818

1919
test('bigint', function () {
20-
expect(
21-
lowerBoundBigInt(
22-
-5000000000000n,
23-
500000000000000000000000000n,
24-
x => x - 1n,
25-
),
26-
).toBe(1n)
20+
expect(lowerBoundBigInt(-5000000000000n, 500000000000000000000000000n, x => x - 1n)).toBe(1n)
2721
})

Diff for: packages/priority-queue/__test__/priority-queue.spec.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ describe('basic', function () {
4848
randomValues[i] = Math.random()
4949
}
5050

51-
const maximum = randomValues.reduce(
52-
(acc, x) => Math.max(acc, x),
53-
Number.MIN_SAFE_INTEGER,
54-
)
51+
const maximum = randomValues.reduce((acc, x) => Math.max(acc, x), Number.MIN_SAFE_INTEGER)
5552

5653
for (let i = 0; i < N; ++i) Q.enqueue(randomValues[i])
5754
for (let i = 0; i <= N; ++i) {
@@ -68,9 +65,7 @@ describe('basic', function () {
6865
}
6966

7067
for (let i = 0; i < N; ++i) Q.enqueue(randomValues[i])
71-
expect(Q.collect().sort((x, y) => x - y)).toEqual(
72-
randomValues.slice().sort((x, y) => x - y),
73-
)
68+
expect(Q.collect().sort((x, y) => x - y)).toEqual(randomValues.slice().sort((x, y) => x - y))
7469
})
7570

7671
test('init', function () {

Diff for: packages/priority-queue/src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ export interface PriorityQueue<T> {
4848
* side of the operator has higher precedence.
4949
* @returns
5050
*/
51-
export function createPriorityQueue<T>(
52-
cmp: (x: T, y: T) => -1 | 0 | 1 | number,
53-
): PriorityQueue<T> {
51+
export function createPriorityQueue<T>(cmp: (x: T, y: T) => -1 | 0 | 1 | number): PriorityQueue<T> {
5452
const _tree: T[] = [null as unknown as T]
5553
let _size = 0
5654

Diff for: packages/roman/src/int2roman.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ export const defaultRomanCodes = 'MDCLXVI'
1717
* @param value
1818
* @param romanCodes
1919
*/
20-
export function int2roman(
21-
originalValue: number,
22-
romanCodes: string = defaultRomanCodes,
23-
): string {
20+
export function int2roman(originalValue: number, romanCodes: string = defaultRomanCodes): string {
2421
let one = 10 ** Math.floor(romanCodes.length / 2)
2522
const MAX_VALUE = romanCodes.length & 1 ? one * 4 : one * 9
2623

@@ -33,9 +30,7 @@ export function int2roman(
3330
const roman: string[] = []
3431

3532
// Convert high-order numbers
36-
i == 0
37-
? convert('', '', romanCodes[0])
38-
: convert('', romanCodes[0], romanCodes[1])
33+
i == 0 ? convert('', '', romanCodes[0]) : convert('', romanCodes[0], romanCodes[1])
3934

4035
// Covert remain numbers
4136
for (one /= 10; one > 0; one /= 10, i += 2) {

0 commit comments

Comments
 (0)