|
-
October 25th, 2006, 10:02 AM
#1
Vector Retrieval Efficiency
I am working in a program that was handed off to me. I need to make it more efficient when processing files. There is a section that has two for loops, one is nested inside the other. Code is below. The Vector can be up to 20,000 items. In this code, for each item in the DataVal, it checks every item in SetupData, and if they match then it processes, and I have now added a break out of the nested loop which helps. Does anyone have a better suggestion for doing this? Thanks.
for (int a=0; a < DataVal.size(); a++)
{
Hashtable dHt = (Hashtable)DataVal.elementAt(a);
int dX = Integer.parseInt((String) dHt.get("X")) + xOffset;
int dY = Integer.parseInt((String) dHt.get("Y")) + yOffset;
if ((dX <= 0) || (dY <= 0))
{
DataVal.removeElementAt(a);
a--;
continue;
} // end if
boolean keep = false;
for (int b=0; b < SetupData.size(); b++)
{
Hashtable tHt = (Hashtable)SetupData.elementAt(b);
int tX = Integer.parseInt((String) tHt.get("X"));
int tY = Integer.parseInt((String) tHt.get("Y"));
String tType = (String) tHt.get("T_TYPE");
if ((dX == tX) && (dY == tY))
{
if (dHt.containsKey("X"))
{
dHt.remove("X");
} // end if
if (dHt.containsKey("Y"))
{
dHt.remove("Y");
} // end if
if (dHt.containsKey("T_TYPE"))
{
dHt.remove("T_TYPE");
} // end if
dHt.put("X",""+tX);
dHt.put("Y",""+tY);
dHt.put("T_TYPE",tType);
keep = true;
break;
} // end if
} // end for
if (!keep)
{
DataVal.removeElementAt(a);
a--;
continue;
} // end if
else
{
DataVal.setElementAt(dfabHt, a);
} // end else
} // end for
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|