• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sound advice appreciated

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you have ids, can you use a Map? For each id in subset, render superset.get(id)?
BTW: Vector is on the legacy list. I use a Collections Crib Sheet to help me keep all the new ones straight.
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Sounds like a Set would be a more natural collection to use for that functionality. Look at the methods retainAll() and containsAll() specified in the Set interface, -- I think this is what you need.
reply
    Bookmark Topic Watch Topic
  • New Topic