Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the List-BinarySearch CPAN distribution.

Report information
The Basics
Id: 76898
Status: resolved
Worked: 3 hours (180 min)
Priority: 0/
Queue: List-BinarySearch

People
Owner: davido [...] cpan.org
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Consider return the bracketing values upon a failed search
Thanks for your module; I'm sick of writing my own binary search routines. One of the reasons I do is that often I need to know the values which bracket my requested value if it does not match. (Uses would be for interpolation of data, insertion of new data into a list, etc) Typical binary search routines simply indicate failure. Would you consider adding this feature to your code? Thanks! Diab
On Mon Apr 30 11:34:28 2012, DJERIUS wrote: Show quoted text
> > One of the reasons I do is that often I need to know the values which > bracket my requested value if it does not match. (Uses would be for > interpolation of data, insertion of new data into a list, etc) Typical > binary search routines simply indicate failure. > > Would you consider adding this feature to your code?
It's a nice suggestion. I will probably implement it, but need to look at several implementation and API options before I settle on a solution. Give it a week or two (as I'm involved in some other projects at the moment as well). I do agree that it's a worthwhile feature. Dave
Five new functions have been added to version 0.06: bsearch_str_pos -- Upon failure returns the best insert point for target. bsearch_num_pos -- Same as above but with numeric comparisons. bsearch_num_range -- Given target_low and target_high returns a range of indices. bsearch_str_range -- Same but for string comparisons. bsearch_general_range -- Auto-detect whether targets are string or number and return a range. This should solve the bracketing and range-finding questions. See the POD and Mastering Algorithms with Perl for additional explanation.