Skip to content

Commit 8c19520

Browse files
committed
//如果有三个子节点,则把更靠近的中间的节点保留,剩下的节点放另一边下面的子节点中
1 parent bd4aa83 commit 8c19520

File tree

5 files changed

+58
-30
lines changed

5 files changed

+58
-30
lines changed

cache.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (import.meta.main) {
2222

2323
async function parallel_cache(
2424
entry_iter: AsyncIterableIterator<WalkEntry>,
25-
limiter: AsyncCurrentLimiter
25+
limiter: AsyncCurrentLimiter,
2626
) {
2727
const files: string[] = [];
2828

@@ -37,21 +37,20 @@ async function parallel_cache(
3737
limiter.run(
3838
function (stack: string[]) {
3939
return runDenocache(stack);
40-
}.bind(null, stack)
40+
}.bind(null, stack),
4141
)
42-
)
42+
),
4343
);
4444
}
4545
async function start() {
4646
const limiter = new AsyncLimiterClass(1);
4747
const args = parse(Deno.args);
4848
console.log(args);
49-
const skip =
50-
typeof args.skip === "string"
51-
? new RegExp(String(args.skip))
52-
: Array.isArray(args.skip)
53-
? args.skip.map((s: string | RegExp) => new RegExp(s))
54-
: undefined;
49+
const skip = typeof args.skip === "string"
50+
? new RegExp(String(args.skip))
51+
: Array.isArray(args.skip)
52+
? args.skip.map((s: string | RegExp) => new RegExp(s))
53+
: undefined;
5554
const entry_iter = searchFilesNames({ skip });
5655
await parallel_cache(entry_iter, limiter);
5756
}
@@ -73,7 +72,7 @@ async function runDenocache(stack: string[]) {
7372
if (!success) {
7473
throw new Error(
7574
"type cache failed:" +
76-
JSON.stringify({ code, success, stdout: out, stderr: err })
75+
JSON.stringify({ code, success, stdout: out, stderr: err }),
7776
);
7877
}
7978
}

check.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (import.meta.main) {
2222

2323
async function parallel_check(
2424
entry_iter: AsyncIterableIterator<WalkEntry>,
25-
limiter: AsyncCurrentLimiter
25+
limiter: AsyncCurrentLimiter,
2626
) {
2727
const files: string[] = [];
2828

@@ -37,21 +37,20 @@ async function parallel_check(
3737
limiter.run(
3838
function (stack: string[]) {
3939
return runDenoCheck(stack);
40-
}.bind(null, stack)
40+
}.bind(null, stack),
4141
)
42-
)
42+
),
4343
);
4444
}
4545
async function start() {
4646
const limiter = new AsyncLimiterClass(navigator.hardwareConcurrency);
4747
const args = parse(Deno.args);
4848
console.log(args);
49-
const skip =
50-
typeof args.skip === "string"
51-
? new RegExp(String(args.skip))
52-
: Array.isArray(args.skip)
53-
? args.skip.map((s: string | RegExp) => new RegExp(s))
54-
: undefined;
49+
const skip = typeof args.skip === "string"
50+
? new RegExp(String(args.skip))
51+
: Array.isArray(args.skip)
52+
? args.skip.map((s: string | RegExp) => new RegExp(s))
53+
: undefined;
5554
const entry_iter = searchFilesNames({ skip });
5655
await parallel_check(entry_iter, limiter);
5756
}
@@ -73,7 +72,7 @@ async function runDenoCheck(stack: string[]) {
7372
if (!success) {
7473
throw new Error(
7574
"type cache failed:" +
76-
JSON.stringify({ code, success, stdout: out, stderr: err })
75+
JSON.stringify({ code, success, stdout: out, stderr: err }),
7776
);
7877
}
7978
}

my-calendar-ii/searchSegmentLeaf.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,37 @@ export function searchSegmentLeaf(
3434
.filter(([a, b]) => node.start <= a && node.end >= b);
3535

3636
node.children = segments.map(([a, b]) => SegmentTree(a, b, node.value));
37+
38+
if (node.children.length === 3) {
39+
//如果有三个子节点,则把更靠近的中间的节点保留,剩下的节点放另一边下面的子节点中
40+
const mid = Math.round((node.start + node.end) / 2);
41+
42+
// console.log(node);
43+
44+
if (
45+
Math.abs(mid - node.children[0].end) <
46+
Math.abs(mid - node.children[2].start)
47+
) {
48+
const left = node.children[0];
49+
const right = SegmentTree(
50+
node.children[1].start,
51+
node.children[2].end,
52+
node.value,
53+
[node.children[1], node.children[2]],
54+
);
55+
node.children = [left, right];
56+
} else {
57+
const left = SegmentTree(
58+
node.children[0].start,
59+
node.children[1].end,
60+
node.value,
61+
[node.children[0], node.children[1]],
62+
);
63+
const right = node.children[2];
64+
node.children = [left, right];
65+
}
66+
// console.log(node);
67+
}
3768
}
3869
if (node.children.length) {
3970
each?.(node);

retry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function retry<T>(
1515
retryOnError?:
1616
| ((error: any) => Promise<boolean>)
1717
| ((error: any) => boolean);
18-
}
18+
},
1919
) {
2020
const retryOnError = opts?.retryOnError ?? (() => true);
2121
const options: Required<RetryOptions> = {

xmake.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { retry } from "./retry.ts";
66

77
async function* findFilesRecursive(
88
path: string,
9-
name: string
9+
name: string,
1010
): AsyncGenerator<string, void, unknown> {
1111
for await (const entry of Deno.readDir(path)) {
1212
const fullPath = resolve(join(path, entry.name));
@@ -37,7 +37,7 @@ async function RunXmake(
3737
sdk: string,
3838
executable: string,
3939
group: string,
40-
mode: string
40+
mode: string,
4141
) {
4242
await RunXmakeConfig(file, toolchain, sdk, executable, mode);
4343
await retry(RunXmakeBuild.bind(null, file, executable, group), {
@@ -50,11 +50,11 @@ async function RunXmake(
5050
const cwd = path.dirname(file);
5151
const dirtobecreate = path.join(
5252
cwd,
53-
path.dirname(filepathmatched)
53+
path.dirname(filepathmatched),
5454
);
5555

5656
console.log(
57-
"Ensures that the directory exists:" + dirtobecreate
57+
"Ensures that the directory exists:" + dirtobecreate,
5858
);
5959
await ensureDir(dirtobecreate);
6060
return true;
@@ -69,7 +69,7 @@ async function RunXmakeConfig(
6969
toolchain: string,
7070
sdk: string,
7171
executable: string,
72-
mode: string
72+
mode: string,
7373
) {
7474
console.log({ file });
7575
const cwd = path.dirname(file);
@@ -88,10 +88,9 @@ export async function RunCommandShell(others: string[], cwd?: string) {
8888

8989
const cmd = os === "windows" ? "powershell.exe" : "bash";
9090

91-
const args =
92-
os === "windows"
93-
? ["-command", others.join(" \n ")]
94-
: ["-c", others.join(" && ")];
91+
const args = os === "windows"
92+
? ["-command", others.join(" \n ")]
93+
: ["-c", others.join(" && ")];
9594

9695
console.log(JSON.stringify({ cmd, cwd, args }));
9796
const command = new Deno.Command(cmd, { cwd: cwd, args });

0 commit comments

Comments
 (0)