• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S search implementation?

 
Todd Friar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've been lurking in this forum for a few months and I've found a lot of great info.

I'm not sure if I can ask a question at this level of detail, so if I can't please go ahead and delete my post.

Anyhow, I'm stuck on how to implement a search on the db for the find method.

I don't think it would be a good idea to read each record from the file until the record you want is found, that would be too slow. So I want to have a table that can be searched to give the location in the file that the specified record is in.

The only simple way I can think of to do this, is to have an array list that contains strings. Each string contains the name of the contractor. To do a search for a contractor, I would have to iterate through each element in the array checking each one by using as regex expression. When there is a match the index of the array would indicate position in the file to get the record. After a match the program would have to continue to search through the array until the end in order to find any more records that have a match. The big downside of this is that it is slow. However it is still faster than physically reading through each record in the file to find what you are looking for.

I thought about sorting the array list first, but then every time you want to add a new record you would have to resort the array, making it unavailible.

Am I on the right path?

If not could some one point me in the right direction?

I hope that wasn't too specific.

Thanks!
 
Sam Codean
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that SCJD does not need you to be a master in sorting and searching algorithm. It is more about developing an application.

What i did was that i gave and interface with methods


For the current assignment i gave a simple implementation which does a linear search (predictNextValue returns the next index) and comparison of the Records is implemented simply by comparing each string

Thus in case you find that the performance is slow and you need a better algorithm then you could simply add your implementation and voila the code still works.you want to do regex comparison feel free to change the compare method. So you have all the chances of future modifications with least affect rather than having the best algorithm.
"Change is eternal"!!!


 
Todd Friar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

I like your idea of the interface. It's give me some ideas.

 
Sam Codean
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just Keep the Good will going
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic