• Post Reply Bookmark Topic Watch Topic
  • New Topic

searching through vectors  RSS feed

 
joew weakers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. Can anybody offer me some sound advice in regard to using Vectors.
My program renders maps onto a simple GUI. SQL select statements retrieve all the necessary map content and put all these geometry values (polygons, points etc.) into a single Vector object v1. My program takes these geometries from this vector v1 and renders them on to the screen. Each geometry has an associated id in v1 in order to assist referencing that particular geometry. If I perform a query on my map and want to highlight certain points or polygons I send another select statement to the database to retrieve solely the ids of the geometries which form the result of my query. The reason for this is that the coordinates of the geometries already lie in the original vector v1 containing the geometries that were rendered to the screen. The results of my query are inserted into a second vector v2. What I need to do now is to compare the ids in the vectors v1 and v2. v1 will contain hundreds of thousands of elements whilst v2 may contain anything from one to several thousand elements. What I want to do is compare the two vectors v1 and v2 and match every element in v2 with the associated element in v1, i.e. v2 is a subset of v1. Is there a good algortihm for achieving this qiuckly or can anyone give me some useful hints to start off. Cheers Joe
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi joew
I have an idea. I am not sure if it would work for you.
We have an 'id' for each vector element here right? So, we can create a Hashtable (or any appropriate Collection API classes) to store "key","value" pairs which will make our search faster.
In that Hashtable we can put, (id,geometryobject) pairs. Now, when you retreive values for the other vector v2, instead of creating a vector you can just create array of Integer or Long or something depending upon the id type and then just do something like,
Integer[] ids = // values we get from the database that you currently put in vector v2
Hashtable geometryObjects = // value you currently store in vector v1
Geometry tempG = null; // place holder to store the object in the below forloop
for(int i=0; i < ids.length; i++) {
tempG = (Geometry)geometryObjects.get(ids[i]);
if ( tempG != null ) {
// highlight it
}
}
You get the idea?
Regards
Maulin
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!