Fix/Perf: more efficient and correct whitelisting

This commit is contained in:
SukkaW
2024-05-27 01:09:11 +08:00
parent 8b1eeb1c14
commit 2f329a4144
4 changed files with 52 additions and 35 deletions

View File

@@ -208,6 +208,26 @@ describe('smol tree', () => {
]);
});
it('should whitelist trie correctly', () => {
const trie = createTrie([
'.t.co',
't.co',
'example.t.co',
'.skk.moe'
], true, true);
expect(trie.dump()).toStrictEqual([
'.skk.moe',
'.t.co'
]);
trie.whitelist('.t.co');
expect(trie.dump()).toStrictEqual(['.skk.moe']);
trie.whitelist('skk.moe');
expect(trie.dump()).toStrictEqual([]);
});
it('should efficiently whitelist domains', () => {
const trie = createTrie([
'skk.moe',
@@ -231,7 +251,6 @@ describe('smol tree', () => {
]);
trie.whitelist('anotherskk.moe');
expect(trie.dump()).toStrictEqual([
'blog.anotherskk.moe'
]);