I am working on a program that calculates the percentage of hits between two lines (A and B). To get the exact percentage, I match the N-grams with a list of strings that are permutations of string A.
Here is my code
public String[] generatePermutations( String name ){
String[] perms = new String[ calcN(name.length()) ];
int nameLen = name.length(),
cnt = 0;
for(int i = 0; i < name.length(); i++ ){
nameLen = name.length()-i;
for( int ii = 0; ii <= i; ii++){
perms[cnt++] = name.substring( ii, ii + nameLen );
}
}
return perms;
}
for reference calcN () below
public int calcN( int n ){
return ( n * (n+1 )) / 2;
}
Given the string "ABC", this method will generate
{"A", "B", "C", "AB", "BC", "ABC"}
Since I do this operation thousands of times (maybe hundreds of thousands), is there a way to compress a few extra loops from my processor? (besides switching to C ++ or C). As always, in advance for a consultation!