• 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

search algorith

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i am trying to implement a search algorith where i have got a list of services and packets and i need to iterate over each service and find its packets and populate some java objects. Currently my algorithm is to hold all the data in a Vector, start with the first element and run through the list finding its packets and move to the next element.

This is pretty slow, take about 10 mins to return results to GUI. Any suggestions as to what other mechanism i could use ??

thanks in advance.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, your "searching" algorithm doesn't exactly sound like one. Can you be more clear in what you want to achieve?

And please don't use Vector. It's pretty much deprecated.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nikil shar wrote:i am trying to implement a search algorith where i have got a list of services and packets and i need to iterate over each service and find its packets and populate some java objects. Currently my algorithm is to hold all the data in a Vector, start with the first element and run through the list finding its packets and move to the next element.
This is pretty slow, take about 10 mins to return results to GUI. Any suggestions as to what other mechanism i could use ??


As Stephan says, that doesn't sound like a search, it sounds like a conversion. Do you want packets from every service? If not, what distinguishes the ones that you don't want?

Java has a very comprehensive framework of datasets called the Java Collections Framework that will probably help if there is anything to search on. I suspect you might be best starting with the tutorials.

Winston
 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply everyone. each of my service has a unique service_number which can be used to link packets to its service. i select all the services and packets from the database by doing a join and store them in a vector. Then i iterate over each element using the service_number to match the packets. Hopefully this makes it clearer as to what i am trying to achieve.

thanks for the link to the tutorial

 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nikil shar wrote:thanks for the reply everyone. each of my service has a unique service_number which can be used to link packets to its service. i select all the services and packets from the database by doing a join and store them in a vector. Then i iterate over each element using the service_number to match the packets. Hopefully this makes it clearer as to what i am trying to achieve.


It still doesn't sound like you have anything to search on, and if that's the case you will not be able to speed up your search. And when you say a 'vector', do you mean a java.util.Vector? Because, if so, there are probably faster alternatives.

From the sound of it, I think your problem may lie in having all your data lumped together in a single set. If I were doing something like this, I'd probably split it in two:
Services and Packets
and then sort the Packets by service number. Or, if you absolutely have to have it all jammed together, sort the whole thing on [service number + packet sequence].

Also, do you actually have a Service class and a Packet class, and is your 'vector' made up of these objects? Or is it just a bunch of rows from a database SELECT statement?
Java works much better with objects than it does with raw data.

Winston
 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Winston,
yap i mean java.util.Vector when i say 'vector'. Also the data is lumped togather after select from the database and its a lot of effort if i were to seperate the dataset. Have tried using a hashmap to store the data using key/value but it doesnt seem to speed things up any more than using a Vector.
 
Marshal
Posts: 79178
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using Vector rather than ArrayList?
 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have tried an arraylist as well and it doesnt seem to improve performance. i think the issue is that i have to iterate over the list multiple times trying to find packets for each service. dont think there is much which can be done to improve the performance
reply
    Bookmark Topic Watch Topic
  • New Topic