*/
public void matchKTuples(){
HashMap<String, TIntLinkedList> s1Map = new HashMap<String, TIntLinkedList>();
String s;
TIntLinkedList l1;
//map k-tuples in s1
for(int i=start1; i<=(end1+1-k); i++){
s = s1.substring(i, i+k);
if(s1Map.containsKey(s)){
l1 = s1Map.get(s);
l1.add(i);
}
else{
l1 = new TIntLinkedList();
l1.add(i);
s1Map.put(s, l1);
}
}
//the fornt list - will be updated as we're moving along s2
List<StringRange> front = new ArrayList<StringRange>();
//lookup k-tuples in s2
for(int i=start2; i<=(end2+1-k); i++){
s = s2.substring(i, i+k);
l1 = s1Map.get(s);
if(l1 == null){ //no matches for this key in s1Map
for(int p=0; p<front.size(); p++){
indices.add(front.get(p)); //stop point for every range on the front list
}
front.clear();
}
else{
//create new front list according the previous front list and l1
List<StringRange> newFront = new ArrayList<StringRange>();
int l1Pos = 0;
int frontPos = 0;
//move over the front list (newFront) and the list of indices from s1 (l1) and act according to the case:
while(l1Pos < l1.size() && frontPos < front.size()){
int l1Element = l1.get(l1Pos);
StringRange frontElement = front.get(frontPos);
//increase k-tuple length by 1
if(l1Element - frontElement.getI1() == frontElement.getLength()-k+1){
newFront.add(new StringRange(frontElement.getI1(), frontElement.getI2(), frontElement.getLength()+1));
l1Pos++;
frontPos++;
}
//add new k-tuple indices to the front list
else if(l1Element - frontElement.getI1() < frontElement.getLength()-k+1){
newFront.add(new StringRange(l1Element, i, k));
l1Pos++;
}
//end of k-tuple - can't get any longer
else{
indices.add(frontElement);
frontPos++;
}
}
//deal with cases of unfinished lists:
while(l1Pos < l1.size()){ //meaning the list of s1 indices is not over
int l1Element = l1.get(l1Pos);
newFront.add(new StringRange(l1Element, i, k));
l1Pos++;
}
while(frontPos < front.size()){ //meaning the front list is not over