-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOracleMultiple.java
More file actions
65 lines (57 loc) · 1.32 KB
/
Copy pathOracleMultiple.java
File metadata and controls
65 lines (57 loc) · 1.32 KB
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
62
63
64
65
public class OracleMultiple {
int delta[][];
OracleMultiple() {
}
}
class Trie {
String[] patrones;
String C = "";// letras diferentes
State raiz;
Trie(String[] x) {
patrones = x;
int r = x.length;
for (String s : x)
for (int i = 0; i < s.length(); i++)
if (!C.contains(s.subSequence(i, i + 1)))
C += s.charAt(i);
raiz = new State(C.length(), r);
for (int i = 0; i < r; i++) {
State current = raiz;
int j = 0;
int m = x[i].length();
while ((j < m) && (current.hijos[C.indexOf(x[i].charAt(j))] != null)) {
current = current.hijos[C.indexOf(x[i].charAt(j))];
j++;
}
while (j < m) {
current = current.addhijo(C.indexOf(x[i].charAt(j)));
j++;
}
if (current.fin)
current.id[i] = true;
else {
current.fin = true;
current.id[i] = true;
}
}
}
}
class State {
int numhijos = 0;
State padre;
boolean fin = false;
boolean[] id;
State[] hijos;// el indice indica por cual letra es hijo
State(int s, int i)// para la raiz
{
hijos = new State[s];
id = new boolean[i];
}
State addhijo(int h)// para hacer un hijo por la rama h
{
numhijos++;
hijos[h] = new State(hijos.length, id.length);
hijos[h].padre = this;
return hijos[h];
}
}