mirror of
https://github.com/SukkaW/Surge.git
synced 2026-09-12 18:44:36 +08:00
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
/* eslint-disable no-await-in-loop -- no concurrent */
|
|
import { fdir as Fdir } from 'fdir';
|
|
import { OUTPUT_SURGE_DIR } from './constants/dir';
|
|
import path from 'node:path';
|
|
import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
|
import { xxhash3 } from 'hash-wasm';
|
|
import { split1st } from 'foxts/split-nth';
|
|
|
|
(async () => {
|
|
const hashMap = new Map<string, Set<string>>();
|
|
|
|
const runHash = async (inputs: string[]) => {
|
|
for (let i = 0, len = inputs.length; i < len; i++) {
|
|
const input = inputs[i];
|
|
const hash = await xxhash3(input);
|
|
if (!hashMap.has(hash)) {
|
|
hashMap.set(hash, new Set());
|
|
}
|
|
hashMap.get(hash)!.add(input);
|
|
}
|
|
};
|
|
|
|
const files = await new Fdir()
|
|
.withRelativePaths()
|
|
.crawl(OUTPUT_SURGE_DIR)
|
|
.withPromise();
|
|
|
|
for (let i = 0, len = files.length; i < len; i++) {
|
|
const file = files[i];
|
|
const fullpath = path.join(OUTPUT_SURGE_DIR, file);
|
|
if (file.startsWith('domainset' + path.sep)) {
|
|
await runHash((await readFileIntoProcessedArray(fullpath)).map(i => (i[0] === '.' ? i.slice(1) : i)));
|
|
} else if (file.startsWith('non_ip' + path.sep)) {
|
|
await runHash((await readFileIntoProcessedArray(fullpath)).map(i => split1st(i, ',')));
|
|
}
|
|
}
|
|
|
|
console.log(hashMap.size);
|
|
let collision = 0;
|
|
hashMap.forEach((v, k) => {
|
|
if (v.size > 1) {
|
|
collision++;
|
|
console.log(k, '=>', v);
|
|
}
|
|
});
|
|
if (collision === 0) {
|
|
console.log(hashMap);
|
|
}
|
|
})();
|