stdlib: Binary search function

new topic     » topic index » view thread      » older message » newer message

This has been an oft requested functionality, and was in principle agreed, even
by Rob:
http://www.openeuphoria.org/cgi-bin/esearch.exu?fromMonth=6&fromYear=1&toMonth=5&toYear=D&postedBy=&keywords=binary_find
http://www.openeuphoria.org/cgi-bin/esearch.exu?fromMonth=6&fromYear=1&toMonth=5&toYear=D&postedBy=&keywords=bfind

Some implementations have been mentioned already (G. Boehme, J. Babor,...).

Now, the devil is in the details. What shall the function do?
* accept only strictly increasing sequences
* accept only strictly monotoni sequences
* accept loosely monotonic sequences (with possible duplicates)
* only cope with <any selection above>, not checking

I think everyone agrees it should return like db_find_key(), ie n>0 when found,
n<0 with ordered insertion resulting in item lading at position -n.

And another point which wasn't agreed upon: would this go to sort.e or
sequence.e?

The version I use in sets.e has a from and to extra parameters. They could be
easily defaulted. Monoony could be passed as a parameter too, depending on the
option chosen.

CChris

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu