Chore: dedupe and sort other rulesets

This commit is contained in:
SukkaW
2024-09-08 01:28:54 +08:00
parent d4ee25e75a
commit 90079b9987
8 changed files with 110 additions and 91 deletions

View File

@@ -1,8 +1,6 @@
import { createTrie, type Trie } from './trie';
export function domainDeduper(inputDomains: string[] | Trie, toArray?: true): string[];
export function domainDeduper(inputDomains: string[] | Trie, toArray: false): Set<string>;
export function domainDeduper(inputDomains: string[] | Trie, toArray = true): string[] | Set<string> {
export function domainsetDeduper(inputDomains: string[] | Trie): string[] {
let trie: Trie;
if (Array.isArray(inputDomains)) {
trie = createTrie(inputDomains, true);
@@ -12,28 +10,5 @@ export function domainDeduper(inputDomains: string[] | Trie, toArray = true): st
throw new Error('Invalid trie');
}
const dumped = trie.dump();
if (toArray) {
return dumped;
}
return new Set(dumped);
// const trie = createTrie(inputDomains, true);
// const sets = new Set(inputDomains);
// for (let i = 0, len1 = inputDomains.length; i < len1; i++) {
// const d = inputDomains[i];
// if (d[0] !== '.') {
// continue;
// }
// trie.substractSetInPlaceFromFound(d, sets);
// sets.delete(d.slice(1));
// }
// if (toArray) {
// return Array.from(sets);
// }
// return sets;
return trie.dump();
}