• Post Reply Bookmark Topic Watch Topic
  • New Topic

search algorith  RSS feed

 
nikil shar
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • 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.
 
Stephan van Hulst
Saloon Keeper
Posts: 7932
143
  • Mark post as helpful
  • send pies
  • 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.
 
Winston Gutkowski
Bartender
Posts: 10574
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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: 10574
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!