Better way to search an array
in
Programming Questions
•
3 years ago
hi,
i want to make an arraysearch faster. The problem is that I want the array to search itself and when a word resembles the same word in a different array, to save the positions.
Now i'm doing it like this:
[code]
import java.util.ArrayList;
XMLElement xml;
void draw() {
loadXML();
noLoop();
}
void loadXML() {
xml = new XMLElement(this, "aol.xml");
// XMLElement aolFile = xml.getChild(0);
int num_aol = xml.getChildCount();
int rows = 1;
String[][] myArray = new String[num_aol][rows];
String[][] myResult = new String[num_aol][rows];
for (int i=0; i<num_aol; i++) {
XMLElement ClickURL = xml.getChild(i);
XMLElement thro = ClickURL.getChild(0);
//String Query = xml.getString(1);
int AnonID = int(ClickURL.getChild(0).getContent());
String Query = ClickURL.getChild(1).getContent();
String QueryTime = ClickURL.getChild(2).getContent();
String ItemRank = ClickURL.getChild(3).getContent();
String[] splitQuery = splitTokens(Query);
int stringAdd = splitQuery.length;
myArray[i] = (String[]) expand(myArray[i], stringAdd);
for (int j = 0; j < splitQuery.length; j++) {
myArray[i][j] = splitQuery[j];
// println(myArray[i][j]);
}
}
// search part
for (int i = 0; i < num_aol; i++)
for (int j = 0; j < myArray[i].length-1; j++)
for (int l = 0; l < num_aol; l++)
for (int k = 0; k < myArray[l].length-1; k++) {
if ( myArray[l][k] == myArray[i][j] ){
if(i == l){
}
else{
println("value 1 = "+ myArray[i][j]+ " value 2 = " + myArray[l][k]);
}
}
}
}
[/code]
Is there a faster way than this?
i want to make an arraysearch faster. The problem is that I want the array to search itself and when a word resembles the same word in a different array, to save the positions.
Now i'm doing it like this:
[code]
import java.util.ArrayList;
XMLElement xml;
void draw() {
loadXML();
noLoop();
}
void loadXML() {
xml = new XMLElement(this, "aol.xml");
// XMLElement aolFile = xml.getChild(0);
int num_aol = xml.getChildCount();
int rows = 1;
String[][] myArray = new String[num_aol][rows];
String[][] myResult = new String[num_aol][rows];
for (int i=0; i<num_aol; i++) {
XMLElement ClickURL = xml.getChild(i);
XMLElement thro = ClickURL.getChild(0);
//String Query = xml.getString(1);
int AnonID = int(ClickURL.getChild(0).getContent());
String Query = ClickURL.getChild(1).getContent();
String QueryTime = ClickURL.getChild(2).getContent();
String ItemRank = ClickURL.getChild(3).getContent();
String[] splitQuery = splitTokens(Query);
int stringAdd = splitQuery.length;
myArray[i] = (String[]) expand(myArray[i], stringAdd);
for (int j = 0; j < splitQuery.length; j++) {
myArray[i][j] = splitQuery[j];
// println(myArray[i][j]);
}
}
// search part
for (int i = 0; i < num_aol; i++)
for (int j = 0; j < myArray[i].length-1; j++)
for (int l = 0; l < num_aol; l++)
for (int k = 0; k < myArray[l].length-1; k++) {
if ( myArray[l][k] == myArray[i][j] ){
if(i == l){
}
else{
println("value 1 = "+ myArray[i][j]+ " value 2 = " + myArray[l][k]);
}
}
}
}
[/code]
Is there a faster way than this?
1
