-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMaximalRepeat.java
105 lines (81 loc) · 3.01 KB
/
MaximalRepeat.java
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Instructs $SubstringIterator$ to visit only the maximal repeats of a string.
* Being dependent on $SubstringIterator$ and on $RightMaximalSubstring$, this class must
* be adapted to the case of large alphabet.
*/
public class MaximalRepeat extends RightMaximalSubstring {
protected int leftContext;
/**
* TRUE iff $v=aw$ where $w$ is a maximal repeat and $a$ is a character.
*/
protected boolean isLeftExtensionOfMaximalRepeat;
/**
* Artificial no-argument constructor, used just to avoid compile-time errors.
* See the no-argument constructor of $Substring$ for details.
*/
protected MaximalRepeat() { }
protected MaximalRepeat(int alphabetLength, int log2alphabetLength, int bitsToEncodeAlphabetLength, long bwtLength, int log2BWTLength, int bitsToEncodeBWTLength) {
super(alphabetLength,log2alphabetLength,bitsToEncodeAlphabetLength,bwtLength,log2BWTLength,bitsToEncodeBWTLength);
}
protected void clone(Substring other) {
super.clone(other);
MaximalRepeat mr = (MaximalRepeat)other;
mr.leftContext=leftContext;
mr.isLeftExtensionOfMaximalRepeat=isLeftExtensionOfMaximalRepeat;
}
protected Substring getInstance() {
return new MaximalRepeat(alphabetLength,log2alphabetLength,bitsToEncodeAlphabetLength,bwtLength,log2BWTLength,bitsToEncodeBWTLength);
}
protected Substring getEpsilon(long[] C) {
MaximalRepeat out = (MaximalRepeat)getInstance();
// $bwtIntervals$
out.nIntervals=alphabetLength+1;
out.bwtIntervals[0][0]=0; // $#$
out.bwtIntervals[0][1]=0;
for (int i=0; i<alphabetLength-1; i++) { // Other characters
out.bwtIntervals[i+1][0]=C[i];
out.bwtIntervals[i+1][1]=C[i+1]-1;
}
out.bwtIntervals[alphabetLength][0]=C[alphabetLength-1];
out.bwtIntervals[alphabetLength][1]=bwtLength-1;
// Other variables
out.address=-1;
out.log2address=-1;
out.previousAddress=-1;
out.length=0;
out.log2length=-1;
out.bitsToEncodeLength=1;
out.firstCharacter=-1;
out.hasBeenExtended=false;
out.hasBeenStolen=false;
out.computeRightContext();
out.leftContext=-1;
out.isLeftExtensionOfMaximalRepeat=false;
return out;
}
public String toString() {
String out = super.toString()+" | ";
out+="leftContext="+leftContext+" ";
out+="isLeftExtensionOfMaximalRepeat="+isLeftExtensionOfMaximalRepeat+" ";
return out;
}
protected final void computeLeftContext(Substring[] leftExtensions) {
leftContext=0;
for (int i=0; i<alphabetLength+1; i++) {
if (leftExtensions[i].frequency()>0) leftContext++;
}
}
protected void visited(Stream stack, RigidStream characterStack, SimpleStream pointerStack, Substring[] cache, Substring[] leftExtensions) {
super.visited(stack,characterStack,pointerStack,cache,leftExtensions);
// Maximal repeat
computeLeftContext(leftExtensions);
// Left-extensions of maximal repeats
if (leftContext>1) {
MaximalRepeat mr;
for (int i=1; i<alphabetLength+1; i++) { // Disregarding $#$
mr=(MaximalRepeat)leftExtensions[i];
if (leftExtensions[i].frequency()>0) mr.isLeftExtensionOfMaximalRepeat=true;
}
}
}
}