-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.ts
61 lines (49 loc) · 1.72 KB
/
filter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class FilterTree {
private readonly map = new Map<number, FilterTree>();
constructor(public terminal:boolean) {
}
insert(message:string, offset:number):void {
const chr1 = message.charCodeAt(offset++);
let chr2 = message.charCodeAt(offset++);
if (isNaN(chr2)) chr2 = 0;
const key = (chr1 << 16) | chr2;
const terminal = offset >= message.length;
let next = this.map.get(key);
if (next == null) this.map.set(key, next = new FilterTree(terminal));
if (terminal) {
next.terminal = true;
} else {
next.insert(message, offset);
}
}
// check(message:string[], arrayIndex:number, stringIndex:number):boolean {
// let terminal = false;
// function read():number {
// const word = message[arrayIndex];
// const chr = word.charCodeAt(stringIndex);
// stringIndex++;
// if (stringIndex >= word.length) {
// stringIndex = 0;
// arrayIndex++;
// if (arrayIndex >= message.length) {
// terminal = true;
// }
// }
// return chr;
// }
// const chr1 = message.charCodeAt(offset++);
// let chr2 = message.charCodeAt(offset++);
// if (isNaN(chr2)) chr2 = 0;
// const key = (chr1 << 16) | chr2;
// const list = this.map.get(key);
// if (list === null) {
// return false;
// }
// list?.terminal
// }
}
// function checkFilter(message:string):boolean {
// const replaced = message.split(/[~!@#$%^&*()_+\-=[\]{};':",./<>?`~\\| ]+/g);
// for (const chr of replaced) {
// }
// }