ruby picture

RCR 162: Binary search

Submitted by legacy (Mon Oct 27 14:10:57 UTC 2003)

Abstract

This is a legacy RCR from Ruby Garden, submitted by ch00k. Matz has declared these RCRs obsolete, and asked that their authors resubmit them in the new format.

I propose to add binary search functionality to Enumerable. Add some method can be called for sorted collection (afer sort!) or, maybe it is better to introduce "is-sorted" method or flag

binary_search_first, binary_search_last

 - to find the first and the last occurence of object with given property

binary_search_all - to return Array of found objects (or iterate a block over them?)

Problem

(RCR imported from old format)

Proposal

Analysis

(RCR imported from old format)

Implementation

(RCR imported from old format)
ruby picture
Comments Current voting

not to Enumerable (, 2003-10-30 08:06:08)

not all objects that include Enumerable have a [] operator or are even indexable. Adding this would mean there would be methods in Enumerable that don't work on all Enumerable objects.

Agree (ch00k, 2003-10-30 12:02:52)

Then maybe add 'Indexable' module?


Strongly opposed 0
Opposed 0
Neutral 0
In favor 0
Strongly advocate 0
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .