SI-9605 Searching does not use binary search for Array#4902
SI-9605 Searching does not use binary search for Array#4902SethTisue merged 1 commit intoscala:2.11.xfrom
Conversation
|
Thanks, that looks like it will probably do the trick! But could you write a test that verifies the correct behavior? You can do this e.g. by creating a custom class that throws an exception if it is compared to a particular value (e.g. the 3rd one in the array), and then search for something in the second half so that comparison should be skipped if the correct implementation is used. (Make sure you explode both if 3 does the comparison or if something is compared to 3, so it doesn't matter which order the algorithm does the comparison in.) |
|
I accidentally put L/G/T/(you fill in this part) here. Not quite yet! |
|
Ack, wrong PR. I meant the ArrayStack one. |
Binary search should be used for every `IndexedSeqLike` instance and not only for `IndexedSeq`. According the Scaladoc, it is `IndexedSeqLike` that guarantees "constant-time or near constant-time element access and length computation".
9989e93 to
0702342
Compare
|
Done, I added a test that verifies if |
|
@ruippeixotog - In general, no, it doesn't, because linear operations (e.g. iterator) may be implemented via apply. |
|
Doesn't that defeat the purpose of linear search? If iterating over a collection is implemented by directly indexing elements with Nonetheless, it doesn't seem to matter anyway. Even if testing this way may not apply to every conceivable collection, in this test I'm not using arbitrary collections - I'm using collections I created inside each test and I know the behavior of their operations. As I delegate all operations other than |
|
It's a little overly-specific about which elements are hit, but sure, this way is fine also. Just to be clear, though, it's not whether |
|
/nothingtoseehere integrate-ide failure is unrelated to the PR |
|
LGTM |
SI-9605 Searching does not use binary search for Array
|
thank you Rui! |
Binary search should be used for every
IndexedSeqLikeinstance and not only forIndexedSeq. According the Scaladoc, it isIndexedSeqLikethat guarantees "constant-time or near constant-time element access and length computation".