a way to improve this search algorithm?!
I need some advises to improve my search algorithm.
What I want to do is parse a file containing int values.
I'm searching the first maximum/minimum value, so when there are two or more max/min values only the first one should be stored. Moreover I want to save the pointer position of the values.
Right now I'm doing this by an if-block:
if (theCurrentPositionValue > max) {
theCurrentPositionValue = max;
index = buff.position();
}
and I do the same with the min value.
Is there a way to get rid of this if-block?
[582 byte] By [
Seek_seeka] at [2007-9-29 23:36:19]

> Is there a way to get rid of this if-block?
Sure, but it will be hacking all along. Why should you want to get rid of this simple if block?
There's a decision to be made and if statements are well suited for that purpose.
Keep your code the way it is now; optimisations can probably be more efffective elsewhere,
not here in this simple single-test (a necessary test) if block.
kind regards,
Jos
to compare integers are very very very quick opreations. To read the file is probably a few thousand times slower anyway.
Things you should be much more careful about to avoid is:
* reading the file in too small chunks - To read the whole chunks of 16 kb should be enough
* Allocating too big byte-buffer for reading. To read the whole file at once is not too good if it's a big file.
* Don't use any .readInt() method in some file-class. This will be very slow. It is ok if you have an underlying BufferInputStream, but isn't too quick.
* Creating strings (new String())- slow and memory consuming.
* Integer.parseInt() is also very slow. If you know the encoding, you could just use that information and just interpretate the bytes you read.
Gil