Hi All,
I have a need to compare two strings in a sliding fashion. For example, lets suppose you have two strings:
A B C D E
F G H I J
You want to compare these two in a way that the first comparison might be:
E
F
Next you slide and compare:
D E
F G
Next you slide and compare:
C D E
F G H
And onward until the last comparison would then be:
A
J
In each case you are comapring overlapping characters to eachother to see if they match, but that is secondary to the algorithm. I have written this and it works, but I am wondering if it could be done faster, because in my application speed matters. Of course, ASM would be great, but I am wondering if anyone can do it faster than my code. Below is the code (note that z and y are indexes into the string which is stored in an array...also rawinputlength is length of the string, a.k.a the number of elements in the array).
I have a need to compare two strings in a sliding fashion. For example, lets suppose you have two strings:
A B C D E
F G H I J
You want to compare these two in a way that the first comparison might be:
E
F
Next you slide and compare:
D E
F G
Next you slide and compare:
C D E
F G H
And onward until the last comparison would then be:
A
J
In each case you are comapring overlapping characters to eachother to see if they match, but that is secondary to the algorithm. I have written this and it works, but I am wondering if it could be done faster, because in my application speed matters. Of course, ASM would be great, but I am wondering if anyone can do it faster than my code. Below is the code (note that z and y are indexes into the string which is stored in an array...also rawinputlength is length of the string, a.k.a the number of elements in the array).
Code:
'this first section slides the strings until the are almost directly over eachother matches2 = 0: matches = 0 overlap1 = %rawInpLength: overlap2 = 1 z = %rawInpLength y = 1 DO DO WHILE z >= overlap1 DO WHILE y >= 1 '''''Do comparison here z = z - 1 y = y - 1 WEND WEND DECR overlap1 INCR overlap2 z = %rawInpLength y = overlap2 LOOP WHILE overlap2 <= %rawInpLength-1 'this section then continues the sliding forward from where the last code finished FOR z = 0 TO %rawInpLength-1 FOR y = 1 TO %rawInpLength - z '''''Do comparison here NEXT y NEXT z
Comment