• Post Reply Bookmark Topic Watch Topic
  • New Topic

a little advice would be appreciated  RSS feed

 
joe weakers
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. I have a rough idea on how to achieve my end result but I would appreciate any suggestions that any of you may have in order to optimize possible solutions. My query is as follows: I retrieve the String id values of various map features that fall within a tolerance distance of a user's current location from a spatial database and insert these Strings into a vector A. I also have a user profile which is composed of several sub-profiles that each contain similar String feature id values to those I just inserted into the first vector above. I create a new vector for each sub-profile of the user and insert into these vectors all the string values of the map features contained within the sub-profile. As to be expected I then compare each individual sub-profile vector with the initial vector A containing all random features falling near the user. What is the fastest and most accurate way to compare each sub-profile vector to vector A? Vector A can contain 0-50 values and generally the sub-profiles contain roughy 10 values. I dont want to have to loop thru A for each sub-profile vector or do I have a choice in this. Thanks a lot, Joe.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First to do is stop using Vector and start using ArrayList (even if only for the massive performance gains this typically yields).

ArrayList (and all Collections) constains a method containsAll(Collection c) which should do what you want to achiev.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Jeroen on all points. But note that if you use ArrayList, then the implementation of containsAll() is going to have to loop through the lists -- just the implementation you wanted to avoid. If you can, try to use HashSets instead of ArrayList, because HashSet.containsAll() can use very efficient lookups to do its work.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All good advice - though at the size you mention, it's unlikely that you will really feel a performance difference. Remember, premature optimization is the root of all evil - you should rather spend your time thinking about ease of maintainability and extensibility...
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was assuming he wanted to avoid having to write the loop code himself
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!